Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,6 @@ dotnet_diagnostic.IDE0005.severity = suggestion
# IDE0017: Simplify object initialization
dotnet_diagnostic.IDE0017.severity = suggestion

# IDE0019: Use pattern matching to avoid as followed by a null check
dotnet_diagnostic.IDE0019.severity = suggestion

# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable)
dotnet_diagnostic.IDE0020.severity = suggestion

# IDE0029: Use coalesce expression
dotnet_diagnostic.IDE0029.severity = suggestion

# IDE0030: Null check can be simplified
dotnet_diagnostic.IDE0030.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -190,9 +190,8 @@ internal override bool DetermineWhetherDBNullIsValid(object item, string columnN
{
column = table.Columns[columnName];
}
else if (arg is int)
else if (arg is int index)
{
int index = (int)arg;
if (0 <= index && index < table.Columns.Count)
{
column = table.Columns[index];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -28,7 +28,7 @@ internal XmlNodeComparer(SortDescriptionCollection sortParameters, XmlNamespaceM
{
_sortParameters = sortParameters;
_namespaceManager = namespaceManager;
_culture = (culture == null) ? CultureInfo.InvariantCulture : culture;
_culture = culture ?? CultureInfo.InvariantCulture;
}

int IComparer.Compare(object o1, object o2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static bool HasInternals
///<summary>Complies list of file items comprising an Application.</summary>
public void Compile(CompilationUnit cu)
{
// KnownTypes, XamlTypeMapper, and ReflectionHelper all hold on to data statically that
// KnownTypes, XamlTypeMapper, and ReflectionHelper all hold on to data statically that
// must not be reused between compilations as different compilations can target different
//
// Defensively clear static data even though the prior compilation should have done it.
Expand Down Expand Up @@ -625,7 +625,7 @@ private void GenerateSource()
// } end namespace
CodeCompileUnit ccu = new CodeCompileUnit();

// generate pragma checksum data
// generate pragma checksum data
Guid hashGuid = !string.IsNullOrEmpty(ChecksumAlgorithm) && ChecksumAlgorithm.Equals("SHA256", StringComparison.OrdinalIgnoreCase)
? s_hashSHA256Guid
: s_hashSHA1Guid;
Expand Down Expand Up @@ -700,7 +700,7 @@ private SourceFileInfo OnSourceFileResolve(FileUnit file)
if (sourceFileInfo.IsXamlFile)
{
int fileExtIndex = file.Path.LastIndexOf(DOTCHAR);

sourceFileInfo.RelativeSourceFilePath = file.Path.Substring(0, fileExtIndex);
}
}
Expand Down Expand Up @@ -849,10 +849,9 @@ internal void ProcessDefinitionNamespace(XamlDefTagNode xamlDefTagNode)
case XmlNodeType.CDATA:
case XmlNodeType.Text:
{
IXmlLineInfo xmlLineInfo = xmlReader as IXmlLineInfo;
int lineNumber = 0;

if (null != xmlLineInfo)
if (xmlReader is IXmlLineInfo xmlLineInfo)
{
lineNumber = xmlLineInfo.LineNumber;
}
Expand Down Expand Up @@ -1306,8 +1305,7 @@ private void InitializeReflectionHelper()
{
for (int i = 0; i < ReferenceAssemblyList.Count; i++)
{
ReferenceAssembly refasm = ReferenceAssemblyList[i] as ReferenceAssembly;
if (refasm != null && refasm.Path.Length > 0)
if (ReferenceAssemblyList[i] is ReferenceAssembly refasm && refasm.Path.Length > 0)
{
paths.Add(refasm.Path);
}
Expand All @@ -1324,9 +1322,7 @@ private void InitializeTypeMapper()
{
for (int i = 0; i < ReferenceAssemblyList.Count; i++)
{
ReferenceAssembly refasm = ReferenceAssemblyList[i] as ReferenceAssembly;

if (refasm != null && refasm.Path.Length > 0)
if (ReferenceAssemblyList[i] is ReferenceAssembly refasm && refasm.Path.Length > 0)
{
_typeMapper.SetAssemblyPath(refasm.AssemblyName, refasm.Path);
}
Expand Down Expand Up @@ -1567,9 +1563,9 @@ private string ParentFolderPrefix
{
// During code generation, ParentFolderPrefix returns the relative path from a .g.cs file to its markup file.
//
// One example is generated #pragmas: #pragma checksum "..\..\..\..\Views\ExportNotificationView.xaml"
// One example is generated #pragmas: #pragma checksum "..\..\..\..\Views\ExportNotificationView.xaml"
//
// The path information for a markup file is represented in SourceFileInfo:
// The path information for a markup file is represented in SourceFileInfo:
//
// SourceFileInfo.OriginalFilePath: "c:\\greenshot\\src\\Greenshot.Addons\\Views\\ExportNotificationView.xaml"
// SourceFileInfo.TargetPath: "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\"
Expand All @@ -1586,23 +1582,23 @@ private string ParentFolderPrefix
//
// The relative path calculation must take in to account both the TargetPath and the RelativeFilePath:
//
// "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\" [SourceFileInfo.TargetPath]
// "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\" [SourceFileInfo.TargetPath]
// "Views\\ExportNotificationView" [SourceFileInfo.RelativeTargetPath]
//
// TargetPath concatenated with the directory portion of the RelativeTargetPath is the location to the .g.cs file:
//
// "c:\\greenshot\\src\\Greenshot.Addons\\obj\\Debug\\net6.0-windows\\Views"
//
//
string pathOfRelativeSourceFilePath = System.IO.Path.GetDirectoryName(SourceFileInfo.RelativeSourceFilePath);

// Return the parent folder of the target file with a trailing DirectorySeparatorChar.
// Return the parent folder of the target file with a trailing DirectorySeparatorChar.
// Return a relative path if possible. Else, return an absolute path.
#if NETFX
#if NETFX
string path = PathInternal.GetRelativePath(TargetPath + pathOfRelativeSourceFilePath, SourceFileInfo.SourcePath, StringComparison.OrdinalIgnoreCase);
#else
string path = Path.GetRelativePath(TargetPath + pathOfRelativeSourceFilePath, SourceFileInfo.SourcePath);
#endif
// Always return a path with a trailing DirectorySeparatorChar.
// Always return a path with a trailing DirectorySeparatorChar.
return path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
}
else
Expand All @@ -1620,7 +1616,7 @@ private string ParentFolderPrefix
}

return parentFolderPrefix;
}
}
}
}

Expand Down Expand Up @@ -1837,9 +1833,8 @@ private CodeExpression GetPropertyValueExpression(ITypeDescriptorContext ctx, Ty
desc.Arguments.CopyTo(args, 0);
CodeExpression[] expressions = new CodeExpression[args.Length];

if (desc.MemberInfo is MethodInfo)
if (desc.MemberInfo is MethodInfo mi)
{
MethodInfo mi = (MethodInfo)desc.MemberInfo;
ParameterInfo[] parameters = mi.GetParameters();

for (int i = 0; i < args.Length; i++)
Expand All @@ -1855,9 +1850,8 @@ private CodeExpression GetPropertyValueExpression(ITypeDescriptorContext ctx, Ty

ce = cmie;
}
else if (desc.MemberInfo is ConstructorInfo) // instance ctor invoke
else if (desc.MemberInfo is ConstructorInfo ci) // instance ctor invoke
{
ConstructorInfo ci = (ConstructorInfo)desc.MemberInfo;
ParameterInfo[] parameters = ci.GetParameters();

for (int i = 0; i < args.Length; i++)
Expand Down Expand Up @@ -1889,9 +1883,8 @@ private CodeExpression GetPropertyValueExpression(ITypeDescriptorContext ctx, Ty
private Type GetEventHandlerType(MemberInfo memberInfo)
{
Type eventHandlerType = null;
if (memberInfo is EventInfo)
if (memberInfo is EventInfo ei)
{
EventInfo ei = (EventInfo)memberInfo;
eventHandlerType = ei.EventHandlerType;
}
else
Expand Down Expand Up @@ -1945,10 +1938,10 @@ private CodeExpression GetEventDelegate(CodeContext cc, MemberInfo miEvent, stri
cDelExp = coce;
}


// The bug that this chunk of code works around was fixed but
// exposes a different bug. To work around the second bug, we
// remove the workaround for the first one.
// remove the workaround for the first one.
// Note that the initial bug was not fixed for VB, so the code block above remains.
// else if (Language == CompilerLanguage.JScript)
// {
Expand Down Expand Up @@ -2648,19 +2641,19 @@ private void GenerateInitializeComponent(bool isApp)
// - Modify the AssemblyVersionAttribute to a wildcard string (e.g. "1.2.*")
// - Set Deterministic to false in the build
// During MarkupCompilation, the AssemblyVersion property would not be set and WPF would correctly generate a resource URI without a version.
// In .NET Core/5 (or .NET Framework SDK-style projects), the same process can be used if GenerateAssemblyVersionAttribute is set to false in
// the build. However, this isn't really the idiomatic way to set the version for an assembly. Instead, developers are more likely to use the
// AssemblyVersion build property. If a developer explicitly sets the AssemblyVersion build property to a wildcard version string, we would use
// that as part of the URI here. This results in an error in Version.Parse during InitializeComponent's call tree. Instead, do as we would have
// In .NET Core/5 (or .NET Framework SDK-style projects), the same process can be used if GenerateAssemblyVersionAttribute is set to false in
// the build. However, this isn't really the idiomatic way to set the version for an assembly. Instead, developers are more likely to use the
// AssemblyVersion build property. If a developer explicitly sets the AssemblyVersion build property to a wildcard version string, we would use
// that as part of the URI here. This results in an error in Version.Parse during InitializeComponent's call tree. Instead, do as we would have
// when the developer sets a wildcard version string via AssemblyVersionAttribute and use an empty string.
string version = hasWildcard || String.IsNullOrEmpty(AssemblyVersion)
? String.Empty
? String.Empty
: COMPONENT_DELIMITER + VER + AssemblyVersion;

string token = String.IsNullOrEmpty(AssemblyPublicKeyToken)
? String.Empty
string token = String.IsNullOrEmpty(AssemblyPublicKeyToken)
? String.Empty
: COMPONENT_DELIMITER + AssemblyPublicKeyToken;

uriPart = FORWARDSLASH + AssemblyName + version + token + COMPONENT_DELIMITER + COMPONENT + FORWARDSLASH + resourceID;

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ internal bool DoCompilation(string assemblyName, string language, string rootNam
{
for (int i = 0; i < _mc.ReferenceAssemblyList.Count; i++)
{
ReferenceAssembly asmReference = _mc.ReferenceAssemblyList[i] as ReferenceAssembly;

if (asmReference != null)
if (_mc.ReferenceAssemblyList[i] is ReferenceAssembly asmReference)
{
if (string.Equals(asmReference.AssemblyName, assemblyName, StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public byte[] GetChecksum(string fileName, Guid hashGuid)
if (HostFileManager != null)
{
object docData = HostFileManager.GetFileDocData(fileName);
IPersistFileCheckSum fileChecksummer = docData as IPersistFileCheckSum;
if (fileChecksummer != null)
if (docData is IPersistFileCheckSum fileChecksummer)
{
byte[] tempBytes = new byte[1024];
int actualSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,7 @@ private void RemoveEntityByName(XmlDocument xmlProjectDoc, string sItemName, str

for (int i = 0; i < root.ChildNodes.Count; i++)
{
XmlElement nodeGroup = root.ChildNodes[i] as XmlElement;

if (nodeGroup != null && string.Equals(nodeGroup.Name, groupName, StringComparison.OrdinalIgnoreCase))
if (root.ChildNodes[i] is XmlElement nodeGroup && string.Equals(nodeGroup.Name, groupName, StringComparison.OrdinalIgnoreCase))
{
//
// This is ItemGroup element.
Expand All @@ -644,9 +642,7 @@ private void RemoveEntityByName(XmlDocument xmlProjectDoc, string sItemName, str

for (int j = 0; j < nodeGroup.ChildNodes.Count; j++)
{
XmlElement nodeItem = nodeGroup.ChildNodes[j] as XmlElement;

if (nodeItem != null && string.Equals(nodeItem.Name, sItemName, StringComparison.OrdinalIgnoreCase))
if (nodeGroup.ChildNodes[j] is XmlElement nodeItem && string.Equals(nodeItem.Name, sItemName, StringComparison.OrdinalIgnoreCase))
{
// This is the item that need to remove.
// Add it into the temporary array list.
Expand All @@ -663,13 +659,11 @@ private void RemoveEntityByName(XmlDocument xmlProjectDoc, string sItemName, str
{
foreach (object node in itemToRemove)
{
XmlElement item = node as XmlElement;

//
// Remove this item from its parent node.
// the parent node should be nodeGroup.
//
if (item != null)
if (node is XmlElement item)
{
nodeGroup.RemoveChild(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ public LineBuffer(string line)

public void SetLine(string line)
{
Content = (line == null) ? string.Empty : line;
Content = line ?? string.Empty;
Index = 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -247,10 +247,8 @@ public override bool Equals(Object o)
return false;
}

if(o is Vector)
if (o is Vector vector)
{
Vector vector = (Vector)o;

return (this == vector);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -253,7 +253,7 @@ GlyphRun glyphRun
glyphRun.EmitBackground(drawingContext, _properties.BackgroundBrush);

drawingContext.DrawGlyphRun(
foregroundBrush != null ? foregroundBrush : _properties.ForegroundBrush,
foregroundBrush ?? _properties.ForegroundBrush,
glyphRun
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -650,9 +650,9 @@ private bool ProcessStagingArea()
// PreProcessedInputEventArgs and cast it to NotifyInputEventArgs
// or ProcessInputEventArgs because a malicious user could upcast
// the object and call inappropriate methods.
NotifyInputEventArgs notifyInputEventArgs = (_notifyInputEventArgs != null) ? _notifyInputEventArgs : new NotifyInputEventArgs();
ProcessInputEventArgs processInputEventArgs = (_processInputEventArgs != null) ? _processInputEventArgs : new ProcessInputEventArgs();
PreProcessInputEventArgs preProcessInputEventArgs = (_preProcessInputEventArgs != null) ? _preProcessInputEventArgs : new PreProcessInputEventArgs();
NotifyInputEventArgs notifyInputEventArgs = _notifyInputEventArgs ?? new NotifyInputEventArgs();
ProcessInputEventArgs processInputEventArgs = _processInputEventArgs ?? new ProcessInputEventArgs();
PreProcessInputEventArgs preProcessInputEventArgs = _preProcessInputEventArgs ?? new PreProcessInputEventArgs();
_notifyInputEventArgs = null;
_processInputEventArgs = null;
_preProcessInputEventArgs = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -44,7 +44,7 @@ public QueryCursorEventArgs(MouseDevice mouse, int timestamp, StylusDevice stylu
public Cursor Cursor
{
get {return _cursor;}
set {_cursor = ((value == null) ? Cursors.None : value);}
set {_cursor = (value ?? Cursors.None);}
}

/// <summary>
Expand Down
Loading
Loading