diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig
index 95018f411b1..cb9ee1477bb 100644
--- a/src/Microsoft.DotNet.Wpf/src/.editorconfig
+++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig
@@ -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
diff --git a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemData/SystemDataExtension.cs b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemData/SystemDataExtension.cs
index 95ecbc5f39c..5830eab48ad 100644
--- a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemData/SystemDataExtension.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemData/SystemDataExtension.cs
@@ -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.
@@ -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];
diff --git a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/XmlNodeComparer.cs b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/XmlNodeComparer.cs
index e1800994c6e..d9358f3ba09 100644
--- a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/XmlNodeComparer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemXml/XmlNodeComparer.cs
@@ -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.
@@ -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)
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs
index e13d4188ec2..c93b028b9c0 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs
@@ -203,7 +203,7 @@ public static bool HasInternals
///Complies list of file items comprising an Application.
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.
@@ -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;
@@ -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);
}
}
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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\\"
@@ -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
@@ -1620,7 +1616,7 @@ private string ParentFolderPrefix
}
return parentFolderPrefix;
- }
+ }
}
}
@@ -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++)
@@ -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++)
@@ -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
@@ -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)
// {
@@ -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;
//
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs
index 17a36b4ee52..1710c1cda32 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/CompilerWrapper.cs
@@ -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))
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs
index 87ba0a58fb8..b1cf4aec055 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs
@@ -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;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
index 02e05847c27..a4272ba5eaf 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
@@ -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.
@@ -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.
@@ -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);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs
index b0081434b08..5a5cf7e9a45 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs
@@ -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;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/MatchingStyle.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/MatchingStyle.cs
index f972c7dad8b..52ee9472f33 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/MatchingStyle.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/MatchingStyle.cs
@@ -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.
@@ -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
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextShapeableCharacters.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextShapeableCharacters.cs
index fad7f52ce11..a5b254362dd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextShapeableCharacters.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextShapeableCharacters.cs
@@ -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.
@@ -253,7 +253,7 @@ GlyphRun glyphRun
glyphRun.EmitBackground(drawingContext, _properties.BackgroundBrush);
drawingContext.DrawGlyphRun(
- foregroundBrush != null ? foregroundBrush : _properties.ForegroundBrush,
+ foregroundBrush ?? _properties.ForegroundBrush,
glyphRun
);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs
index 7404141b4b8..42844a31a4c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs
@@ -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.
@@ -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;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/QueryCursorEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/QueryCursorEventArgs.cs
index 80118953638..24d32e73bf4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/QueryCursorEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/QueryCursorEventArgs.cs
@@ -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.
@@ -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);}
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs
index 5322c8b00bf..b5e28430d3c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs
@@ -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.
@@ -683,10 +683,8 @@ public bool Equals(Color color)
/// Whether or not the two colors are equal
public override bool Equals(object o)
{
- if (o is Color)
+ if (o is Color color)
{
- Color color = (Color)o;
-
return (this == color);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/BrushValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/BrushValueSerializer.cs
index fed36e95cb6..87bcc5abab6 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/BrushValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/BrushValueSerializer.cs
@@ -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.
@@ -66,11 +66,10 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Brush)
+ if (value is Brush instance)
{
- Brush instance = (Brush) value;
// When invoked by the serialization engine we can convert to string only for some instances
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
if (!instance.CanSerializeToString())
{
// Let base throw an exception.
@@ -78,7 +77,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
}
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/CacheModeValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/CacheModeValueSerializer.cs
index e01460dc2ed..627c543094a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/CacheModeValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/CacheModeValueSerializer.cs
@@ -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.
@@ -66,11 +66,10 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is CacheMode)
+ if (value is CacheMode instance)
{
- CacheMode instance = (CacheMode) value;
// When invoked by the serialization engine we can convert to string only for some instances
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
if (!instance.CanSerializeToString())
{
// Let base throw an exception.
@@ -78,7 +77,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
}
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/DoubleCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/DoubleCollectionValueSerializer.cs
index 50b15a9c61f..3e11a5009a0 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/DoubleCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/DoubleCollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is DoubleCollection)
+ if (value is DoubleCollection instance)
{
- DoubleCollection instance = (DoubleCollection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/GeometryValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/GeometryValueSerializer.cs
index e6da570e5a1..65783d4b870 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/GeometryValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/GeometryValueSerializer.cs
@@ -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.
@@ -66,11 +66,10 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Geometry)
+ if (value is Geometry instance)
{
- Geometry instance = (Geometry) value;
// When invoked by the serialization engine we can convert to string only for some instances
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
if (!instance.CanSerializeToString())
{
// Let base throw an exception.
@@ -78,7 +77,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
}
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/Int32CollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/Int32CollectionValueSerializer.cs
index 271c0277c41..32fefedde6b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/Int32CollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/Int32CollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Int32Collection)
+ if (value is Int32Collection instance)
{
- Int32Collection instance = (Int32Collection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PathFigureCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PathFigureCollectionValueSerializer.cs
index 74234ea2374..ec3fe0a1baa 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PathFigureCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PathFigureCollectionValueSerializer.cs
@@ -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.
@@ -66,11 +66,10 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is PathFigureCollection)
+ if (value is PathFigureCollection instance)
{
- PathFigureCollection instance = (PathFigureCollection) value;
// When invoked by the serialization engine we can convert to string only for some instances
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
if (!instance.CanSerializeToString())
{
// Let base throw an exception.
@@ -78,7 +77,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
}
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PointCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PointCollectionValueSerializer.cs
index 3ea8766ddf2..1430e4e7f3c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PointCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/PointCollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is PointCollection)
+ if (value is PointCollection instance)
{
- PointCollection instance = (PointCollection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/TransformValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/TransformValueSerializer.cs
index fcf38d59396..cfdccf59d14 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/TransformValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/TransformValueSerializer.cs
@@ -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.
@@ -66,11 +66,10 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Transform)
+ if (value is Transform instance)
{
- Transform instance = (Transform) value;
// When invoked by the serialization engine we can convert to string only for some instances
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
if (!instance.CanSerializeToString())
{
// Let base throw an exception.
@@ -78,7 +77,7 @@ public override string ConvertToString(object value, IValueSerializerContext con
}
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/VectorCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/VectorCollectionValueSerializer.cs
index 9d04079f928..ddb553f1155 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/VectorCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Converters/Generated/VectorCollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is VectorCollection)
+ if (value is VectorCollection instance)
{
- VectorCollection instance = (VectorCollection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingDrawingContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingDrawingContext.cs
index 3fbb67463dc..b4f98cde756 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingDrawingContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingDrawingContext.cs
@@ -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.
@@ -1026,8 +1026,7 @@ public override void PushEffect(
// NOTE:Disabling this API for now
_currentDrawingGroup.BitmapEffect = effect;
- _currentDrawingGroup.BitmapEffectInput = (effectInput != null) ?
- effectInput : new BitmapEffectInput();
+ _currentDrawingGroup.BitmapEffectInput = effectInput ?? new BitmapEffectInput();
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs
index c004756c111..f0a0a6c42f4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs
@@ -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.
@@ -191,7 +191,7 @@ public Uri BaseUri
public override string ToString()
{
string source = _familyIdentifier.Source;
- return source != null ? source : string.Empty;
+ return source ?? string.Empty;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs
index 49d540e56bc..3f591db91e0 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ImageSourceConverter.cs
@@ -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.
@@ -105,10 +105,8 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
null
);
}
- else if (value is byte[])
+ else if (value is byte[] bytes)
{
- byte[] bytes = (byte[])value;
-
if (bytes != null)
{
Stream memStream = null;
@@ -133,10 +131,8 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
);
}
}
- else if (value is Stream)
+ else if (value is Stream stream)
{
- Stream stream = (Stream)value;
-
return BitmapFrame.Create(
stream,
BitmapCreateOptions.None,
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/StreamGeometry.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/StreamGeometry.cs
index 313d03286ae..a9ff4b42c48 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/StreamGeometry.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/StreamGeometry.cs
@@ -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.
@@ -396,9 +396,7 @@ internal override void UpdateResource(DUCE.Channel channel, bool skipOnChannelCh
data.hTransform = hTransform;
data.FillRule = FillRule;
- byte[] pathDataToMarshal = _data == null ?
- Geometry.GetEmptyPathGeometryData().SerializedData :
- _data;
+ byte[] pathDataToMarshal = _data ?? GetEmptyPathGeometryData().SerializedData;
unsafe
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Matrix3DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Matrix3DValueSerializer.cs
index 8e36638c27c..3dafe3c951e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Matrix3DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Matrix3DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Matrix3D)
+ if (value is Matrix3D instance)
{
- Matrix3D instance = (Matrix3D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DCollectionValueSerializer.cs
index 1d23344d728..13628c7a6dc 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DCollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Point3DCollection)
+ if (value is Point3DCollection instance)
{
- Point3DCollection instance = (Point3DCollection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DValueSerializer.cs
index 0cd4d07afed..fbe9ab1bd6e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point3DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Point3D)
+ if (value is Point3D instance)
{
- Point3D instance = (Point3D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point4DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point4DValueSerializer.cs
index 19fae559b4c..32b0e1ba148 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point4DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Point4DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Point4D)
+ if (value is Point4D instance)
{
- Point4D instance = (Point4D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/QuaternionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/QuaternionValueSerializer.cs
index b9e6f68b9ae..db28bfed7b8 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/QuaternionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/QuaternionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Quaternion)
+ if (value is Quaternion instance)
{
- Quaternion instance = (Quaternion) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Rect3DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Rect3DValueSerializer.cs
index 47f5627958d..e8935c2b15c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Rect3DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Rect3DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Rect3D)
+ if (value is Rect3D instance)
{
- Rect3D instance = (Rect3D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Size3DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Size3DValueSerializer.cs
index 4857164f5dd..81a1eaecbe0 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Size3DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Size3DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Size3D)
+ if (value is Size3D instance)
{
- Size3D instance = (Size3D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DCollectionValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DCollectionValueSerializer.cs
index c051f1604fe..30aa5617897 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DCollectionValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DCollectionValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Vector3DCollection)
+ if (value is Vector3DCollection instance)
{
- Vector3DCollection instance = (Vector3DCollection) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DValueSerializer.cs
index dfd84600ef9..48eb1498609 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Converters/Generated/Vector3DValueSerializer.cs
@@ -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.
@@ -63,12 +63,11 @@ public override object ConvertFromString(string value, IValueSerializerContext c
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
- if (value is Vector3D)
+ if (value is Vector3D instance)
{
- Vector3D instance = (Vector3D) value;
- #pragma warning suppress 6506 // instance is obviously not null
+#pragma warning suppress 6506 // instance is obviously not null
return instance.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport2DVisual3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport2DVisual3D.cs
index b6486544643..25e539a4598 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport2DVisual3D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport2DVisual3D.cs
@@ -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.
@@ -468,36 +468,32 @@ private void SwapInCyclicBrush(Material material)
{
Material currMaterial = materialStack.Pop();
- if (currMaterial is DiffuseMaterial)
+ if (currMaterial is DiffuseMaterial diffMaterial)
{
- DiffuseMaterial diffMaterial = (DiffuseMaterial)currMaterial;
if ((Boolean)diffMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
{
diffMaterial.Brush = internalBrush;
numMaterialsSwapped++;
}
}
- else if (currMaterial is EmissiveMaterial)
+ else if (currMaterial is EmissiveMaterial emmMaterial)
{
- EmissiveMaterial emmMaterial = (EmissiveMaterial)currMaterial;
if ((Boolean)emmMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
{
emmMaterial.Brush = internalBrush;
numMaterialsSwapped++;
}
}
- else if (currMaterial is SpecularMaterial)
+ else if (currMaterial is SpecularMaterial specMaterial)
{
- SpecularMaterial specMaterial = (SpecularMaterial)currMaterial;
if ((Boolean)specMaterial.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
{
specMaterial.Brush = internalBrush;
numMaterialsSwapped++;
}
}
- else if (currMaterial is MaterialGroup)
+ else if (currMaterial is MaterialGroup matGroup)
{
- MaterialGroup matGroup = (MaterialGroup)currMaterial;
// the IsVisualHostMaterialProperty should not be set on a MaterialGroup - verify that
if ((Boolean)matGroup.GetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty))
@@ -507,10 +503,10 @@ private void SwapInCyclicBrush(Material material)
// iterate over the children and put them on the stack of materials to modify
MaterialCollection children = matGroup.Children;
-
+
if (children != null)
{
- for (int i=0, count = children.Count; i < count; i++)
+ for (int i = 0, count = children.Count; i < count; i++)
{
Material m = children[i];
materialStack.Push(m);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs
index 3da58ffa113..2cb4f878193 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/MarkedHighlightComponent.cs
@@ -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.
@@ -54,7 +54,7 @@ public MarkedHighlightComponent(XmlQualifiedName type, DependencyObject host)
{
ArgumentNullException.ThrowIfNull(type);
- _DPHost = host == null ? this : host;
+ _DPHost = host ?? this;
ClipToBounds = false;
//create anchor highlight. The second parameter controls
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ConnectionPointCookie.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ConnectionPointCookie.cs
index f9998b07633..816365e1bd8 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ConnectionPointCookie.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ConnectionPointCookie.cs
@@ -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.
@@ -23,10 +23,8 @@ internal class ConnectionPointCookie
internal ConnectionPointCookie(object source, object sink, Type eventInterface)
{
Exception ex = null;
- if (source is UnsafeNativeMethods.IConnectionPointContainer)
+ if (source is UnsafeNativeMethods.IConnectionPointContainer cpc)
{
- UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source;
-
try
{
Guid tmp = eventInterface.GUID;
@@ -37,11 +35,11 @@ internal ConnectionPointCookie(object source, object sink, Type eventInterface)
}
catch (Exception e)
{
- if(CriticalExceptions.IsCriticalException(e))
+ if (CriticalExceptions.IsCriticalException(e))
{
throw;
}
-
+
connectionPoint = null;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs
index 203d24acd21..28b655cd1ae 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ViewManager.cs
@@ -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.
@@ -176,9 +176,8 @@ public override int GetHashCode()
public override bool Equals(object o)
{
- if (o is WeakRefKey)
+ if (o is WeakRefKey ck)
{
- WeakRefKey ck = (WeakRefKey)o;
object c1 = Target;
object c2 = ck.Target;
@@ -555,7 +554,7 @@ internal ViewRecord GetViewRecord(object collection, CollectionViewSource cvs, T
else
{
// collection is not a factory - create an appropriate view
- IList il = (ilsList != null) ? ilsList : collection as IList;
+ IList il = ilsList ?? collection as IList;
if (il != null)
{
// create a view on an IList or IBindingList
@@ -583,7 +582,7 @@ internal ViewRecord GetViewRecord(object collection, CollectionViewSource cvs, T
throw new ArgumentException(SR.Format(SR.CollectionView_WrongType, collectionViewType.Name));
// if collection is IListSource, get its list first (bug 1023903)
- object arg = (ilsList != null) ? ilsList : collection;
+ object arg = ilsList ?? collection;
try
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizableResourceBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizableResourceBuilder.cs
index 2a8917c5f12..34bdbe37ef7 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizableResourceBuilder.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizableResourceBuilder.cs
@@ -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.
@@ -565,7 +565,7 @@ LocalizabilityAttribute second
{
if (first == null || second == null)
{
- return (first == null) ? second : first;
+ return first ?? second;
}
// min of two readability enum. The less the more restrictive.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/SelectionEditor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/SelectionEditor.cs
index bc1656c125d..cb98fa0c8df 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/SelectionEditor.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/SelectionEditor.cs
@@ -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.
@@ -165,7 +165,7 @@ private void OnAdornerMouseButtonDownEvent(object sender, MouseButtonEventArgs a
// If the current captured device is Stylus, we should activate the LassoSelectionBehavior with
// the Stylus. Otherwise, use mouse.
EditingCoordinator.ActivateDynamicBehavior(EditingCoordinator.LassoSelectionBehavior,
- args.StylusDevice != null ? args.StylusDevice : args.Device);
+ args.StylusDevice ?? args.Device);
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs
index ffa0d791abc..ae8dead2c0d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs
@@ -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.
@@ -292,7 +292,7 @@ internal IInputElement InputHitTestCore(Point point)
ie = _ptsPage.InputHitTest(point);
}
}
- return (ie != null) ? ie : _structuralCache.FormattingOwner as IInputElement;
+ return ie ?? _structuralCache.FormattingOwner as IInputElement;
}
///
@@ -392,7 +392,7 @@ internal ReadOnlyCollection FloatingElementResults
}
///
- /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
+ /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
///
///
/// Child element whose DesiredSize has changed
@@ -1212,7 +1212,7 @@ IEnumerator IContentHost.HostedElements
}
///
- /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
+ /// Called when a UIElement-derived class which is hosted by a IContentHost changes it’s DesiredSize
///
///
/// Child element whose DesiredSize has changed
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs
index 9999421b809..46fa18c169d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs
@@ -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.
@@ -212,7 +212,7 @@ internal override TextSpan GetPrecedingText
precedingText = new CharacterBufferRange(precedingTextString, 0, precedingTextString.Length);
StaticTextPointer pointer = position.CreateStaticPointer();
- DependencyObject element = (pointer.Parent != null) ? pointer.Parent : _paraClient.Paragraph.Element;
+ DependencyObject element = pointer.Parent ?? _paraClient.Paragraph.Element;
culture = DynamicPropertyReader.GetCultureInfo(element);
}
@@ -408,9 +408,8 @@ internal ContainerVisual CreateVisual()
foreach (TextSpan textSpan in runs)
{
TextRun run = (TextRun)textSpan.Value;
- if (run is InlineObjectRun)
+ if (run is InlineObjectRun inlineObject)
{
- InlineObjectRun inlineObject = (InlineObjectRun)run;
FlowDirection flowDirection;
Rect rect = GetBoundsFromPosition(dcpRun, run.Length, out flowDirection);
Debug.Assert(DoubleUtil.GreaterThanOrClose(rect.Width, 0), "Negative inline object's width.");
@@ -422,7 +421,7 @@ internal ContainerVisual CreateVisual()
ContainerVisual parent = currentParent as ContainerVisual;
Invariant.Assert(parent != null, "Parent should always derives from ContainerVisual.");
parent.Children.Remove(inlineObject.UIElementIsland);
- }
+ }
if (!line.HasCollapsed || ((rect.Left + inlineObject.UIElementIsland.Root.DesiredSize.Width) < line.Width))
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalTextSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalTextSource.cs
index d9a1cf1fb4f..cbf8e120733 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalTextSource.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/OptimalTextSource.cs
@@ -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.
@@ -161,7 +161,7 @@ internal override TextSpan GetPrecedingText
StaticTextPointer pointer = position.CreateStaticPointer();
- DependencyObject element = (pointer.Parent != null) ? pointer.Parent : _paraClient.Paragraph.Element;
+ DependencyObject element = pointer.Parent ?? _paraClient.Paragraph.Element;
culture = DynamicPropertyReader.GetCultureInfo(element);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs
index e246099b6a0..cb2f57a7a06 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsHost.cs
@@ -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.
@@ -1978,17 +1978,15 @@ internal unsafe int GetAttachedObjectsBeforeTextLine(
for(int objectIndex = 0; objectIndex < attachedObjects.Count; objectIndex++)
{
- if(attachedObjects[objectIndex] is FigureObject)
+ if (attachedObjects[objectIndex] is FigureObject figureObject)
{
- FigureObject figureObject = (FigureObject) attachedObjects[objectIndex];
-
rgnmpAttachedObject[objectIndex] = figureObject.Para.Handle;
rgdcpAnchor[objectIndex] = figureObject.Dcp;
rgidobj[objectIndex] = PTS.fsidobjFigure;
}
else
{
- FloaterObject floaterObject = (FloaterObject) attachedObjects[objectIndex];
+ FloaterObject floaterObject = (FloaterObject)attachedObjects[objectIndex];
rgnmpAttachedObject[objectIndex] = floaterObject.Para.Handle;
rgdcpAnchor[objectIndex] = floaterObject.Dcp;
@@ -2095,17 +2093,15 @@ internal unsafe int GetAttachedObjectsInTextLine(
for(int objectIndex = 0; objectIndex < attachedObjects.Count; objectIndex++)
{
- if(attachedObjects[objectIndex] is FigureObject)
+ if (attachedObjects[objectIndex] is FigureObject figureObject)
{
- FigureObject figureObject = (FigureObject) attachedObjects[objectIndex];
-
rgnmpAttachedObject[objectIndex] = figureObject.Para.Handle;
rgdcpAnchor[objectIndex] = figureObject.Dcp;
rgidobj[objectIndex] = PTS.fsidobjFigure;
}
else
{
- FloaterObject floaterObject = (FloaterObject) attachedObjects[objectIndex];
+ FloaterObject floaterObject = (FloaterObject)attachedObjects[objectIndex];
rgnmpAttachedObject[objectIndex] = floaterObject.Para.Handle;
rgdcpAnchor[objectIndex] = floaterObject.Dcp;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/ComplexLine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/ComplexLine.cs
index 71e9d233c11..9c9a2c82f2a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/ComplexLine.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/ComplexLine.cs
@@ -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.
@@ -101,7 +101,7 @@ public override TextSpan GetPrecedingText(i
precedingText = new CharacterBufferRange(precedingTextString, 0, precedingTextString.Length);
StaticTextPointer pointer = position.CreateStaticPointer();
- DependencyObject element = (pointer.Parent != null) ? pointer.Parent : _owner;
+ DependencyObject element = pointer.Parent ?? _owner;
culture = DynamicPropertyReader.GetCultureInfo(element);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
index faedef8b8bb..f7acb0ce97a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs
@@ -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.
@@ -1707,9 +1707,8 @@ private void OnGetPageNumberCompleted(object sender, GetPageNumberCompletedEvent
//Ensure that the UserState passed with this event contains an
//MakeVisibleData object. If not, we ignore it as this event
//could have originated from someone else calling GetPageNumberAsync.
- if (e.UserState is MakeVisibleData)
+ if (e.UserState is MakeVisibleData data)
{
- MakeVisibleData data = (MakeVisibleData)e.UserState;
MakeVisibleAsync(data, e.PageNumber);
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextContainerHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextContainerHelper.cs
index 540abe66535..15cadac88ae 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextContainerHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextContainerHelper.cs
@@ -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.
@@ -700,13 +700,11 @@ internal static int GetCPFromEmbeddedObject(UIElement embeddedObject, ElementEdg
{
Invariant.Assert(edge == ElementEdge.BeforeStart || edge == ElementEdge.AfterEnd, "Cannot retrieve CP from the content of embedded object.");
int cp = -1;
- if (embeddedObject is FrameworkElement)
+ if (embeddedObject is FrameworkElement fe)
{
- FrameworkElement fe = (FrameworkElement)embeddedObject;
//likely the embedded element is hosted by some TextElement, like InlineUIContainer or BlockUIContainer
- if (fe.Parent is TextElement)
+ if (fe.Parent is TextElement uiContainer)
{
- TextElement uiContainer = (TextElement)fe.Parent;
cp = (edge == ElementEdge.BeforeStart) ? uiContainer.ContentStartOffset : uiContainer.ContentEndOffset;
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs
index 2757d3cb501..502bdbada89 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs
@@ -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.
@@ -199,9 +199,8 @@ internal override Geometry GetTightBoundingGeometryFromTextPositions(ITextPointe
private Rect CalculateViewportRect()
{
Rect visibleRect = Rect.Empty;
- if (RenderScope is IScrollInfo)
+ if (RenderScope is IScrollInfo scrollInfo)
{
- IScrollInfo scrollInfo = (IScrollInfo)RenderScope;
if (scrollInfo.ViewportWidth != 0 && scrollInfo.ViewportHeight != 0)
{
visibleRect = new Rect(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset, scrollInfo.ViewportWidth, scrollInfo.ViewportHeight);
@@ -816,10 +815,8 @@ private ITextPointer GetTextPositionFromPoint(ParagraphResult paragraph, Point p
}
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult) // Subpage implies new coordinate system.
{
- // Subpage implies new coordinate system.
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
point.X -= subpageParagraphResult.ContentOffset.X;
point.Y -= subpageParagraphResult.ContentOffset.Y;
@@ -830,9 +827,8 @@ private ITextPointer GetTextPositionFromPoint(ParagraphResult paragraph, Point p
{
ReadOnlyCollection columns;
ReadOnlyCollection nestedFloatingElements;
- if (paragraph is FloaterParagraphResult)
+ if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
columns = floaterParagraphResult.Columns;
nestedFloatingElements = floaterParagraphResult.FloatingElements;
TransformToSubpage(ref point, floaterParagraphResult.ContentOffset);
@@ -1030,10 +1026,8 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta
cellInfo = ((TableParagraphResult)paragraph).GetCellInfoFromPoint(point);
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult) // Subpage implies new coordinate system.
{
- // Subpage implies new coordinate system.
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
point.X -= subpageParagraphResult.ContentOffset.X;
point.Y -= subpageParagraphResult.ContentOffset.Y;
@@ -1044,10 +1038,8 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta
cellInfo.Adjust(new Point(subpageParagraphResult.ContentOffset.X, subpageParagraphResult.ContentOffset.Y));
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult) // Subpage implies new coordinate system.
{
- // Subpage implies new coordinate system.
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
TransformToSubpage(ref point, figureParagraphResult.ContentOffset);
cellInfo = GetCellInfoFromPoint(figureParagraphResult.Columns, figureParagraphResult.FloatingElements, point, tableFilter);
if (cellInfo != null)
@@ -1055,10 +1047,8 @@ private CellInfo GetCellInfoFromPoint(ParagraphResult paragraph, Point point, Ta
cellInfo.Adjust(new Point(figureParagraphResult.ContentOffset.X, figureParagraphResult.ContentOffset.Y));
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult) // Subpage implies new coordinate system.
{
- // Subpage implies new coordinate system.
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
TransformToSubpage(ref point, floaterParagraphResult.ContentOffset);
cellInfo = GetCellInfoFromPoint(floaterParagraphResult.Columns, floaterParagraphResult.FloatingElements, point, tableFilter);
if (cellInfo != null)
@@ -1191,10 +1181,8 @@ private Rect GetRectangleFromTextPosition(ParagraphResult paragraph, ITextPointe
}
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult) // Subpage implies new coordinate system.
{
- // Subpage implies new coordinate system.
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
rect = GetRectangleFromTextPosition(subpageParagraphResult.Columns, subpageParagraphResult.FloatingElements, position);
if (rect != Rect.Empty)
{
@@ -1202,9 +1190,8 @@ private Rect GetRectangleFromTextPosition(ParagraphResult paragraph, ITextPointe
rect.Y += subpageParagraphResult.ContentOffset.Y;
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Columns collection is null.");
@@ -1216,9 +1203,8 @@ private Rect GetRectangleFromTextPosition(ParagraphResult paragraph, ITextPointe
TransformFromSubpage(ref rect, floaterParagraphResult.ContentOffset);
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Columns collection is null.");
@@ -1401,19 +1387,16 @@ private static Geometry GetTightBoundingGeometryFromTextPositionsInFloatingEleme
Geometry paragraphGeometry = null;
Invariant.Assert(floatingElements[i] is FloaterParagraphResult ||
floatingElements[i] is FigureParagraphResult);
- if (floatingElements[i] is FloaterParagraphResult)
+ // Transform visible rect to subpage coordinates, and transform geometry from subpage coordinates
+ if (floatingElements[i] is FloaterParagraphResult floaterParagraphResult)
{
- // Transform visible rect to subpage coordinates, and transform geometry from subpage coordinates
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)floatingElements[i];
TransformToSubpage(ref visibleRectThisPara, floaterParagraphResult.ContentOffset);
paragraphGeometry = floaterParagraphResult.GetTightBoundingGeometryFromTextPositions(startPosition, endPosition, visibleRectThisPara, out success);
// Geometry within the floater needs to be transformed from subpage content
TransformFromSubpage(paragraphGeometry, floaterParagraphResult.ContentOffset);
}
- else if (floatingElements[i] is FigureParagraphResult)
+ else if (floatingElements[i] is FigureParagraphResult figureParagraphResult) // Transform visible rect to subpage coordinates, and transform geometry from subpage coordinates
{
- // Transform visible rect to subpage coordinates, and transform geometry from subpage coordinates
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)floatingElements[i];
TransformToSubpage(ref visibleRectThisPara, figureParagraphResult.ContentOffset);
paragraphGeometry = figureParagraphResult.GetTightBoundingGeometryFromTextPositions(startPosition, endPosition, visibleRectThisPara, out success);
// Geometry within the figure needs to be transformed from subpage content
@@ -1510,9 +1493,8 @@ private bool IsAtCaretUnitBoundary(ParagraphResult paragraph, ITextPointer posit
isAtCaretUnitBoundary = IsAtCaretUnitBoundary(nestedParagraphs, _emptyParagraphCollection, position);
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult)
{
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
ReadOnlyCollection columns = subpageParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = subpageParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1522,9 +1504,8 @@ private bool IsAtCaretUnitBoundary(ParagraphResult paragraph, ITextPointer posit
isAtCaretUnitBoundary = IsAtCaretUnitBoundary(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1534,9 +1515,8 @@ private bool IsAtCaretUnitBoundary(ParagraphResult paragraph, ITextPointer posit
isAtCaretUnitBoundary = IsAtCaretUnitBoundary(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1637,9 +1617,8 @@ private ITextPointer GetNextCaretUnitPosition(ParagraphResult paragraph, ITextPo
nextCaretPosition = GetNextCaretUnitPosition(nestedParagraphs, _emptyParagraphCollection, position, direction);
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult)
{
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
ReadOnlyCollection columns = subpageParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = subpageParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1649,9 +1628,8 @@ private ITextPointer GetNextCaretUnitPosition(ParagraphResult paragraph, ITextPo
nextCaretPosition = GetNextCaretUnitPosition(columns, nestedFloatingElements, position, direction);
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1661,9 +1639,8 @@ private ITextPointer GetNextCaretUnitPosition(ParagraphResult paragraph, ITextPo
nextCaretPosition = GetNextCaretUnitPosition(columns, nestedFloatingElements, position, direction);
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1760,9 +1737,8 @@ private ITextPointer GetBackspaceCaretUnitPosition(ParagraphResult paragraph, IT
backspaceCaretPosition = GetBackspaceCaretUnitPosition(nestedParagraphs, _emptyParagraphCollection, position);
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult)
{
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
ReadOnlyCollection columns = subpageParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = subpageParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1772,9 +1748,8 @@ private ITextPointer GetBackspaceCaretUnitPosition(ParagraphResult paragraph, IT
backspaceCaretPosition = GetBackspaceCaretUnitPosition(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -1784,9 +1759,8 @@ private ITextPointer GetBackspaceCaretUnitPosition(ParagraphResult paragraph, IT
backspaceCaretPosition = GetBackspaceCaretUnitPosition(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -2355,9 +2329,8 @@ private TextSegment GetLineRangeFromPosition(ParagraphResult paragraph, ITextPoi
lineRange = GetLineRangeFromPosition(nestedParagraphs, _emptyParagraphCollection, position);
}
}
- else if (paragraph is SubpageParagraphResult)
+ else if (paragraph is SubpageParagraphResult subpageParagraphResult)
{
- SubpageParagraphResult subpageParagraphResult = (SubpageParagraphResult)paragraph;
ReadOnlyCollection columns = subpageParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = subpageParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -2367,9 +2340,8 @@ private TextSegment GetLineRangeFromPosition(ParagraphResult paragraph, ITextPoi
lineRange = GetLineRangeFromPosition(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FigureParagraphResult)
+ else if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -2379,9 +2351,8 @@ private TextSegment GetLineRangeFromPosition(ParagraphResult paragraph, ITextPoi
lineRange = GetLineRangeFromPosition(columns, nestedFloatingElements, position);
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -2563,10 +2534,8 @@ private ITextPointer GetPositionAtNextLine(ReadOnlyCollection p
}
}
}
- else if (paragraphs[paragraphIndex] is TableParagraphResult)
+ else if (paragraphs[paragraphIndex] is TableParagraphResult tableResult) // c) TableParagraph - process nested paragraphs.
{
- // c) TableParagraph - process nested paragraphs.
- TableParagraphResult tableResult = (TableParagraphResult)paragraphs[paragraphIndex];
CellParaClient cpcStart = tableResult.GetCellParaClientFromPosition(position);
CellParaClient cpcCur = cpcStart;
Rect paragraphBox = paragraphs[paragraphIndex].LayoutBox;
@@ -2828,9 +2797,8 @@ private ITextPointer GetPositionAtNextLineFromSiblingPara(ReadOnlyCollection glyphRuns, ITextPointer s
for (int index = 0; index < paragraphs.Count; index++)
{
ParagraphResult paragraph = paragraphs[index];
- if (paragraph is TextParagraphResult)
+ if (paragraph is TextParagraphResult tpr)
{
- TextParagraphResult tpr = (TextParagraphResult)paragraph;
if (start.CompareTo(tpr.EndPosition) < 0 && end.CompareTo(tpr.StartPosition) > 0)
{
ITextPointer startRange = start.CompareTo(tpr.StartPosition) < 0 ? tpr.StartPosition : start;
@@ -3190,9 +3157,8 @@ private void GetGlyphRunsFromFloatingElements(List glyphRuns, ITextPoi
{
success = true;
ITextPointer endThisPara = end.CompareTo(paragraph.EndPosition) < 0 ? end : paragraph.EndPosition;
- if (paragraph is FigureParagraphResult)
+ if (paragraph is FigureParagraphResult figureParagraphResult)
{
- FigureParagraphResult figureParagraphResult = (FigureParagraphResult)paragraph;
ReadOnlyCollection columns = figureParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = figureParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
@@ -3202,9 +3168,8 @@ private void GetGlyphRunsFromFloatingElements(List glyphRuns, ITextPoi
GetGlyphRuns(glyphRuns, start, endThisPara, columns, nestedFloatingElements);
}
}
- else if (paragraph is FloaterParagraphResult)
+ else if (paragraph is FloaterParagraphResult floaterParagraphResult)
{
- FloaterParagraphResult floaterParagraphResult = (FloaterParagraphResult)paragraph;
ReadOnlyCollection columns = floaterParagraphResult.Columns;
ReadOnlyCollection nestedFloatingElements = floaterParagraphResult.FloatingElements;
Invariant.Assert(columns != null, "Column collection is null.");
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs
index f3e3c76357f..5d1daaee60c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/CommonItemDialog.cs
@@ -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.
@@ -121,7 +121,7 @@ public string DefaultDirectory
get
{
// Avoid returning a null string - return String.Empty instead.
- return _defaultDirectory == null ? String.Empty : _defaultDirectory;
+ return _defaultDirectory ?? string.Empty;
}
set
{
@@ -160,7 +160,7 @@ public string InitialDirectory
get
{
// Avoid returning a null string - return String.Empty instead.
- return _initialDirectory == null ? String.Empty : _initialDirectory;
+ return _initialDirectory ?? string.Empty;
}
set
{
@@ -179,7 +179,7 @@ public string RootDirectory
get
{
// Avoid returning a null string - return String.Empty instead.
- return _rootDirectory == null ? String.Empty : _rootDirectory;
+ return _rootDirectory ?? string.Empty;
}
set
{
@@ -218,7 +218,7 @@ public string Title
get
{
// Avoid returning a null string - return String.Empty instead.
- return _title == null ? String.Empty : _title;
+ return _title ?? string.Empty;
}
set
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs
index 079f3d8c503..ca5e661559f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs
@@ -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.
@@ -262,7 +262,7 @@ public string DefaultExt
{
// For string properties, it's important to not return null, as an empty
// string tends to make more sense to beginning developers.
- return _defaultExtension == null ? String.Empty : _defaultExtension;
+ return _defaultExtension ?? string.Empty;
}
set
@@ -307,7 +307,7 @@ public string Filter
{
// For string properties, it's important to not return null, as an empty
// string tends to make more sense to beginning developers.
- return _filter == null ? String.Empty : _filter;
+ return _filter ?? string.Empty;
}
set
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs
index 67f064fc1b4..243e143107f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/CalendarAutomationPeer.cs
@@ -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.
@@ -382,9 +382,8 @@ IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
if (childRow == row && childColumn == column)
{
object dataContext = (child as FrameworkElement).DataContext;
- if (dataContext is DateTime)
+ if (dataContext is DateTime date)
{
- DateTime date = (DateTime)dataContext;
AutomationPeer peer = GetOrCreateDateTimeAutomationPeer(date, OwningCalendar.DisplayMode);
return ProviderFromPeer(peer);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FrameworkContentElementAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FrameworkContentElementAutomationPeer.cs
index f6b595b0668..c02ee1a4e82 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FrameworkContentElementAutomationPeer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/FrameworkContentElementAutomationPeer.cs
@@ -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.
@@ -44,7 +44,7 @@ protected override string GetAutomationIdCore()
}
}
- return result == null ? string.Empty : result;
+ return result ?? string.Empty;
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs
index 5b5be0b384a..db8c19c2aa4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemAutomationPeer.cs
@@ -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.
@@ -677,7 +677,7 @@ private object RawItem
if (iwr != null)
{
object item = iwr.Target;
- return (item == null) ? DependencyProperty.UnsetValue : item;
+ return item ?? DependencyProperty.UnsetValue;
}
else
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs
index 00c94607c9d..0e150e4335c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Calendar.cs
@@ -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.
@@ -911,34 +911,32 @@ internal void OnDayClick(DateTime selectedDate)
internal void OnCalendarButtonPressed(CalendarButton b, bool switchDisplayMode)
{
- if (b.DataContext is DateTime)
+ if (b.DataContext is DateTime d)
{
- DateTime d = (DateTime)b.DataContext;
-
DateTime? newDate = null;
CalendarMode newMode = CalendarMode.Month;
switch (this.DisplayMode)
{
case CalendarMode.Month:
- {
- Debug.Assert(false);
- break;
- }
+ {
+ Debug.Assert(false);
+ break;
+ }
case CalendarMode.Year:
- {
- newDate = DateTimeHelper.SetYearMonth(this.DisplayDate, d);
- newMode = CalendarMode.Month;
- break;
- }
+ {
+ newDate = DateTimeHelper.SetYearMonth(this.DisplayDate, d);
+ newMode = CalendarMode.Month;
+ break;
+ }
case CalendarMode.Decade:
- {
- newDate = DateTimeHelper.SetYear(this.DisplayDate, d.Year);
- newMode = CalendarMode.Year;
- break;
- }
+ {
+ newDate = DateTimeHelper.SetYear(this.DisplayDate, d.Year);
+ newMode = CalendarMode.Year;
+ break;
+ }
default:
Debug.Assert(false);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs
index 3916267624a..3672e8b2cd4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellInfo.cs
@@ -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.
@@ -122,7 +122,7 @@ internal static DataGridCellInfo CreatePossiblyPartialCellInfo(object item, Data
}
else
{
- return new DataGridCellInfo(owner, column, (item == null) ? DependencyProperty.UnsetValue : item);
+ return new DataGridCellInfo(owner, column, item ?? DependencyProperty.UnsetValue);
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
index 917ac40068d..38ff2412e9e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs
@@ -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.
@@ -154,9 +154,8 @@ public DataGridLength(double value, DataGridLengthUnitType type, double desiredV
/// and unit type as oCompare.
public override bool Equals(object obj)
{
- if (obj is DataGridLength)
+ if (obj is DataGridLength l)
{
- DataGridLength l = (DataGridLength)obj;
return this == l;
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs
index 9849eb680ef..a865b65c784 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridRow.cs
@@ -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.
@@ -713,9 +713,8 @@ private static object OnCoerceDetailsVisibility(DependencyObject d, object baseV
row.DataGridOwner,
DataGrid.RowDetailsVisibilityModeProperty);
- if (visibility is DataGridRowDetailsVisibilityMode)
+ if (visibility is DataGridRowDetailsVisibilityMode visibilityMode)
{
- var visibilityMode = (DataGridRowDetailsVisibilityMode)visibility;
var hasDetailsTemplate = row.DetailsTemplate != null || row.DetailsTemplateSelector != null;
var isRealItem = row.Item != CollectionView.NewItemPlaceholder;
switch (visibilityMode)
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
index 5d88bd25b9a..478bb9988ea 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs
@@ -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.
@@ -2327,9 +2327,8 @@ private static bool DoubleValue_Validate(object value)
bool ok;
// Ensure value is double
- if (value is double)
+ if (value is double checkValue)
{
- double checkValue = (double)value;
// Check if double is within an assumed range
if ((double.IsNaN(checkValue)) ||
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
index f3c5616696d..ecc5835a7eb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentReader.cs
@@ -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.
@@ -1264,9 +1264,8 @@ private bool ConvertToViewingMode(object value, out FlowDocumentReaderViewingMod
mode = (FlowDocumentReaderViewingMode)value;
success = true;
}
- else if (value is String)
+ else if (value is String str)
{
- String str = (String)value;
if (str == FlowDocumentReaderViewingMode.Page.ToString())
{
mode = FlowDocumentReaderViewingMode.Page;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs
index 11b42ce5790..c0ce686bdfd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PasswordBox.cs
@@ -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.
@@ -944,9 +944,8 @@ private void SetRenderScopeToContentHost(TextBoxView renderScope)
// Add renderScope as a child of ContentHostTemplateName
_renderScope = renderScope;
- if (_passwordBoxContentHost is ScrollViewer)
+ if (_passwordBoxContentHost is ScrollViewer scrollViewer)
{
- ScrollViewer scrollViewer = (ScrollViewer)_passwordBoxContentHost;
if (scrollViewer.Content != null)
{
throw new NotSupportedException(SR.TextBoxScrollViewerMarkedAsTextBoxContentMustHaveNoContent);
@@ -956,9 +955,8 @@ private void SetRenderScopeToContentHost(TextBoxView renderScope)
scrollViewer.Content = _renderScope;
}
}
- else if (_passwordBoxContentHost is Decorator)
+ else if (_passwordBoxContentHost is Decorator decorator)
{
- Decorator decorator = (Decorator)_passwordBoxContentHost;
if (decorator.Child != null)
{
throw new NotSupportedException(SR.TextBoxDecoratorMarkedAsTextBoxContentMustHaveNoContent);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs
index 3db9c371da1..05681d4109d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CalendarItem.cs
@@ -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.
@@ -1161,9 +1161,8 @@ private void AddMonthModeHighlight()
for (int childIndex = COLS; childIndex < count; childIndex++)
{
CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton;
- if (childButton.DataContext is DateTime)
+ if (childButton.DataContext is DateTime date)
{
- DateTime date = (DateTime)childButton.DataContext;
childButton.SetValue(
CalendarDayButton.IsHighlightedPropertyKey,
(daysToHighlight != 0) && DateTimeHelper.InRange(date, hStart, hEnd));
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CustomPopupPlacement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CustomPopupPlacement.cs
index ad1f34ff6f0..399aafac6a1 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CustomPopupPlacement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/CustomPopupPlacement.cs
@@ -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.
@@ -81,9 +81,8 @@ public PopupPrimaryAxis PrimaryAxis
/// True if equivalent. False otherwise.
public override bool Equals(object o)
{
- if (o is CustomPopupPlacement)
+ if (o is CustomPopupPlacement placement)
{
- CustomPopupPlacement placement = (CustomPopupPlacement)o;
return (placement._primaryAxis == _primaryAxis) && (placement._point == _point);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs
index d1a52a0d127..d95c6e90848 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentPageView.cs
@@ -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.
@@ -103,7 +103,7 @@ public DocumentPaginator DocumentPaginator
///
public DocumentPage DocumentPage
{
- get { return (_documentPage == null) ? DocumentPage.Missing : _documentPage; }
+ get { return _documentPage ?? DocumentPage.Missing; }
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs
index 92b1d0a1f8b..db8160a70fe 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs
@@ -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.
@@ -1162,9 +1162,8 @@ private void HandleRequestBringIntoView(RequestBringIntoViewEventArgs args)
if (child != null)
{
// Special case UIElements already connected to visual tree.
- if (args.TargetObject is UIElement)
+ if (args.TargetObject is UIElement targetObject)
{
- UIElement targetObject = (UIElement)args.TargetObject;
if (VisualTreeHelper.IsAncestorOf(this, targetObject))
{
targetRect = args.TargetRect;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/GridViewRowPresenterBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/GridViewRowPresenterBase.cs
index 788dcd62ddc..f7e6e1c7d50 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/GridViewRowPresenterBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/GridViewRowPresenterBase.cs
@@ -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.
@@ -304,7 +304,7 @@ private FrameworkElement GetStableAncester()
{
ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(TemplatedParent);
- return (ic != null) ? ic : (FrameworkElement)this;
+ return ic ?? (FrameworkElement)this;
}
// if and only if both conditions below are satisfied, row presenter visual is ready.
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationConstraints.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationConstraints.cs
index 25bf9dbe67a..27a38622c11 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationConstraints.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationConstraints.cs
@@ -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.
@@ -101,9 +101,8 @@ public Rect Viewport
/// and Viewport as oCompare.
override public bool Equals(object oCompare)
{
- if (oCompare is HierarchicalVirtualizationConstraints)
+ if (oCompare is HierarchicalVirtualizationConstraints constraints)
{
- HierarchicalVirtualizationConstraints constraints = (HierarchicalVirtualizationConstraints)oCompare;
return (this == constraints);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationHeaderDesiredSizes.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationHeaderDesiredSizes.cs
index 9c23c82f40f..0c01d75e0af 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationHeaderDesiredSizes.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationHeaderDesiredSizes.cs
@@ -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.
@@ -84,9 +84,8 @@ public Size PixelSize
/// and pixel sizes as oCompare.
override public bool Equals(object oCompare)
{
- if (oCompare is HierarchicalVirtualizationHeaderDesiredSizes)
+ if (oCompare is HierarchicalVirtualizationHeaderDesiredSizes headerDesiredSizes)
{
- HierarchicalVirtualizationHeaderDesiredSizes headerDesiredSizes = (HierarchicalVirtualizationHeaderDesiredSizes)oCompare;
return (this == headerDesiredSizes);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationItemDesiredSizes.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationItemDesiredSizes.cs
index d0f3d1a5054..ebeed7fe47a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationItemDesiredSizes.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/HierarchicalVirtualizationItemDesiredSizes.cs
@@ -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.
@@ -175,9 +175,8 @@ public Size PixelSizeAfterViewport
/// and pixel sizes as oCompare.
override public bool Equals(object oCompare)
{
- if (oCompare is HierarchicalVirtualizationItemDesiredSizes)
+ if (oCompare is HierarchicalVirtualizationItemDesiredSizes itemDesiredSizes)
{
- HierarchicalVirtualizationItemDesiredSizes itemDesiredSizes = (HierarchicalVirtualizationItemDesiredSizes)oCompare;
return (this == itemDesiredSizes);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/IItemContainerGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/IItemContainerGenerator.cs
index 4380e80ccb9..0180ca5e7a1 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/IItemContainerGenerator.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/IItemContainerGenerator.cs
@@ -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.
@@ -158,10 +158,9 @@ public override string ToString()
// This is required by FxCop.
public override bool Equals(object o)
{
- if (o is GeneratorPosition)
+ if (o is GeneratorPosition that)
{
- GeneratorPosition that = (GeneratorPosition)o;
- return this._index == that._index &&
+ return this._index == that._index &&
this._offset == that._offset;
}
return false;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs
index 088f1ef8599..0ffd61dd279 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs
@@ -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.
@@ -1971,10 +1971,8 @@ private void SetRenderScopeToContentHost()
// Add renderScope as a child of ContentHostTemplateName
_renderScope = renderScope;
- if (_textBoxContentHost is ScrollViewer)
+ if (_textBoxContentHost is ScrollViewer scrollViewer)
{
- ScrollViewer scrollViewer = (ScrollViewer)_textBoxContentHost;
-
if (scrollViewer.Content != null)
{
_renderScope = null;
@@ -1987,9 +1985,8 @@ private void SetRenderScopeToContentHost()
scrollViewer.Content = _renderScope; // this may replace old render scope in case of upgrade scenario in TextBox
}
}
- else if (_textBoxContentHost is Decorator)
+ else if (_textBoxContentHost is Decorator decorator)
{
- Decorator decorator = (Decorator)_textBoxContentHost;
if (decorator.Child != null)
{
_renderScope = null;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SelectedCellsChangedEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SelectedCellsChangedEventArgs.cs
index 037018464a7..7a7a8176e19 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SelectedCellsChangedEventArgs.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SelectedCellsChangedEventArgs.cs
@@ -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.
@@ -42,8 +42,8 @@ public SelectedCellsChangedEventArgs(ReadOnlyCollection addedC
internal SelectedCellsChangedEventArgs(DataGrid owner, VirtualizedCellInfoCollection addedCells, VirtualizedCellInfoCollection removedCells)
{
- _addedCells = (addedCells != null) ? addedCells : VirtualizedCellInfoCollection.MakeEmptyCollection(owner);
- _removedCells = (removedCells != null) ? removedCells : VirtualizedCellInfoCollection.MakeEmptyCollection(owner);
+ _addedCells = addedCells ?? VirtualizedCellInfoCollection.MakeEmptyCollection(owner);
+ _removedCells = removedCells ?? VirtualizedCellInfoCollection.MakeEmptyCollection(owner);
Debug.Assert(_addedCells.IsReadOnly, "_addedCells should have ended up as read-only.");
Debug.Assert(_removedCells.IsReadOnly, "_removedCells should have ended up as read-only.");
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs
index 048f9060cc7..248f183287d 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs
@@ -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.
@@ -1717,7 +1717,7 @@ protected virtual IInputElement InputHitTestCore(Point point)
}
// If nothing has been hit, assume that element itself has been hit.
- return (ie != null) ? ie : this;
+ return ie ?? this;
}
///
@@ -4090,7 +4090,7 @@ private static void OnTextChanged(DependencyObject d, string newText)
if (text._complexContent == null)
{
- text._contentCache = (newText != null) ? newText : String.Empty;
+ text._contentCache = newText ?? string.Empty;
}
else
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ValidationResult.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ValidationResult.cs
index 0b60fa54fdd..22e09990f82 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ValidationResult.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ValidationResult.cs
@@ -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.
@@ -114,7 +114,7 @@ public override bool Equals(object obj)
/// hash code for the current ValidationResult
public override int GetHashCode()
{
- return IsValid.GetHashCode() ^ ((ErrorContent == null) ? int.MinValue : ErrorContent).GetHashCode();
+ return IsValid.GetHashCode() ^ (ErrorContent ?? int.MinValue).GetHashCode();
}
private bool _isValid;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs
index 668192b9fa0..bc1a1cbca97 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs
@@ -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.
@@ -122,9 +122,8 @@ public VirtualizationCacheLength(double cacheBeforeViewport, double cacheAfterVi
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
- if (oCompare is VirtualizationCacheLength)
+ if (oCompare is VirtualizationCacheLength l)
{
- VirtualizationCacheLength l = (VirtualizationCacheLength)oCompare;
return (this == l);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
index 29982e81768..426f6c2f2f3 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs
@@ -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.
@@ -69,9 +69,8 @@ public CornerRadius(double topLeft, double topRight, double bottomRight, double
/// True if object is a CornerRadius and all sides of it are equal to this CornerRadius'.
public override bool Equals(object obj)
{
- if (obj is CornerRadius)
+ if (obj is CornerRadius otherObj)
{
- CornerRadius otherObj = (CornerRadius)obj;
return (this == otherObj);
}
return (false);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ObjectDataProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ObjectDataProvider.cs
index 9d360cc18e8..2fe9f453bbd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ObjectDataProvider.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ObjectDataProvider.cs
@@ -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.
@@ -142,7 +142,7 @@ public object ObjectInstance
{
get
{
- return (_instanceProvider != null) ? _instanceProvider : _objectInstance;
+ return _instanceProvider ?? _objectInstance;
}
set
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs
index 9f19e0bac2e..18874f75038 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlDataProvider.cs
@@ -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.
@@ -352,7 +352,7 @@ private void LoadFromSource()
Uri sourceUri = this.Source;
if (sourceUri.IsAbsoluteUri == false)
{
- Uri baseUri = (_baseUri != null) ? _baseUri : BindUriHelper.BaseUri;
+ Uri baseUri = _baseUri ?? BindUriHelper.BaseUri;
sourceUri = BindUriHelper.GetResolvedUri(baseUri, sourceUri);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DependencyPropertyHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DependencyPropertyHelper.cs
index 09e3c32d956..748e69a5e53 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DependencyPropertyHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DependencyPropertyHelper.cs
@@ -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.
@@ -118,11 +118,9 @@ public override int GetHashCode()
///
public override bool Equals(object o)
{
- if (o is ValueSource)
+ if (o is ValueSource that)
{
- ValueSource that = (ValueSource)o;
-
- return this._baseValueSource == that._baseValueSource &&
+ return this._baseValueSource == that._baseValueSource &&
this._isExpression == that._isExpression &&
this._isAnimated == that._isAnimated &&
this._isCoerced == that._isCoerced;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs
index 02da4c4d52c..359241d158f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs
@@ -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.
@@ -65,7 +65,7 @@ public DocumentReference() : base()
/// The document tree
public FixedDocument GetDocument(bool forceReload)
{
- DocumentsTrace.FixedDocumentSequence.IDF.Trace($"DocumentReference.GetDocument ({(Source == null ? new Uri("", UriKind.RelativeOrAbsolute) : Source)}, {forceReload})");
+ DocumentsTrace.FixedDocumentSequence.IDF.Trace($"DocumentReference.GetDocument ({(Source ?? new Uri("", UriKind.RelativeOrAbsolute))}, {forceReload})");
VerifyAccess();
FixedDocument idp = null;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs
index e0351f639da..b04c7a4ce7a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs
@@ -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.
@@ -320,11 +320,10 @@ internal int GetPageNumber(ContentPosition contentPosition)
// Because of that we are expecting one of 2 types here.
DynamicDocumentPaginator childPaginator = null;
ContentPosition childContentPosition = null;
- if (contentPosition is DocumentSequenceTextPointer)
+ if (contentPosition is DocumentSequenceTextPointer dsTextPointer)
{
- DocumentSequenceTextPointer dsTextPointer = (DocumentSequenceTextPointer)contentPosition;
- #pragma warning suppress 6506 // dsTextPointer is obviously not null
+#pragma warning suppress 6506 // dsTextPointer is obviously not null
childPaginator = GetPaginator(dsTextPointer.ChildBlock.DocRef);
childContentPosition = dsTextPointer.ChildPointer as ContentPosition;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs
index 695ad26237f..0f8579fe74c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs
@@ -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.
@@ -498,7 +498,7 @@ internal ContentPosition GetObjectPosition(Object o)
fixedTextPointer = new FixedTextPointer(true, LogicalDirection.Forward, flowPosition);
}
- return (fixedTextPointer != null) ? fixedTextPointer : ContentPosition.Missing;
+ return fixedTextPointer ?? ContentPosition.Missing;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs
index 2fff300666f..ad37cefacbf 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextBuilder.cs
@@ -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.
@@ -1507,9 +1507,8 @@ public void AddElement(FixedSOMElement element)
_fixedNodes.Add(element.FixedNode);
}
}
- else if (element is FixedSOMImage)
+ else if (element is FixedSOMImage image)
{
- FixedSOMImage image = (FixedSOMImage)element;
_FinishTextRun(true);
_SetHyperlink(navUri, image.FixedNode, shadowHyperlink);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs
index a1f169470fb..241076b1020 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs
@@ -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.
@@ -92,15 +92,13 @@ internal override ITextPointer GetTextPositionFromPoint(Point point, bool snapTo
{
pos = _CreateTextPointerFromGlyphs(g, point);
}
- else if (e is Image)
+ else if (e is Image im)
{
- Image im = (Image)e;
FixedPosition fixedp = new FixedPosition(this.FixedPage.CreateFixedNode(this.PageIndex, im), 0);
pos = _CreateTextPointer(fixedp, LogicalDirection.Forward);
}
- else if (e is Path)
+ else if (e is Path p)
{
- Path p = (Path)e;
if (p.Fill is ImageBrush)
{
FixedPosition fixedp = new FixedPosition(this.FixedPage.CreateFixedNode(this.PageIndex, p), 0);
@@ -196,17 +194,15 @@ internal override Rect GetRawRectangleFromTextPosition(ITextPointer position, ou
}
DependencyObject element = this.FixedPage.GetElement(fixedp.Node);
- if (element is Glyphs)
+ if (element is Glyphs g)
{
- Glyphs g = (Glyphs)element;
designRect = _GetGlyphRunDesignRect(g, fixedp.Offset, fixedp.Offset);
// need to do transform
GeneralTransform tran = g.TransformToAncestor(this.FixedPage);
designRect = _GetTransformedCaretRect(tran, designRect.TopLeft, designRect.Height);
}
- else if (element is Image)
+ else if (element is Image image)
{
- Image image = (Image)element;
GeneralTransform tran = image.TransformToAncestor(this.FixedPage);
Point offset = new Point(0, 0);
if (fixedp.Offset > 0)
@@ -215,9 +211,8 @@ internal override Rect GetRawRectangleFromTextPosition(ITextPointer position, ou
}
designRect = _GetTransformedCaretRect(tran, offset, image.ActualHeight);
}
- else if (element is Path)
+ else if (element is Path path)
{
- Path path = (Path)element;
GeneralTransform tran = path.TransformToAncestor(this.FixedPage);
Rect bounds = path.Data.Bounds;
Point offset = bounds.TopLeft;
@@ -440,9 +435,8 @@ internal override bool IsAtCaretUnitBoundary(ITextPointer position)
if (_GetFixedPosition(ftp, out fixedp))
{
DependencyObject element = this.FixedPage.GetElement(fixedp.Node);
- if (element is Glyphs)
+ if (element is Glyphs g)
{
- Glyphs g = (Glyphs)element;
int characterCount = (g.UnicodeString == null ? 0 : g.UnicodeString.Length);
if (fixedp.Offset == characterCount)
{ //end of line -- allow caret
@@ -511,9 +505,8 @@ internal override ITextPointer GetNextCaretUnitPosition(ITextPointer position, L
if (_GetFixedPosition(ftp, out fixedp))
{
DependencyObject element = this.FixedPage.GetElement(fixedp.Node);
- if (element is Glyphs)
+ if (element is Glyphs g)
{
- Glyphs g = (Glyphs)element;
GlyphRun run = g.ToGlyphRun();
int characterCount = (run.Characters == null) ? 0 : run.Characters.Count;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs
index 5824acd693b..afcd3c81680 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs
@@ -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.
@@ -927,7 +927,7 @@ internal ContentPosition GetObjectPosition(Object element)
textPointer = null;
}
flowContentPosition = textPointer as TextPointer;
- return (flowContentPosition != null) ? flowContentPosition : ContentPosition.Missing;
+ return flowContentPosition ?? ContentPosition.Missing;
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineCollection.cs
index 23f2e569603..3edc451f1ff 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineCollection.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineCollection.cs
@@ -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.
@@ -189,9 +189,8 @@ private int AddText(string text, bool returnIndex)
ArgumentNullException.ThrowIfNull(text);
// Special case for TextBlock - to keep its simple content in simple state
- if (this.Parent is TextBlock)
+ if (this.Parent is TextBlock textBlock)
{
- TextBlock textBlock = (TextBlock)this.Parent;
if (!textBlock.HasComplexContent)
{
textBlock.Text = textBlock.Text + text;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs
index 7061dcf86fd..5746c2e8410 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs
@@ -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.
@@ -69,7 +69,7 @@ public PageContent() : base()
public FixedPage GetPageRoot(bool forceReload)
{
#if DEBUG
- DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRoot Source={(Source == null ? new Uri("", UriKind.RelativeOrAbsolute) : Source)}");
+ DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRoot Source={(Source ?? new Uri("", UriKind.RelativeOrAbsolute))}");
#endif
// VerifyAccess();
@@ -101,7 +101,7 @@ public FixedPage GetPageRoot(bool forceReload)
public void GetPageRootAsync(bool forceReload)
{
#if DEBUG
- DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRootAsync Source={(Source == null ? new Uri("", UriKind.RelativeOrAbsolute) : Source)}");
+ DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRootAsync Source={(Source ?? new Uri("", UriKind.RelativeOrAbsolute))}");
#endif
// VerifyAccess();
@@ -141,7 +141,7 @@ public void GetPageRootAsync(bool forceReload)
public void GetPageRootAsyncCancel()
{
#if DEBUG
- DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRootAsyncCancel Source={(Source == null ? new Uri("", UriKind.RelativeOrAbsolute) : Source)}");
+ DocumentsTrace.FixedFormat.PageContent.Trace($"PageContent.GetPageRootAsyncCancel Source={(Source ?? new Uri("", UriKind.RelativeOrAbsolute))}");
#endif
// VerifyAccess();
// Important: do not throw if no outstanding GetPageRootAsyncCall
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSelection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSelection.cs
index 638c13d3a0e..9827a9897d7 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSelection.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditorSelection.cs
@@ -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.
@@ -311,7 +311,7 @@ private static void OnMoveDownByLine(object sender, ExecutedRoutedEventArgs args
ITextPointer lineEndPosition = GetPositionAtLineEnd(originalMovingPosition);
ITextPointer nextPosition = lineEndPosition.GetNextInsertionPosition(LogicalDirection.Forward);
- This.Selection.SetCaretToPosition(nextPosition != null ? nextPosition : lineEndPosition,
+ This.Selection.SetCaretToPosition(nextPosition ?? lineEndPosition,
originalMovingPosition.LogicalDirection, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/true);
}
else if (IsPaginated(This.TextView))
@@ -401,7 +401,7 @@ private static void OnMoveUpByLine(object sender, ExecutedRoutedEventArgs args)
ITextPointer lineStartPosition = GetPositionAtLineStart(originalMovingPosition);
ITextPointer previousPosition = lineStartPosition.GetNextInsertionPosition(LogicalDirection.Backward);
- This.Selection.SetCaretToPosition(previousPosition != null ? previousPosition : lineStartPosition,
+ This.Selection.SetCaretToPosition(previousPosition ?? lineStartPosition,
originalMovingPosition.LogicalDirection, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/true);
}
else if (IsPaginated(This.TextView))
@@ -1070,7 +1070,7 @@ private static void OnSelectDownByLine(object sender, ExecutedRoutedEventArgs ar
ITextPointer nextPosition = lineEndPosition.GetNextInsertionPosition(LogicalDirection.Forward);
// Extend selection and bring new position into view if needed (for paginated viewers)
- ExtendSelectionAndBringIntoView(nextPosition != null ? nextPosition : lineEndPosition, This);
+ ExtendSelectionAndBringIntoView(nextPosition ?? lineEndPosition, This);
}
else if (IsPaginated(This.TextView))
{
@@ -1260,7 +1260,7 @@ private static void OnSelectUpByLine(object sender, ExecutedRoutedEventArgs args
ITextPointer previousPosition = lineStartPosition.GetNextInsertionPosition(LogicalDirection.Backward);
// Extend selection and bring new position into view if needed (for paginated viewers)
- ExtendSelectionAndBringIntoView(previousPosition != null ? previousPosition : lineStartPosition, This);
+ ExtendSelectionAndBringIntoView(previousPosition ?? lineStartPosition, This);
}
else if (IsPaginated(This.TextView))
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeBase.cs
index 6bb2b812d96..bfedbbdf19f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeBase.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeBase.cs
@@ -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.
@@ -1345,7 +1345,7 @@ internal static void SetText(ITextRange thisRange, string textData)
// which can create paragraphs etc.
if (textData.Length > 0)
{
- ITextPointer insertPosition = (explicitInsertPosition == null) ? thisRange.Start : explicitInsertPosition;
+ ITextPointer insertPosition = explicitInsertPosition ?? thisRange.Start;
// Ensure last paragraph existence and prepare ends for the new selection
bool pastedFragmentEndsWithNewLine = textData.EndsWith("\n", StringComparison.Ordinal);
@@ -1739,9 +1739,8 @@ private static void CreateNormalizedTextSegment(ITextRange thisRange, ITextPoint
else
{
// Handle Floater/Figure boundaries: non-empty ranges never cross them
- if (start is TextPointer)
+ if (start is TextPointer adjustedStart)
{
- TextPointer adjustedStart = (TextPointer)start;
TextPointer adjustedEnd = (TextPointer)end;
NormalizeAnchoredBlockBoundaries(ref adjustedStart, ref adjustedEnd);
start = adjustedStart;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs
index 13c36c23cc2..6cf37435da2 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSchema.cs
@@ -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.
@@ -591,28 +591,24 @@ internal static bool ValuesAreEqual(object value1, object value2)
// Comparing null with empty collections
if (value1 == null)
{
- if (value2 is TextDecorationCollection)
+ if (value2 is TextDecorationCollection decorations2)
{
- TextDecorationCollection decorations2 = (TextDecorationCollection)value2;
return decorations2.Count == 0;
}
- else if (value2 is TextEffectCollection)
+ else if (value2 is TextEffectCollection effects2)
{
- TextEffectCollection effects2 = (TextEffectCollection)value2;
return effects2.Count == 0;
}
return false;
}
else if (value2 == null)
{
- if (value1 is TextDecorationCollection)
+ if (value1 is TextDecorationCollection decorations1)
{
- TextDecorationCollection decorations1 = (TextDecorationCollection)value1;
return decorations1.Count == 0;
}
- else if (value1 is TextEffectCollection)
+ else if (value1 is TextEffectCollection effects1)
{
- TextEffectCollection effects1 = (TextEffectCollection)value1;
return effects1.Count == 0;
}
return false;
@@ -632,9 +628,8 @@ internal static bool ValuesAreEqual(object value1, object value2)
TextDecorationCollection decorations2 = (TextDecorationCollection)value2;
return decorations1.ValueEquals(decorations2);
}
- else if (value1 is FontFamily)
+ else if (value1 is FontFamily fontFamily1)
{
- FontFamily fontFamily1 = (FontFamily)value1;
FontFamily fontFamily2 = (FontFamily)value2;
return fontFamily1.Equals(fontFamily2);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
index 07a21fc4e79..ab3c3486f8b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ZoomPercentageConverter.cs
@@ -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.
@@ -145,64 +145,62 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
isValidArg = true;
}
// If value is a string, then parse
- else if (value is string)
- {
- try
+ else if (value is string zoomString) // Remove whitespace on either end of the string.
{
- // Remove whitespace on either end of the string.
- string zoomString = (string)value;
- if ((culture != null) && !String.IsNullOrEmpty(zoomString))
+ try
{
- zoomString = ((string)value).Trim();
-
- // If this is not a neutral culture attempt to remove the percent symbol.
- if ((!culture.IsNeutralCulture) && (zoomString.Length > 0) && (culture.NumberFormat != null))
+ if ((culture != null) && !String.IsNullOrEmpty(zoomString))
{
- // This will strip the percent sign (if it exists) depending on the culture information.
- switch (culture.NumberFormat.PercentPositivePattern)
+ zoomString = ((string)value).Trim();
+
+ // If this is not a neutral culture attempt to remove the percent symbol.
+ if ((!culture.IsNeutralCulture) && (zoomString.Length > 0) && (culture.NumberFormat != null))
{
- case 0: // n %
- case 1: // n%
- // Remove the last character if it is a percent sign
- if (zoomString.Length - 1 == zoomString.LastIndexOf(
- culture.NumberFormat.PercentSymbol,
- StringComparison.CurrentCultureIgnoreCase))
- {
- zoomString = zoomString.Substring(0, zoomString.Length - 1);
- }
- break;
- case 2: // %n
- // Remove the first character if it is a percent sign.
- if (0 == zoomString.IndexOf(
- culture.NumberFormat.PercentSymbol,
- StringComparison.CurrentCultureIgnoreCase))
- {
- zoomString = zoomString.Substring(1);
- }
- break;
+ // This will strip the percent sign (if it exists) depending on the culture information.
+ switch (culture.NumberFormat.PercentPositivePattern)
+ {
+ case 0: // n %
+ case 1: // n%
+ // Remove the last character if it is a percent sign
+ if (zoomString.Length - 1 == zoomString.LastIndexOf(
+ culture.NumberFormat.PercentSymbol,
+ StringComparison.CurrentCultureIgnoreCase))
+ {
+ zoomString = zoomString.Substring(0, zoomString.Length - 1);
+ }
+ break;
+ case 2: // %n
+ // Remove the first character if it is a percent sign.
+ if (0 == zoomString.IndexOf(
+ culture.NumberFormat.PercentSymbol,
+ StringComparison.CurrentCultureIgnoreCase))
+ {
+ zoomString = zoomString.Substring(1);
+ }
+ break;
+ }
}
- }
- // If this conversion throws then the string wasn't a valid zoom value.
- zoomValue = System.Convert.ToDouble(zoomString, culture);
- isValidArg = true;
+ // If this conversion throws then the string wasn't a valid zoom value.
+ zoomValue = System.Convert.ToDouble(zoomString, culture);
+ isValidArg = true;
+ }
}
- }
-// Allow empty catch statements.
+ // Allow empty catch statements.
#pragma warning disable 56502
- // Catch only the expected parse exceptions
- catch (ArgumentOutOfRangeException) { }
- catch (ArgumentNullException) { }
- catch (FormatException) { }
- catch (OverflowException) { }
+ // Catch only the expected parse exceptions
+ catch (ArgumentOutOfRangeException) { }
+ catch (ArgumentNullException) { }
+ catch (FormatException) { }
+ catch (OverflowException) { }
-// Disallow empty catch statements.
+ // Disallow empty catch statements.
#pragma warning restore 56502
- }
+ }
- // Argument wasn't a valid percent, set error value.
- if (!isValidArg)
+ // Argument wasn't a valid percent, set error value.
+ if (!isValidArg)
{
return DependencyProperty.UnsetValue;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs
index 498c6ade451..30cbab0ff65 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs
@@ -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.
@@ -182,9 +182,8 @@ public FigureLength(double value, FigureUnitType type)
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
- if(oCompare is FigureLength)
+ if (oCompare is FigureLength l)
{
- FigureLength l = (FigureLength)oCompare;
return (this == l);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
index 4298c27703b..2fc3b21bb2e 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
@@ -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.
@@ -1767,7 +1767,7 @@ internal static INameScope FindScope(DependencyObject d, out DependencyObject sc
DependencyObject parent = LogicalTreeHelper.GetParent(d);
- d = (parent != null) ? parent : Helper.FindMentor(d.InheritanceContext);
+ d = parent ?? Helper.FindMentor(d.InheritanceContext);
}
scopeOwner = null;
@@ -2501,7 +2501,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen
if (Parent == null)
{
// Invalidate relevant properties for this subtree
- DependencyObject parent = (newParent != null) ? newParent : oldParent;
+ DependencyObject parent = newParent ?? oldParent;
TreeWalkHelper.InvalidateOnTreeChange(this, null, parent, (newParent != null));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
index 16ba3ee0c26..141aa7f356b 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs
@@ -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.
@@ -336,7 +336,7 @@ internal void ChangeLogicalParent(DependencyObject newParent)
///////////////////
// Invalidate relevant properties for this subtree
- DependencyObject parent = (newParent != null) ? newParent : oldParent;
+ DependencyObject parent = newParent ?? oldParent;
TreeWalkHelper.InvalidateOnTreeChange(/* fe = */ null, /* fce = */ this, parent, (newParent != null));
// If no one has called BeginInit then mark the element initialized and fire Initialized event
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
index 3b682b33bf8..878a7fa8dab 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs
@@ -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.
@@ -333,7 +333,7 @@ internal void ChangeLogicalParent(DependencyObject newParent)
///////////////////
// Invalidate relevant properties for this subtree
- DependencyObject parent = (newParent != null) ? newParent : oldParent;
+ DependencyObject parent = newParent ?? oldParent;
TreeWalkHelper.InvalidateOnTreeChange(/* fe = */ this, /* fce = */ null, parent, (newParent != null));
// If no one has called BeginInit then mark the element initialized and fire Initialized event
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs
index d542d988a43..895b4340d1f 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs
@@ -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.
@@ -151,9 +151,8 @@ public GridLength(double value, GridUnitType type)
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
- if(oCompare is GridLength)
+ if (oCompare is GridLength l)
{
- GridLength l = (GridLength)oCompare;
return (this == l);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs
index 01898f6d6c8..e17d40d3eb4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs
@@ -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.
@@ -1072,7 +1072,7 @@ private bool Navigate(DependencyObject currentElement, TraversalRequest request,
if (!traversed && firstElement != nextTab)
{
// Navigate to next element in the tree
- traversed = Navigate(nextTab, request, modifierKeys, firstElement == null ? nextTab : firstElement);
+ traversed = Navigate(nextTab, request, modifierKeys, firstElement ?? nextTab);
}
return traversed;
@@ -3093,7 +3093,7 @@ private DependencyObject FindElementAtViewportEdge(
}
}
}
- return result != null ? result : partialResult;
+ return result ?? partialResult;
}
///
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs
index 18316c87680..3bf284cbfc9 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs
@@ -1123,14 +1123,13 @@ internal void LoadAssemblyInfoRecord(BamlAssemblyInfoRecord record)
internal void EnsureAssemblyRecord(Assembly asm)
{
string fullName = asm.FullName;
- BamlAssemblyInfoRecord record = ObjectHashTable[fullName] as BamlAssemblyInfoRecord;
// If we don't have an assembly record for this assembly yet it is most likely
// because it is an assembly that is part of the default namespace and was not defined
// using a mapping PI. In that case, add an assembly record to the object cache and
// populate it with the required data. Note that it DOES NOT have a valid AssemblyId
// and this is not written out the the baml stream.
- if (record == null)
+ if (ObjectHashTable[fullName] is not BamlAssemblyInfoRecord record)
{
record = new BamlAssemblyInfoRecord();
record.AssemblyFullName = fullName;
@@ -1846,10 +1845,8 @@ internal struct AssemblyInfoKey
///
public override bool Equals(object o)
{
- if (o is AssemblyInfoKey)
+ if (o is AssemblyInfoKey key)
{
- AssemblyInfoKey key = (AssemblyInfoKey)o;
-
return ((key.AssemblyFullName != null) ?
key.AssemblyFullName.Equals(this.AssemblyFullName) :
(this.AssemblyFullName == null));
@@ -1908,10 +1905,8 @@ internal struct TypeInfoKey
///
public override bool Equals(object o)
{
- if (o is TypeInfoKey)
+ if (o is TypeInfoKey key)
{
- TypeInfoKey key = (TypeInfoKey)o;
-
return ((key.DeclaringAssembly != null) ?
key.DeclaringAssembly.Equals(this.DeclaringAssembly) :
(this.DeclaringAssembly == null)) &&
@@ -1954,6 +1949,6 @@ public override int GetHashCode()
/// Return string representation of this key
///
public override string ToString() =>
- $"TypeInfoKey: Assembly={((DeclaringAssembly != null) ? DeclaringAssembly : "null")} Type={((TypeFullName != null) ? TypeFullName : "null")}";
+ $"TypeInfoKey: Assembly={(DeclaringAssembly ?? "null")} Type={(TypeFullName ?? "null")}";
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs
index 14a6829033d..8ac27b017bd 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs
@@ -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.
@@ -816,7 +816,7 @@ private void ReadXmlnsPropertyRecord()
info.ClrNamespace = string.Empty;
info.AssemblyName = string.Empty;
info.Prefix = "xmlns";
- info.LocalName = bamlRecord.Prefix == null ? string.Empty : bamlRecord.Prefix;
+ info.LocalName = bamlRecord.Prefix ?? string.Empty;
info.Name = string.IsNullOrEmpty(bamlRecord.Prefix) ?
"xmlns" :
$"xmlns:{bamlRecord.Prefix}";
@@ -1039,7 +1039,7 @@ private BamlPropertyInfo GetPropertyCustomRecordInfo()
{
Type declaringType = null;
_propertyDP = _bamlRecordReader.GetCustomDependencyPropertyValue(bamlRecord, out declaringType);
- declaringType = declaringType == null ? _propertyDP.OwnerType : declaringType;
+ declaringType = declaringType ?? _propertyDP.OwnerType;
info.Value = $"{declaringType.Name}.{_propertyDP.Name}";
string xmlns = _parserContext.XamlTypeMapper.GetXmlNamespace(declaringType.Namespace,
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs
index 1a67f73f0b5..b4fa5c3e629 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs
@@ -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.
@@ -3810,9 +3810,8 @@ internal virtual void SetClrComplexPropertyCore(object parentObject, object valu
// Check if we have a Nullable type. If so and the object being set is
// not a Nullable or an expression, then attempt a conversion.
- if (memberInfo is PropertyInfo)
+ if (memberInfo is PropertyInfo propertyInfo)
{
- PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
value = OptionallyMakeNullable(propertyInfo.PropertyType, value, propertyInfo.Name);
propertyInfo.SetValue(parentObject, value, BindingFlags.Default, null, null
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs
index ecfa9fa3884..c23c676d6cc 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordWriter.cs
@@ -535,8 +535,7 @@ private IBamlDictionaryKey FindBamlDictionaryKey(KeyDeferRecord record)
for (int i = 0; i < record.RecordList.Count; i++)
{
ValueDeferRecord valueDeferRecord = (ValueDeferRecord)record.RecordList[i];
- IBamlDictionaryKey dictionaryKey = valueDeferRecord.Record as IBamlDictionaryKey;
- if (dictionaryKey != null)
+ if (valueDeferRecord.Record is IBamlDictionaryKey dictionaryKey)
{
return dictionaryKey;
}
@@ -567,11 +566,10 @@ internal void WriteDefAttribute(XamlDefAttributeNode xamlDefNode)
// attribute is *NOT* a MarkupExtension. A MarkupExtension would cause
// WriteKeyElementStart being called.
KeyDeferRecord keyRecord = (KeyDeferRecord)(_deferKeys[_deferKeys.Count-1]);
- BamlDefAttributeKeyStringRecord defKeyRecord = keyRecord.Record as BamlDefAttributeKeyStringRecord;
- if (defKeyRecord == null)
+ if (keyRecord.Record is not BamlDefAttributeKeyStringRecord defKeyRecord)
{
defKeyRecord =
- (BamlDefAttributeKeyStringRecord) BamlRecordManager.GetWriteRecord(BamlRecordType.DefAttributeKeyString);
+ (BamlDefAttributeKeyStringRecord)BamlRecordManager.GetWriteRecord(BamlRecordType.DefAttributeKeyString);
TransferOldSharedData(keyRecord.Record as IBamlDictionaryKey, defKeyRecord as IBamlDictionaryKey);
keyRecord.Record = defKeyRecord;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs
index 3fc6a6a7a40..1bd30c0b526 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs
@@ -4710,8 +4710,7 @@ internal void SetPropertyMember (object propertyMember)
else
{
// Cache a additional MemberInfo for the given attribute
- object[] arr = PropertyMember as object[];
- if (arr == null)
+ if (PropertyMember is not object[] arr)
{
arr = new object[3];
arr[0] = PropertyMember;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs
index c798fcf1a2d..b9a588d7db4 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ParserContext.cs
@@ -279,7 +279,7 @@ public string XmlLang
set
{
EndRepeat();
- _xmlLang = (null == value ? String.Empty : value);
+ _xmlLang = (value ?? string.Empty);
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs
index 91caa0b9c94..a0c6306ca51 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs
@@ -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.
@@ -342,7 +342,7 @@ private static void CacheShouldSerializeMethod(ShouldSerializeKey key, MethodInf
{
// The instance stored in _shouldSerializeCacheLock is used as a sentinal for null
// The avoids having to perform two lookups in the Hashtable to detect a cached null value.
- object value = methodInfo == null ? _shouldSerializeCacheLock : methodInfo;
+ object value = methodInfo ?? _shouldSerializeCacheLock;
lock (_shouldSerializeCacheLock)
{
_shouldSerializeCache[key] = value;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs
index eebc5cd516c..206eeeca998 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/TemplateXamlParser.cs
@@ -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.
@@ -745,25 +745,23 @@ public override void WriteElementStart(XamlElementStartNode xamlElementStartNode
if (xamlElementStartNode.SerializerType != null && _styleModeStack.Depth > 0)
{
- XamlSerializer serializer = XamlTypeMapper.CreateInstance(xamlElementStartNode.SerializerType)
- as XamlSerializer;
- if (serializer == null)
- {
- ThrowException(nameof(SR.ParserNoSerializer),
- xamlElementStartNode.TypeFullName,
- xamlElementStartNode.LineNumber,
- xamlElementStartNode.LinePosition);
- }
- else
- {
- // Depending on whether this is the compile case or the parse xaml
- // case, we want to convert the xaml into baml or objects.
-
- #if PBTCOMPILER
- serializer.ConvertXamlToBaml(TokenReader,
- BamlRecordWriter == null ? ParserContext : BamlRecordWriter.ParserContext,
- xamlElementStartNode, BamlRecordWriter);
- #else
+ if (XamlTypeMapper.CreateInstance(xamlElementStartNode.SerializerType) is not XamlSerializer serializer)
+ {
+ ThrowException(nameof(SR.ParserNoSerializer),
+ xamlElementStartNode.TypeFullName,
+ xamlElementStartNode.LineNumber,
+ xamlElementStartNode.LinePosition);
+ }
+ else
+ {
+ // Depending on whether this is the compile case or the parse xaml
+ // case, we want to convert the xaml into baml or objects.
+
+#if PBTCOMPILER
+ serializer.ConvertXamlToBaml(TokenReader,
+ BamlRecordWriter == null ? ParserContext : BamlRecordWriter.ParserContext,
+ xamlElementStartNode, BamlRecordWriter);
+#else
// If we're in the content of the template, we'll convert to baml. Then TemplateBamlRecordReader
// gets the option of instantiating it or keeping it in baml. For example, if this is a nested
@@ -803,9 +801,9 @@ public override void WriteElementStart(XamlElementStartNode xamlElementStartNode
TreeBuilder.RecordReader);
}
- #endif
+#endif
- }
+ }
}
else
@@ -920,6 +918,7 @@ public override void WriteElementEnd(XamlElementEndNode xamlElementEndNode)
}
}
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0029:Use coalesce expression", Justification = "Incorrect resolution by formatter")]
private Type TargetType
{
get
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs
index 936b0487adb..56d92ce9d52 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlParser.cs
@@ -221,9 +221,8 @@ public bool ReadXaml(bool singleRecordMode)
int linePosition = 0;
string newMessage = null;
- if (e is XmlException)
+ if (e is XmlException xmlEx)
{
- XmlException xmlEx = (XmlException)e;
lineNumber = xmlEx.LineNumber;
linePosition = xmlEx.LinePosition;
newMessage = xmlEx.Message;
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs
index 89757eea51b..430dfc8598c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReader.cs
@@ -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.
@@ -498,7 +498,7 @@ internal static void RewrapException(Exception e, IXamlLineInfo lineInfo, Uri ba
internal static XamlParseException WrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
{
- Exception baseException = (e.InnerException == null) ? e : e.InnerException;
+ Exception baseException = e.InnerException ?? e;
if (baseException is System.Windows.Markup.XamlParseException)
{
var xe = ((System.Windows.Markup.XamlParseException)baseException);
@@ -515,9 +515,8 @@ internal static XamlParseException WrapException(Exception e, IXamlLineInfo line
System.Xaml.XamlException xe = (System.Xaml.XamlException)e;
return new XamlParseException(xe.Message, xe.LineNumber, xe.LinePosition, baseUri, baseException);
}
- else if (e is XmlException)
+ else if (e is XmlException xe)
{
- XmlException xe = (XmlException)e;
return new XamlParseException(xe.Message, xe.LineNumber, xe.LinePosition, baseUri, baseException);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs
index 9348fae75f1..74370198541 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs
@@ -1467,8 +1467,7 @@ public Type ContextDataType
{
get
{
- DictionaryContextData dcd = _contextData as DictionaryContextData;
- if (dcd == null)
+ if (_contextData is not DictionaryContextData dcd)
{
return _contextData as Type;
}
@@ -2909,7 +2908,7 @@ out elementScopedAttributeFound
case AttributeContext.Unknown:
WriteUnknownAttribute(attribNamespaceURI, attribLocalName,
attribValue, depth, parentTypeNamespace,
- unknownTagName == null ? parentType.Name : unknownTagName,
+ unknownTagName ?? parentType.Name,
dynamicObject, resolvedProperties);
break;
@@ -3125,8 +3124,7 @@ private void WriteDefAttributes(
ThrowException(nameof(SR.ParserNoDictionaryName));
}
- DictionaryContextData dictionaryData = ParentContext.ContextData as DictionaryContextData;
- if (dictionaryData != null)
+ if (ParentContext.ContextData is DictionaryContextData dictionaryData)
{
object key;
// Note that not all keys can be resolved at compile time. For those that fail,
@@ -3199,9 +3197,8 @@ private void WritePropertyAttribute(
propertyCanWrite = !((DependencyProperty)dynamicObject).ReadOnly;
}
#endif
- else if (dynamicObject is MethodInfo)
+ else if (dynamicObject is MethodInfo methodInfo)
{
- MethodInfo methodInfo = (MethodInfo)dynamicObject;
if (methodInfo.GetParameters().Length == 1)
{
methodInfo = methodInfo.DeclaringType.GetMethod(
@@ -3952,13 +3949,12 @@ private void CompileComplexProperty(
// BamlRecordReader has secondary protection against nested property
// records, but the error message less friendly to users. ("'Property'
// record unexpected in BAML stream.")
- ElementContextStackData parentTag = ElementContextStack.ParentContext as ElementContextStackData;
- if( parentTag != null )
+ if (ElementContextStack.ParentContext is ElementContextStackData parentTag)
{
- if ( parentTag.ContextType == ElementContextType.PropertyComplex ||
+ if (parentTag.ContextType == ElementContextType.PropertyComplex ||
parentTag.ContextType == ElementContextType.PropertyArray ||
parentTag.ContextType == ElementContextType.PropertyIList ||
- parentTag.ContextType == ElementContextType.PropertyIDictionary )
+ parentTag.ContextType == ElementContextType.PropertyIDictionary)
{
ThrowException(nameof(SR.ParserNestedComplexProp), complexPropName);
}
@@ -5263,21 +5259,18 @@ bool Normalization
{
set
{
-
Debug.Assert(null != XmlReader, "XmlReader is not yet set");
//check if it's a XmlCompatibilityReader first
- XmlCompatibilityReader xmlCompatReader = XmlReader as XmlCompatibilityReader;
- if (null != xmlCompatReader)
+ if (XmlReader is XmlCompatibilityReader xmlCompatReader)
{
xmlCompatReader.Normalization = true;
}
else
{
//now check for XmlTextReader
- XmlTextReader xmlTextReader = XmlReader as XmlTextReader;
// review, what if not the XmlTextReader.
- if (null != xmlTextReader)
+ if (XmlReader is XmlTextReader xmlTextReader)
{
xmlTextReader.Normalization = true;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs
index 3b46b06a617..b0f12d35e74 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs
@@ -3891,20 +3891,16 @@ internal void ResetMapper()
_linePosition = 0;
_isProtectedAttributeAllowed = false;
- NamespaceMapEntry[] defaultNsMaps = _namespaceMapHashList[XamlReaderHelper.DefaultNamespaceURI] as NamespaceMapEntry[];
- NamespaceMapEntry[] definitionNsMaps = _namespaceMapHashList[XamlReaderHelper.DefinitionNamespaceURI] as NamespaceMapEntry[];
- NamespaceMapEntry[] definitionMetroNsMaps = _namespaceMapHashList[XamlReaderHelper.DefinitionMetroNamespaceURI] as NamespaceMapEntry[];
-
_namespaceMapHashList.Clear();
- if (null != defaultNsMaps)
+ if (_namespaceMapHashList[XamlReaderHelper.DefaultNamespaceURI] is NamespaceMapEntry[] defaultNsMaps)
{
_namespaceMapHashList.Add(XamlReaderHelper.DefaultNamespaceURI, defaultNsMaps);
}
- if (null != definitionNsMaps)
+ if (_namespaceMapHashList[XamlReaderHelper.DefinitionNamespaceURI] is NamespaceMapEntry[] definitionNsMaps)
{
_namespaceMapHashList.Add(XamlReaderHelper.DefinitionNamespaceURI, definitionNsMaps);
}
- if (null != definitionMetroNsMaps)
+ if (_namespaceMapHashList[XamlReaderHelper.DefinitionMetroNamespaceURI] is NamespaceMapEntry[] definitionMetroNsMaps)
{
_namespaceMapHashList.Add(XamlReaderHelper.DefinitionMetroNamespaceURI, definitionMetroNsMaps);
}
@@ -4012,8 +4008,7 @@ internal void SetPropertyAndType(
"GetPropertyAndType must always be called before SetPropertyAndType");
// add the type taking a lock
- PropertyAndType pAndT = _dpLookupHashtable[dpName] as PropertyAndType;
- if (pAndT == null)
+ if (_dpLookupHashtable[dpName] is not PropertyAndType pAndT)
{
_dpLookupHashtable[dpName] = new PropertyAndType(null, dpInfo, false, true, ownerType, isInternal);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs
index cb686bb766b..53b171b3839 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs
@@ -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.
@@ -255,9 +255,8 @@ IEnumerator IEnumerable.GetEnumerator()
/// The zero-based index in array at which copying begins
public void CopyTo(Array array, int index)
{
- IDictionary dict = GetNamespacesInScope(NamespaceScope.All) as IDictionary;
- if (dict != null)
- dict.CopyTo(array,index);
+ if (GetNamespacesInScope(NamespaceScope.All) is IDictionary dict)
+ dict.CopyTo(array, index);
}
#endregion ICollectionMethods
@@ -387,7 +386,7 @@ public string LookupPrefix(string xmlNamespace)
public string DefaultNamespace()
{
string defaultNs = LookupNamespace(string.Empty);
- return (defaultNs == null) ? string.Empty : defaultNs;
+ return defaultNs ?? string.Empty;
}
#endif
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiTrigger.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiTrigger.cs
index 7fc34b8aa29..eb635e7fb00 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiTrigger.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiTrigger.cs
@@ -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.
@@ -103,7 +103,7 @@ internal override void Seal()
_conditions[i].Property,
LogicalOp.Equals,
_conditions[i].Value,
- (_conditions[i].SourceName != null) ? _conditions[i].SourceName : StyleHelper.SelfName);
+ _conditions[i].SourceName ?? StyleHelper.SelfName);
}
// Set conditions array for all property triggers
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StaticResourceExtension.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StaticResourceExtension.cs
index 0bd351d6ebf..3bb3900230c 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StaticResourceExtension.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StaticResourceExtension.cs
@@ -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.
@@ -253,9 +253,8 @@ private ResourceDictionary FindTheResourceDictionary(IServiceProvider servicePro
return resourceDictionary;
}
}
- if (ambientValue.Value is Style)
+ if (ambientValue.Value is Style style)
{
- var style = (Style)ambientValue.Value;
var resourceDictionary = style.FindResourceDictionary(ResourceKey);
if (resourceDictionary != null)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
index 33eb9da1b09..5eb84ef15a2 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Style.cs
@@ -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.
@@ -782,28 +782,26 @@ private void ProcessVisualTriggers(Style style)
{
StyleHelper.AddPropertyTriggerWithAction( trigger, ((Trigger)trigger).Property, ref this.PropertyTriggersWithActions );
}
- else if( trigger is MultiTrigger )
+ else if (trigger is MultiTrigger multiTrigger)
{
- MultiTrigger multiTrigger = (MultiTrigger)trigger;
- for( int k = 0; k < multiTrigger.Conditions.Count; k++ )
+ for (int k = 0; k < multiTrigger.Conditions.Count; k++)
{
Condition triggerCondition = multiTrigger.Conditions[k];
- StyleHelper.AddPropertyTriggerWithAction( trigger, triggerCondition.Property, ref this.PropertyTriggersWithActions );
+ StyleHelper.AddPropertyTriggerWithAction(trigger, triggerCondition.Property, ref this.PropertyTriggersWithActions);
}
}
- else if( trigger is DataTrigger )
+ else if (trigger is DataTrigger)
{
- StyleHelper.AddDataTriggerWithAction( trigger, ((DataTrigger)trigger).Binding, ref this.DataTriggersWithActions );
+ StyleHelper.AddDataTriggerWithAction(trigger, ((DataTrigger)trigger).Binding, ref this.DataTriggersWithActions);
}
- else if( trigger is MultiDataTrigger )
+ else if (trigger is MultiDataTrigger multiDataTrigger)
{
- MultiDataTrigger multiDataTrigger = (MultiDataTrigger)trigger;
- for( int k = 0; k < multiDataTrigger.Conditions.Count; k++ )
+ for (int k = 0; k < multiDataTrigger.Conditions.Count; k++)
{
Condition dataCondition = multiDataTrigger.Conditions[k];
- StyleHelper.AddDataTriggerWithAction( trigger, dataCondition.Binding, ref this.DataTriggersWithActions );
+ StyleHelper.AddDataTriggerWithAction(trigger, dataCondition.Binding, ref this.DataTriggersWithActions);
}
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
index fb2d6049ba6..7c8945476f8 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs
@@ -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.
@@ -5763,35 +5763,33 @@ internal struct ChildValueLookup
// Trading off an object boxing cost in exchange for avoiding reflection cost.
public override bool Equals( object value )
{
- if( value is ChildValueLookup )
+ if (value is ChildValueLookup other)
{
- ChildValueLookup other = (ChildValueLookup)value;
-
- if( LookupType == other.LookupType &&
- Property == other.Property &&
- Value == other.Value )
+ if (LookupType == other.LookupType &&
+ Property == other.Property &&
+ Value == other.Value)
{
- if( Conditions == null &&
- other.Conditions == null )
+ if (Conditions == null &&
+ other.Conditions == null)
{
// Both condition arrays are null
return true;
}
- if( Conditions == null ||
- other.Conditions == null )
+ if (Conditions == null ||
+ other.Conditions == null)
{
// One condition array is null, but not other
return false;
}
// Both condition array non-null, see if they're the same length..
- if( Conditions.Length == other.Conditions.Length )
+ if (Conditions.Length == other.Conditions.Length)
{
// Same length. Walk the list and compare.
- for( int i = 0; i < Conditions.Length; i++ )
+ for (int i = 0; i < Conditions.Length; i++)
{
- if( !Conditions[i].TypeSpecificEquals(other.Conditions[i]) )
+ if (!Conditions[i].TypeSpecificEquals(other.Conditions[i]))
{
return false;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs
index f68c50c2604..58c94aebd4a 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs
@@ -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.
@@ -70,9 +70,8 @@ public Thickness(double left, double top, double right, double bottom)
/// True if object is a Thickness and all sides of it are equal to this Thickness'.
public override bool Equals(object obj)
{
- if (obj is Thickness)
+ if (obj is Thickness otherObj)
{
- Thickness otherObj = (Thickness)obj;
return (this == otherObj);
}
return (false);
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs
index 06d06a49883..8045347a174 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs
@@ -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.
@@ -13,7 +13,7 @@ namespace System.Windows
/// A single Style property conditional dependency driver
///
[ContentProperty("Setters")]
- [XamlSetTypeConverterAttribute("ReceiveTypeConverter")]
+ [XamlSetTypeConverterAttribute("ReceiveTypeConverter")]
public class Trigger : TriggerBase, IAddChild, ISupportInitialize
{
///
@@ -213,7 +213,7 @@ internal sealed override void Seal()
_property,
LogicalOp.Equals,
_value,
- (_sourceName != null) ? _sourceName : StyleHelper.SelfName) };
+ _sourceName ?? StyleHelper.SelfName) };
// Set Condition for all property triggers
for (int i = 0; i < PropertyValues.Count; i++)
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs
index 8c68ec9750c..472c67f4aab 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/BrushProxy.cs
@@ -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.
@@ -3323,9 +3323,8 @@ public static BrushProxy BlendColorWithBrush(bool opacityOnly, Color colorA, Bru
}
// SolidColorBrush * GradientBrush
- if (brushB.Brush is GradientBrush)
+ if (brushB.Brush is GradientBrush gradientBrush)
{
- GradientBrush gradientBrush = (GradientBrush)brushB.Brush;
return brushB.BlendGradient(colorA, reverse, gradientBrush.ColorInterpolationMode);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/PrimitiveList.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/PrimitiveList.cs
index 315037b9518..0bc13e6f009 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/PrimitiveList.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/PrimitiveList.cs
@@ -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.
@@ -54,13 +54,11 @@ internal static string LeftPad(object obj, int len)
{
s = ((Double)obj).ToString("F1", CultureInfo.InvariantCulture);
}
- else if (obj is Rect)
+ else if (obj is Rect r)
{
- Rect r = (Rect) obj;
-
- return " [" + LeftPad(r.Left, 6) + ' '
- + LeftPad(r.Top, 6) + ' '
- + LeftPad(r.Width, 6) + ' '
+ return " [" + LeftPad(r.Left, 6) + ' '
+ + LeftPad(r.Top, 6) + ' '
+ + LeftPad(r.Width, 6) + ' '
+ LeftPad(r.Height, 6) + "]";
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/MetroSerializationManager.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/MetroSerializationManager.cs
index 5f523e4d201..833fcfd67d4 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/MetroSerializationManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/MetroSerializationManager.cs
@@ -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.
@@ -882,8 +882,8 @@ Object serializableObject
out designerSerializationFlagsAttr) == true)
{
TypeCacheItem typeCacheItem = GetTypeCacheItem(propertyType);
- serializerTypeForProperty = serializerTypeForProperty == null ? typeCacheItem.SerializerType : serializerTypeForProperty;
- typeConverterForProperty = typeConverterForProperty == null ? typeCacheItem.TypeConverter : typeConverterForProperty;
+ serializerTypeForProperty = serializerTypeForProperty ?? typeCacheItem.SerializerType;
+ typeConverterForProperty = typeConverterForProperty ?? typeCacheItem.TypeConverter;
TypeDependencyPropertyCache
dependencyPropertyCache = new TypeDependencyPropertyCache(memberInfo,
diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
index e1bc50432aa..26892112485 100644
--- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
+++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs
@@ -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.
@@ -884,9 +884,8 @@ private void SerializeLinksInLogicalTree(DependencyObject dependencyObject, ICon
private void SerializeLinkTargetForElement(IInputElement element, IContentHost contentHost, Visual root)
{
- if (element is FrameworkElement)
+ if (element is FrameworkElement fe)
{
- FrameworkElement fe = (FrameworkElement)element;
string id = fe.Name;
if (!String.IsNullOrEmpty(id))
{
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs
index 19d33e3c124..07e5a2b8705 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs
@@ -227,7 +227,6 @@ private static bool IsDialogOverrideEnabled
if (key != null)
{
object dbgJITDebugLaunchSettingValue = key.GetValue("DbgJITDebugLaunchSetting");
- string dbgManagedDebuggerValue = key.GetValue("DbgManagedDebugger") as string;
//
// Only count the enable if there's a JIT debugger to launch.
@@ -235,7 +234,7 @@ private static bool IsDialogOverrideEnabled
enabled = (dbgJITDebugLaunchSettingValue is int && ((int)dbgJITDebugLaunchSettingValue & 2) != 0);
if (enabled)
{
- enabled = dbgManagedDebuggerValue != null && dbgManagedDebuggerValue.Length > 0;
+ enabled = key.GetValue("DbgManagedDebugger") is string dbgManagedDebuggerValue && dbgManagedDebuggerValue.Length > 0;
}
}
return enabled;
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
index ee7dc3e4b6f..6d6f1adc951 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
@@ -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.
@@ -68,7 +68,7 @@ internal static string GetAssemblyPartialName(Assembly assembly)
{
AssemblyName name = new AssemblyName(assembly.FullName);
string partialName = name.Name;
- return (partialName != null) ? partialName : string.Empty;
+ return partialName ?? string.Empty;
}
#endif
@@ -201,8 +201,7 @@ static void CleanupCollectedAssemblies(object state) // dummy parameter required
{
foreach (object key in _assemblies.Keys)
{
- WeakReference weakRef = key as WeakReference;
- if (weakRef is null)
+ if (key is not WeakReference weakRef)
{
continue;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/TraceProvider.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/TraceProvider.cs
index 7f9a0d5f7f2..391cf7f0fb4 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/TraceProvider.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/TraceProvider.cs
@@ -269,8 +269,7 @@ to fill the passed in ETW data descriptor.
{
dataDescriptor->Reserved = 0;
- string sRet = data as string;
- if (sRet != null)
+ if (data is string sRet)
{
dataDescriptor->Size = (uint)((sRet.Length + 1) * 2);
return sRet;
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndSubclass.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndSubclass.cs
index d17b78efeac..2e351428b57 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndSubclass.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndSubclass.cs
@@ -398,9 +398,7 @@ private object DispatcherCallbackOperation(object o)
param.retVal = IntPtr.Zero;
if (_bond == Bond.Attached)
{
- HwndWrapperHook hook= _hook.Target as HwndWrapperHook;
-
- if (hook != null)
+ if (_hook.Target is HwndWrapperHook hook)
{
// make the call
param.retVal = hook(param.hwnd, param.msg, param.wParam, param.lParam, ref param.handled);
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs
index 96ce2a431e2..6cfce7c953e 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs
@@ -72,9 +72,7 @@ public override string ToString()
public override bool Equals( object obj )
{
- XFORM xform = obj as XFORM;
-
- if( xform == null )
+ if (obj is not XFORM xform)
{
return false;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs
index 93ff97928a8..26e3d2bbdcc 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/ReflectionHelper.cs
@@ -200,8 +200,7 @@ internal static Type GetReflectionType(object item)
if (item == null)
return null;
- ICustomTypeProvider ictp = item as ICustomTypeProvider;
- if (ictp == null)
+ if (item is not ICustomTypeProvider ictp)
return item.GetType();
else
return ictp.GetCustomType();
@@ -230,7 +229,7 @@ private static string GetCustomAttributeData(MemberInfo mi, Type attrType, out T
{
IList list = CustomAttributeData.GetCustomAttributes(mi);
string attrValue = GetCustomAttributeData(list, attrType, out typeValue, true, false);
- return attrValue is null ? string.Empty : attrValue;
+ return attrValue ?? string.Empty;
}
#if PBTCOMPILER
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
index 63be6a4d974..5d7e42f885c 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
@@ -65,14 +65,12 @@ internal static class NameValidationHelper
#if !PBTCOMPILER
internal static bool NameValidationCallback(object candidateName)
{
- string name = candidateName as string;
-
- if( name != null )
+ if (candidateName is string name)
{
// Non-null string, ask the XAML validation code for blessing.
return IsValidIdentifierName(name);
}
- else if( candidateName == null )
+ else if (candidateName == null)
{
// Null string is allowed
return true;
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs
index 936df76619b..c08d0a1ad33 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs
@@ -49,9 +49,8 @@ internal static MemberInfo GetMemberInfoForPropertyConverter(object dpOrPiOrMi)
{
MethodInfo methodInfo;
#if !PBTCOMPILER
- DependencyProperty dp = dpOrPiOrMi as DependencyProperty;
- if (dp != null)
+ if (dpOrPiOrMi is DependencyProperty dp)
{
// While parsing styles or templates, we end up getting a DependencyProperty,
// even for non-attached cases. In this case, we try fetching the CLR
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs
index f79ef3e6315..e4357f59f74 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/XmlCompatibilityReader.cs
@@ -713,10 +713,8 @@ public bool Normalization
{
set
{
- XmlTextReader xmlTextReader = Reader as XmlTextReader;
-
// review, what if not the XmlTextReader.
- if (xmlTextReader is not null)
+ if (Reader is XmlTextReader xmlTextReader)
{
xmlTextReader.Normalization = value;
}
@@ -731,8 +729,7 @@ internal System.Text.Encoding Encoding
{
get
{
- XmlTextReader textReader = Reader as XmlTextReader;
- if (textReader is null)
+ if (Reader is not XmlTextReader textReader)
{
return new System.Text.UTF8Encoding(true, true);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs
index 49a41769b12..9f9f269f0b5 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipAdorner.cs
@@ -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.
@@ -34,7 +34,7 @@ public KeyTipAdorner(UIElement adornedElement,
RibbonGroup ownerRibbonGroup)
: base(adornedElement)
{
- PlacementTarget = (placementTarget == null ? adornedElement : placementTarget);
+ PlacementTarget = (placementTarget ?? adornedElement);
HorizontalPlacement = horizontalPlacement;
VerticalPlacement = verticalPlacement;
HorizontalOffset = horizontalOffset;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs
index 45391bf4528..1ad9176dd2c 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/KeyTipService.cs
@@ -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.
@@ -1380,7 +1380,7 @@ private static void OnShowingKeyTipChanged(DependencyObject element, DependencyP
if (activatingEventArgs.KeyTipVisibility == Visibility.Visible)
{
// Create the keytip and add it as the adorner.
- UIElement adornedElement = RibbonHelper.GetContainingUIElement(activatingEventArgs.PlacementTarget == null ? element : activatingEventArgs.PlacementTarget);
+ UIElement adornedElement = RibbonHelper.GetContainingUIElement(activatingEventArgs.PlacementTarget ?? element);
if (adornedElement != null && adornedElement.IsVisible)
{
bool isScrollAdornerLayer = false;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs
index 167d935e0a1..cf25994dd48 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs
@@ -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.
@@ -95,9 +95,8 @@ public RibbonControlLength(double value, RibbonControlLengthUnitType type)
///
public override bool Equals(object obj)
{
- if (obj is RibbonControlLength)
+ if (obj is RibbonControlLength length)
{
- RibbonControlLength length = (RibbonControlLength)obj;
return (this == length);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
index 938d28501f1..d76549ece6e 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/InertiaProcessor2D.cs
@@ -328,22 +328,19 @@ public void SetParameters(InertiaParameters2D parameters)
{
ArgumentNullException.ThrowIfNull(parameters);
- InertiaTranslationBehavior2D translationParameters = parameters as InertiaTranslationBehavior2D;
- if (translationParameters != null)
+ if (parameters is InertiaTranslationBehavior2D translationParameters)
{
TranslationBehavior = translationParameters;
return;
}
- InertiaRotationBehavior2D rotationParameters = parameters as InertiaRotationBehavior2D;
- if (rotationParameters != null)
+ if (parameters is InertiaRotationBehavior2D rotationParameters)
{
RotationBehavior = rotationParameters;
return;
}
- InertiaExpansionBehavior2D expansionParameters = parameters as InertiaExpansionBehavior2D;
- if (expansionParameters != null)
+ if (parameters is InertiaExpansionBehavior2D expansionParameters)
{
ExpansionBehavior = expansionParameters;
return;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/Reference.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/Reference.cs
index e69cfe43cbe..de7ad9b2bc6 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/Reference.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/Reference.cs
@@ -26,8 +26,7 @@ public Reference(string name)
public override object ProvideValue(IServiceProvider serviceProvider)
{
ArgumentNullException.ThrowIfNull(serviceProvider);
- IXamlNameResolver nameResolver = serviceProvider.GetService(typeof(IXamlNameResolver)) as IXamlNameResolver;
- if (nameResolver is null)
+ if (serviceProvider.GetService(typeof(IXamlNameResolver)) is not IXamlNameResolver nameResolver)
{
throw new InvalidOperationException(SR.MissingNameResolver);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs
index ac809630501..013a7a054f3 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs
@@ -80,8 +80,7 @@ public override object ProvideValue(IServiceProvider serviceProvider)
ArgumentNullException.ThrowIfNull(serviceProvider);
- IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
- if (xamlTypeResolver is null)
+ if (serviceProvider.GetService(typeof(IXamlTypeResolver)) is not IXamlTypeResolver xamlTypeResolver)
{
throw new ArgumentException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, nameof(IXamlTypeResolver)));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs
index 3f8b3fb5065..ec28fbabc34 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs
@@ -67,8 +67,7 @@ public override object ProvideValue(IServiceProvider serviceProvider)
// Get the IXamlTypeResolver from the service provider
ArgumentNullException.ThrowIfNull(serviceProvider);
- IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
- if( xamlTypeResolver is null)
+ if (serviceProvider.GetService(typeof(IXamlTypeResolver)) is not IXamlTypeResolver xamlTypeResolver)
{
throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, nameof(IXamlTypeResolver)));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/AttachablePropertyServices.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/AttachablePropertyServices.cs
index 0a5bbf33e95..0cc0e5d3be3 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/AttachablePropertyServices.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/AttachablePropertyServices.cs
@@ -20,8 +20,7 @@ public static int GetAttachedPropertyCount(object instance)
return 0;
}
- IAttachedPropertyStore ap = instance as IAttachedPropertyStore;
- if (ap is not null)
+ if (instance is IAttachedPropertyStore ap)
{
return ap.PropertyCount;
}
@@ -36,8 +35,7 @@ public static void CopyPropertiesTo(object instance, KeyValuePair(object instance, AttachableMemberIdentifier
return false;
}
- IAttachedPropertyStore ap = instance as IAttachedPropertyStore;
- if (ap is not null)
+ if (instance is IAttachedPropertyStore ap)
{
object obj;
bool result = ap.TryGetProperty(name, out obj);
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ContextServices.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ContextServices.cs
index 0dd64851cf9..a5ef906ed48 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ContextServices.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ContextServices.cs
@@ -17,8 +17,7 @@ public static object GetTargetProperty(ObjectWriterContext xamlContext)
// If the XamlMember implements IProvideValueTarget, ask it for the TargetProperty first
Debug.Assert(xamlContext.ParentProperty is not null);
- IProvideValueTarget ipvt = xamlContext.ParentProperty as IProvideValueTarget;
- if (ipvt is not null)
+ if (xamlContext.ParentProperty is IProvideValueTarget ipvt)
{
return ipvt.TargetProperty;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
index 0c851e12c0c..d4fce78e789 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
@@ -385,10 +385,9 @@ private List FindAmbientValues(IEnumerable ceili
{ // The Ambient Property is either Fully build or not set.
// FIRST: Ask the object (via IQueryAmbient interface) if it has a value for this property.
// This is usefull to prevent needless creation of empty lazy properties.
- var ambientCtrl = inst as XAML3.IQueryAmbient;
// If there is no ambientControl or if ambientControl says YES, then get the property value.
- if (ambientCtrl is null || ambientCtrl.IsAmbientPropertyAvailable(prop.Name))
+ if (inst is not XAML3.IQueryAmbient ambientCtrl || ambientCtrl.IsAmbientPropertyAvailable(prop.Name))
{
returnAmbientValue = true;
value = _runtime.GetValue(inst, prop);
@@ -892,8 +891,7 @@ private XAML3.INameScopeDictionary HuntAroundForARootNameScope(ObjectWriterFrame
if (nameScopeDictionary is null)
{
- XAML3.INameScope nameScope = inst as XAML3.INameScope;
- if (nameScope is not null)
+ if (inst is XAML3.INameScope nameScope)
{
nameScopeDictionary = new NameScopeDictionary(nameScope);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterFrame.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterFrame.cs
index 975c29a1230..b2564975e57 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterFrame.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterFrame.cs
@@ -138,8 +138,7 @@ public object Key
{
// We use a special KeyHolder in some x:Reference scenarios.
// We need to unwrap this when returning.
- FixupTargetKeyHolder ftkh = _key as FixupTargetKeyHolder;
- if (ftkh is not null)
+ if (_key is FixupTargetKeyHolder ftkh)
{
return ftkh.Key;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/EventConverter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/EventConverter.cs
index 8f43c1aaec3..d0507eafa33 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/EventConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/EventConverter.cs
@@ -50,16 +50,14 @@ internal static void GetRootObjectAndDelegateType(ITypeDescriptorContext? contex
return;
}
- IRootObjectProvider? rootObjectService = context.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
- if (rootObjectService is null)
+ if (context.GetService(typeof(IRootObjectProvider)) is not IRootObjectProvider rootObjectService)
{
return;
}
rootObject = rootObjectService.RootObject;
- IDestinationTypeProvider? targetService = context.GetService(typeof(IDestinationTypeProvider)) as IDestinationTypeProvider;
- if (targetService is null)
+ if (context.GetService(typeof(IDestinationTypeProvider)) is not IDestinationTypeProvider targetService)
{
return;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlNodes.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlNodes.cs
index ed2a9b23262..8041245a08b 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlNodes.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlNodes.cs
@@ -269,9 +269,8 @@ internal static bool IsEof_Helper(XamlNodeType nodeType, object data)
return false;
}
- if (data is InternalNodeType)
+ if (data is InternalNodeType internalNodeType)
{
- InternalNodeType internalNodeType = (InternalNodeType)data;
if (internalNodeType == InternalNodeType.EndOfStream)
{
return true;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs
index aeafe4514aa..ef9ff187915 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlObjectWriter.cs
@@ -771,8 +771,7 @@ public override void WriteEndMember()
bool shouldSetValue = true;
if (value is not null)
{
- XAML3.MarkupExtension me = value as XAML3.MarkupExtension;
- if (me is not null)
+ if (value is XAML3.MarkupExtension me)
{
_context.CurrentInstance = me;
XamlType valueXamlType = GetXamlType(value.GetType());
@@ -1156,8 +1155,7 @@ private void Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
object[] args = ctx.CurrentCtorArgs;
for (int i = 0; i < args.Length; i++)
{
- XAML3.MarkupExtension me = args[i] as XAML3.MarkupExtension;
- if (me is not null)
+ if (args[i] is XAML3.MarkupExtension me)
{
args[i] = Logic_PushAndPopAProvideValueStackFrame(ctx, XamlLanguage.PositionalParameters, me, false);
}
@@ -1338,8 +1336,7 @@ private bool Logic_CreatePropertyValueFromValue(ObjectWriterContext ctx)
XamlType propertyType = property.Type;
object value = ctx.CurrentInstance;
- XamlReader deferredContent = value as XamlReader;
- if (deferredContent is not null)
+ if (value is XamlReader deferredContent)
{
// property.DeferringLoader looks at the property AND the type of the property.
XamlValueConverter deferringLoader = property.DeferringLoader;
@@ -1566,8 +1563,7 @@ private void Logic_ApplyCurrentPreconstructionPropertyValues(ObjectWriterContext
// so don't call ProvideValue() now on directives here.
// (x:Key and x:Name need their own "saved spot" outside of PreconstructionPropertyValues)
- XAML3.MarkupExtension me = value as XAML3.MarkupExtension;
- if (me is not null && !prop.IsDirective)
+ if (value is XAML3.MarkupExtension me && !prop.IsDirective)
{
Logic_PushAndPopAProvideValueStackFrame(ctx, prop, me, true);
}
@@ -1808,8 +1804,7 @@ private void Logic_DoAssignmentToParentCollection(ObjectWriterContext ctx)
{
// If Value is a Markup Extention then check the collection item type
// if it can hold the ME then don't call ProvideValue().
- XAML3.MarkupExtension me = value as XAML3.MarkupExtension;
- if(me is not null && !Logic_WillParentCollectionAdd(ctx, value.GetType(), true))
+ if (value is XAML3.MarkupExtension me && !Logic_WillParentCollectionAdd(ctx, value.GetType(), true))
{
// We don't need to call Logic_ProvideValue() with the extra handler
// interfaces, because this is collection not a scalar property.
@@ -2046,9 +2041,8 @@ private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
}
ctx.ParentIsPropertyValueSet = true;
- if (value is NameFixupToken)
+ if (value is NameFixupToken token)
{
- var token = (NameFixupToken)value;
if (parentProperty.IsDirective)
{
// Only the key directive may be assigned a reference.
@@ -2174,8 +2168,7 @@ private void RegisterName(ObjectWriterContext ctx, string name,
XAML3.INameScope nameScope, XAML3.INameScope parentNameScope, bool isRoot)
{
XAML3.INameScope underlyingNameScope = nameScope;
- NameScopeDictionary nameScopeDict = nameScope as NameScopeDictionary;
- if (nameScopeDict is not null)
+ if (nameScope is NameScopeDictionary nameScopeDict)
{
underlyingNameScope = nameScopeDict.UnderlyingNameScope;
}
@@ -2233,8 +2226,7 @@ private void Logic_ValidateXClass(ObjectWriterContext ctx, object value)
throw ctx.WithLineInfo(new XamlObjectWriterException(SR.Format(SR.DirectiveNotAtRoot, XamlLanguage.Class)));
}
- string className = value as string;
- if (className is null)
+ if (value is not string className)
{
throw ctx.WithLineInfo(new XamlObjectWriterException(SR.Format(SR.DirectiveMustBeString, XamlLanguage.Class)));
}
@@ -2593,8 +2585,7 @@ private void ProcessNameFixup_Reparse(NameFixupToken token, bool nameResolutionI
_lastInstance = owc.CurrentInstance;
}
- NameFixupToken newToken = owc.CurrentInstance as NameFixupToken;
- if (newToken is not null)
+ if (owc.CurrentInstance is NameFixupToken newToken)
{
// Line Info should be the same as the original token, not wherever we happen to be currently.
// Also several properties on Target (IsOnTheStack, EndInstanceLineInfo, and potentially others)
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlXmlReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlXmlReader.cs
index cf349e8fd21..0c576cb6bee 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlXmlReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/InfosetObjects/XamlXmlReader.cs
@@ -196,9 +196,8 @@ private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContex
_mergedSettings.XmlLang = myXmlReader.XmlLang;
}
- IXmlNamespaceResolver myXmlReaderNS = myXmlReader as IXmlNamespaceResolver;
Dictionary xmlnsDictionary = null;
- if (myXmlReaderNS is not null)
+ if (myXmlReader is IXmlNamespaceResolver myXmlReaderNS)
{
IDictionary rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local);
if (rootNamespaces is not null)
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs
index 061426ac968..2bf4dc513b5 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs
@@ -124,8 +124,7 @@ protected MethodInfo GetFactoryMethod(Type type, string methodName, object[] arg
{
// We go down this path even if there are no args, because we might match a params array
MemberInfo[] members = type.GetMember(methodName, MemberTypes.Method, flags);
- MethodBase[] methods = members as MethodBase[];
- if (methods is null)
+ if (members is not MethodBase[] methods)
{
methods = new MethodBase[members.Length];
Array.Copy(members, methods, members.Length);
@@ -382,8 +381,7 @@ public override IEnumerable GetDictionaryItems(object dictionar
// - an IDictionaryEnumerator,
// - an IEnumerator>, or
// - an IEnumerator that returns DictionaryEntrys
- IDictionaryEnumerator dictionaryEnumerator = enumerator as IDictionaryEnumerator;
- if (dictionaryEnumerator is not null)
+ if (enumerator is IDictionaryEnumerator dictionaryEnumerator)
{
return DictionaryEntriesFromIDictionaryEnumerator(dictionaryEnumerator);
}
@@ -464,8 +462,7 @@ public override void SetConnectionId(object root, int connectionId, object insta
{
try
{
- XAML3.IComponentConnector connector = root as XAML3.IComponentConnector;
- if(connector is not null)
+ if (root is XAML3.IComponentConnector connector)
{
connector.Connect(connectionId, instance);
}
@@ -485,10 +482,9 @@ public override void InitializationGuard(XamlType xamlType, object obj, bool beg
{
try
{
- ISupportInitialize supportInit = obj as ISupportInitialize;
- if(supportInit is not null)
+ if (obj is ISupportInitialize supportInit)
{
- if(begin)
+ if (begin)
{
supportInit.BeginInit();
}
@@ -531,8 +527,7 @@ public override void SetUriBase(XamlType xamlType, object obj, Uri baseUri)
{
try
{
- XAML3.IUriContext uriContext = obj as XAML3.IUriContext;
- if(uriContext is not null)
+ if (obj is XAML3.IUriContext uriContext)
{
uriContext.BaseUri = baseUri;
}
@@ -553,14 +548,12 @@ public override void SetUriBase(XamlType xamlType, object obj, Uri baseUri)
public override void SetXmlInstance(object inst, XamlMember property, XAML3.XData xData)
{
object propInstance = GetValue(inst, property, true);
- IXmlSerializable iXmlSerial = propInstance as IXmlSerializable;
- if(iXmlSerial is null)
+ if (propInstance is not IXmlSerializable iXmlSerial)
{
throw CreateException((SR.Format(SR.XmlDataNull, property.Name)));
}
- XmlReader reader = xData.XmlReader as XmlReader;
- if(reader is null)
+ if (xData.XmlReader is not XmlReader reader)
{
throw new XamlInternalException(SR.Format(SR.XmlValueNotReader, property.Name));
}
@@ -602,8 +595,7 @@ public override object DeferredLoad(ServiceProviderContext serviceContext,
catch (Exception e)
{
// Reset the reader in case our caller catches and retries
- IXamlIndexingReader indexingReader = deferredContent as IXamlIndexingReader;
- if(indexingReader is not null && indexingReader.CurrentIndex >= 0)
+ if (deferredContent is IXamlIndexingReader indexingReader && indexingReader.CurrentIndex >= 0)
{
indexingReader.CurrentIndex = -1;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs
index 48d75bc686a..3d13094809c 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs
@@ -164,8 +164,7 @@ public override object CreateFromValue(
{
if (ts == BuiltInValueConverter.Event)
{
- string valueString = value as string;
- if (valueString is not null)
+ if (value is string valueString)
{
object rootObject;
Type delegateType;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
index 48d180f9719..d40b99ebdc6 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
@@ -410,8 +410,7 @@ internal static XamlMember LookupNameScopeProperty(XamlType xamlType)
// We only check this once, at the root of the doc, and only in ObjectWriter.
// So it's fine to use live reflection here.
object obj = GetCustomAttribute(typeof(XAML3.NameScopePropertyAttribute), xamlType.UnderlyingType);
- XAML3.NameScopePropertyAttribute nspAttr = obj as XAML3.NameScopePropertyAttribute;
- if (nspAttr is not null)
+ if (obj is XAML3.NameScopePropertyAttribute nspAttr)
{
Type ownerType = nspAttr.Type;
string propertyName = nspAttr.Name;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs
index 61089548954..f1685238a04 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs
@@ -58,8 +58,7 @@ public EventHandler SetTypeConverterHandler
public virtual void AddToCollection(object instance, object item)
{
ArgumentNullException.ThrowIfNull(instance);
- IList list = instance as IList;
- if (list is not null)
+ if (instance is IList list)
{
list.Add(item);
return;
@@ -93,8 +92,7 @@ public virtual void AddToCollection(object instance, object item)
public virtual void AddToDictionary(object instance, object key, object item)
{
ArgumentNullException.ThrowIfNull(instance);
- IDictionary dictionary = instance as IDictionary;
- if (dictionary is not null)
+ if (instance is IDictionary dictionary)
{
dictionary.Add(key, item);
return;
@@ -213,8 +211,7 @@ public virtual MethodInfo GetEnumeratorMethod()
public virtual IEnumerator GetItems(object instance)
{
ArgumentNullException.ThrowIfNull(instance);
- IEnumerable enumerable = instance as IEnumerable;
- if (enumerable is not null)
+ if (instance is IEnumerable enumerable)
{
return enumerable.GetEnumerator();
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeTypeConverter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeTypeConverter.cs
index ce325723e8d..7879e29f3c0 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeTypeConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeTypeConverter.cs
@@ -18,9 +18,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
- string typeName = value as string;
-
- if (context is not null && typeName is not null)
+ if (context is not null && value is string typeName)
{
XamlType result = ConvertStringToXamlType(context, typeName);
if (result is not null)
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs
index a5f691db79c..bf55754d45b 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs
@@ -106,8 +106,7 @@ private string GetDefaultName()
public override bool Equals(object obj)
{
- XamlValueConverter other = obj as XamlValueConverter;
- if (other is null)
+ if (obj is not XamlValueConverter other)
{
return false;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs
index ca85e41de68..9e9cdd6edeb 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlException.cs
@@ -22,8 +22,7 @@ public XamlException(string message, Exception innerException, int lineNumber, i
public XamlException(string message, Exception innerException)
: base(message, innerException)
{
- XamlException xex = innerException as XamlException;
- if (xex is not null)
+ if (innerException is XamlException xex)
{
LineNumber = xex.LineNumber;
LinePosition = xex.LinePosition;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs
index f7ce28b32d8..b8940205126 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs
@@ -173,9 +173,7 @@ public override void WriteNamespace(NamespaceDeclaration namespaceDeclaration)
public override void WriteValue(object value)
{
- string s = value as string;
-
- if (s is null)
+ if (value is not string s)
{
throw new ArgumentException(SR.XamlMarkupExtensionWriterCannotWriteNonstringValue);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
index 6509691e513..ca35ae1a179 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
@@ -101,8 +101,7 @@ public override bool Read()
MarkupInfo node = nodes.Pop();
currentXamlNode = node.XamlNode;
- ObjectMarkupInfo objectNode = node as ObjectMarkupInfo;
- currentInstance = objectNode is not null ? objectNode.Object : null;
+ currentInstance = node is ObjectMarkupInfo objectNode ? objectNode.Object : null;
var subNodes = node.Decompose();
@@ -279,8 +278,7 @@ public bool IsAttributableMarkupExtension
return false;
}
- ObjectMarkupInfo r = children[0] as ObjectMarkupInfo;
- return (r is not null && r.IsAttributableMarkupExtension);
+ return (children[0] is ObjectMarkupInfo r && r.IsAttributableMarkupExtension);
}
}
@@ -309,8 +307,7 @@ public bool IsAttributable
// Empty collections and atoms are attributable
if (Children.Count == 0 || Children[0] is ValueMarkupInfo) { return true; }
- ObjectMarkupInfo r = Children[0] as ObjectMarkupInfo;
- if (r is null)
+ if (Children[0] is not ObjectMarkupInfo r)
{
throw new InvalidOperationException(SR.ExpectedObjectMarkupInfo);
}
@@ -674,19 +671,16 @@ static void RemoveObjectNodesForCollectionOrDictionary(MemberMarkupInfo memberIn
{
if (memberInfo.Children.Count == 1)
{
- var objectInfo = memberInfo.Children[0] as ObjectMarkupInfo;
- if (objectInfo is not null && objectInfo.Properties.Count == 1 && memberType == objectInfo.XamlNode.XamlType)
+ if (memberInfo.Children[0] is ObjectMarkupInfo objectInfo && objectInfo.Properties.Count == 1 && memberType == objectInfo.XamlNode.XamlType)
{
if (objectInfo.Properties[0].XamlNode.Member == XamlLanguage.Items)
{
- var itemsMemberInfo = objectInfo.Properties[0] as MemberMarkupInfo;
- if(itemsMemberInfo is not null && itemsMemberInfo.Children.Count > 0)
+ if (objectInfo.Properties[0] is MemberMarkupInfo itemsMemberInfo && itemsMemberInfo.Children.Count > 0)
{
// Check if the first element of the collection/dictionary is a ME and replace the SO with GO only if it is not an ME.
// This is to handle cases where the first element is, say, null. If we remove the SO, then there is no way to
// know if the collection is null or the first element is null.
- var itemInfo = itemsMemberInfo.Children[0] as ObjectMarkupInfo;
- if(itemInfo is null || itemInfo.XamlNode.XamlType is null || !itemInfo.XamlNode.XamlType.IsMarkupExtension)
+ if (itemsMemberInfo.Children[0] is not ObjectMarkupInfo itemInfo || itemInfo.XamlNode.XamlType is null || !itemInfo.XamlNode.XamlType.IsMarkupExtension)
{
// change the member to GetObject
objectInfo.XamlNode = new XamlNode(XamlNodeType.GetObject);
@@ -1237,14 +1231,12 @@ void AddFactoryMethodAndValidateArguments(Type valueType, MemberInfo memberInfo,
// default ctor
methodParams = Array.Empty();
}
- else if (memberInfo is ConstructorInfo)
+ else if (memberInfo is ConstructorInfo ctor)
{
- var ctor = (ConstructorInfo)memberInfo;
methodParams = ctor.GetParameters();
}
- else if (memberInfo is MethodInfo)
+ else if (memberInfo is MethodInfo mi)
{
- var mi = (MethodInfo)memberInfo;
methodParams = mi.GetParameters();
var methodName = memberInfo.Name;
@@ -1936,8 +1928,7 @@ public static ObjectMarkupInfo ForObject(object value, SerializerContext context
// throw new XamlObjectReaderException(SR.XamlSerializerCannotHaveXDataAtRoot(valueType.Name));
// }
- var valueAsArray = value as Array;
- if (valueAsArray is not null)
+ if (value is Array valueAsArray)
{
return ForArray(valueAsArray, context);
}
@@ -3055,8 +3046,7 @@ public Entry(TKey key, TValue value)
public override bool Equals(object obj)
{
- Entry other = obj as Entry;
- return other is not null && other.Key.Equals(Key);
+ return obj is Entry other && other.Key.Equals(Key);
}
public override int GetHashCode()
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
index d815159c135..341dbbd63f0 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
@@ -812,8 +812,7 @@ internal bool AreInternalsVisibleTo(Assembly fromAssembly, Assembly toAssembly)
private static void CleanupCollectedAssemblies(object schemaContextWeakRef)
{
WeakReference weakRef = (WeakReference)schemaContextWeakRef;
- XamlSchemaContext schemaContext = weakRef.Target as XamlSchemaContext;
- if (schemaContext is not null)
+ if (weakRef.Target is XamlSchemaContext schemaContext)
{
schemaContext.CleanupCollectedAssemblies();
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs
index 5068ec3c9a0..d769f96d4d4 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs
@@ -667,8 +667,7 @@ internal ConstructorInfo GetConstructor(Type[] paramTypes)
}
IEnumerable ctors = GetConstructors();
- ConstructorInfo[] ctorArray = ctors as ConstructorInfo[];
- if (ctorArray is null)
+ if (ctors is not ConstructorInfo[] ctorArray)
{
ctorArray = new List(ctors).ToArray();
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs
index 9709881946d..de5c34bf120 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs
@@ -212,8 +212,7 @@ public override void WriteValue(object value)
}
else
{
- string s = value as string;
- if (s is null)
+ if (value is not string s)
{
throw new ArgumentException(SR.XamlXmlWriterCannotWriteNonstringValue, nameof(value));
}
diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs
index ede2cca9ec8..58b43248ba6 100644
--- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs
+++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs
@@ -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.
@@ -174,15 +174,14 @@ internal static ClientSideProviderDescription[] GetProxyDescriptionTable()
{
proxyDescriptions[count++] = (ClientSideProviderDescription)o;
}
- else if (o is ClientSideProviderFactoryCallback)
+ else if (o is ClientSideProviderFactoryCallback pfc)
{
- ClientSideProviderFactoryCallback pfc = (ClientSideProviderFactoryCallback)o;
proxyDescriptions[count++] = new ClientSideProviderDescription(pfc, null);
}
else
{
- foreach( Object o1 in (ArrayList) o )
+ foreach (Object o1 in (ArrayList)o)
{
proxyDescriptions[count++] = (ClientSideProviderDescription)o1;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/ItemContainerPattern.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/ItemContainerPattern.cs
index b56a56a55e4..0ee850ca855 100644
--- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/ItemContainerPattern.cs
+++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/ItemContainerPattern.cs
@@ -154,14 +154,12 @@ private object PropertyValueValidateAndMap(AutomationProperty property, object v
// If this is a control type, use the ID, not the CLR object
value = ((ControlType)value).Id;
}
- else if (value is Rect)
+ else if (value is Rect rc)
{
- Rect rc = (Rect)value;
value = new double[] { rc.Left, rc.Top, rc.Width, rc.Height };
}
- else if (value is Point)
+ else if (value is Point pt)
{
- Point pt = (Point)value;
value = new double[] { pt.X, pt.Y };
}
else if (value is CultureInfo)
diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/PropertyCondition.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/PropertyCondition.cs
index b7e84b922e6..3a46207b5ad 100644
--- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/PropertyCondition.cs
+++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/PropertyCondition.cs
@@ -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.
@@ -157,24 +157,21 @@ void Init(AutomationProperty property, object val, PropertyConditionFlags flags
// If this is a control type, use the ID, not the CLR object
val = ((ControlType)val).Id;
}
- else if (val is Rect)
+ else if (val is Rect rc)
{
- Rect rc = (Rect)val;
val = new double[] { rc.Left, rc.Top, rc.Width, rc.Height };
}
- else if (val is Point)
+ else if (val is Point pt)
{
- Point pt = (Point)val;
val = new double[] { pt.X, pt.Y };
}
else if (val is CultureInfo)
{
val = ((CultureInfo)val).LCID;
}
- else if (val is AutomationHeadingLevel)
+ else if (val is AutomationHeadingLevel automationHeadingLevel)
{
- AutomationHeadingLevel automationHeadingLevel = (AutomationHeadingLevel)(val);
- switch(automationHeadingLevel)
+ switch (automationHeadingLevel)
{
case AutomationHeadingLevel.None:
val = HeadingLevel.None;
diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs
index 84284eb9995..cf6faea09a1 100644
--- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs
+++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs
@@ -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.
@@ -517,7 +517,7 @@ internal string Value
// Need to convert nulls into an empty string, so need to just test for a null.
// Therefore we can not use IsNullOrEmpty() here, suppress the warning.
#pragma warning suppress 6507
- return value != null ? value : "";
+ return value ?? "";
}
catch (Exception e)
{
@@ -574,9 +574,8 @@ internal static Accessible GetFullAccessibleChildByIndex(Accessible accParent, i
{
return Accessible.Wrap(accChild);
}
- else if (child is int)
+ else if (child is int idChild)
{
- int idChild = (int)child;
return Accessible.Wrap(accParent.IAccessible, idChild);
}
}
@@ -640,11 +639,10 @@ internal Accessible [] GetSelection()
children = new Accessible[1];
children[0] = AccessibleFromObject(obj, _acc);
}
- else if (obj is object [])
+ else if (obj is object[] objs)
{
- object [] objs = (object [])obj;
children = new Accessible[objs.Length];
- for (int i=0;i 0 && milist[0] != null)
+ if (milist.Length > 0 && milist[0] != null)
{
paAttrs = (Attribute[])milist[0].GetCustomAttributes(typeof(Attribute), true);
}
}
- else {
+ else
+ {
paAttrs = (Attribute[])providerType.GetCustomAttributes(typeof(Attribute), true);
}
if (paAttrs != null)
{
- if (addAttrs == null)
+ if (addAttrs == null)
{
addAttrs = paAttrs;
}
@@ -512,7 +512,7 @@ private AttributeCollection GetAttachedPropertyAttributes()
addAttrs.CopyTo(newArray, 0);
paAttrs.CopyTo(newArray, addAttrs.Length);
addAttrs = newArray;
-}
+ }
}
}
}
@@ -572,7 +572,7 @@ private static MethodInfo GetAttachedPropertySetMethod(DependencyProperty dp)
method = reflectionType.GetMethod(methodName, f, _dpBinder, paramTypes, null);
lock(_setMethodCache) {
- _setMethodCache[dp] = (method == null ? _nullMethodSentinel : method);
+ _setMethodCache[dp] = (method ?? _nullMethodSentinel);
}
}
@@ -664,18 +664,16 @@ private void MergeAttributes()
foreach (Attribute a in baseAttributes)
{
Attribute attrToAdd = a;
- DefaultValueAttribute defAttr = a as DefaultValueAttribute;
- if (defAttr != null)
+ if (a is DefaultValueAttribute defAttr)
{
// DP metadata always overrides CLR metadata for
// default value.
attrToAdd = null;
}
- else
+ else
{
- ReadOnlyAttribute roAttr = a as ReadOnlyAttribute;
- if (roAttr != null)
+ if (a is ReadOnlyAttribute roAttr)
{
// DP metata is the merge of CLR metadata for
// read only
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyObjectProvider.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyObjectProvider.cs
index c157123984d..66456ece627 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyObjectProvider.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyObjectProvider.cs
@@ -96,13 +96,11 @@ public override ICustomTypeDescriptor GetExtendedTypeDescriptor(object instance)
///
public override IDictionary GetCache(object instance)
{
- DependencyObject d = instance as DependencyObject;
-
// This should never happen because we are bound only
// to dependency object types. However, in case it
// does, simply invoke the base and get out.
- if (d == null)
+ if (instance is not DependencyObject d)
{
return base.GetCache(instance);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyPropertyAttribute.cs
index 51ae8f9d290..58a3e43fe23 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyPropertyAttribute.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ComponentModel/DependencyPropertyAttribute.cs
@@ -48,11 +48,9 @@ internal DependencyPropertyAttribute(DependencyProperty dependencyProperty, bool
///
public override bool Equals(object value)
{
- DependencyPropertyAttribute da = value as DependencyPropertyAttribute;
-
- if (da != null &&
- object.ReferenceEquals(da._dp, _dp) &&
- da._isAttached == _isAttached)
+ if (value is DependencyPropertyAttribute da &&
+ object.ReferenceEquals(da._dp, _dp) &&
+ da._isAttached == _isAttached)
{
return true;
}
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/FreezableDefaultValueFactory.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/FreezableDefaultValueFactory.cs
index 3ad6f21d37f..79354657052 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/FreezableDefaultValueFactory.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/FreezableDefaultValueFactory.cs
@@ -52,14 +52,13 @@ internal override object CreateDefaultValue(DependencyObject owner, DependencyPr
"It is the caller responsibility to ensure that owner and property are non-null.");
Freezable result = _defaultValuePrototype;
- Freezable ownerFreezable = owner as Freezable;
-
+
// If the owner is frozen, just return the frozen prototype.
- if (ownerFreezable != null && ownerFreezable.IsFrozen)
+ if (owner is Freezable ownerFreezable && ownerFreezable.IsFrozen)
{
return result;
}
-
+
result = _defaultValuePrototype.Clone();
// Wire up a FreezableDefaultPromoter to observe the default value we
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs
index bfa34587233..377c6116d24 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/RightsManagementEncryptionTransform.cs
@@ -754,8 +754,7 @@ private void
ref bool stop
)
{
- LoadUseLicenseForUserParams lulfup = param as LoadUseLicenseForUserParams;
- if (lulfup == null)
+ if (param is not LoadUseLicenseForUserParams lulfup)
{
throw new ArgumentException(SR.CallbackParameterInvalid, "param");
}
@@ -809,8 +808,7 @@ private void
ref bool stop
)
{
- ContentUser userToDelete = param as ContentUser;
- if (userToDelete == null)
+ if (param is not ContentUser userToDelete)
{
throw new ArgumentException(SR.CallbackParameterInvalid, "param");
}
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs
index 1fcdd598664..32845ad3214 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs
@@ -524,8 +524,7 @@ internal static HashAlgorithm GetHashAlgorithm(String hashAlgorithmName)
// we should attempt to dispose it if it offers IDisposable.
if (algorithm == null && o != null)
{
- IDisposable disposable = o as IDisposable;
- if (disposable != null)
+ if (o is IDisposable disposable)
disposable.Dispose();
}
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs
index 5488c32bcae..13338f5a41d 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/ClientSession.cs
@@ -917,8 +917,7 @@ private static Uri GetRegistryPassportCertificationUrl()
else
{
object keyValue = key.GetValue(null); // this should get the default value
- string stringValue = keyValue as string;
- if (stringValue != null)
+ if (keyValue is string stringValue)
{
return new Uri(stringValue);
}
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs
index 67fdfae5ac3..5659102499d 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs
@@ -65,15 +65,13 @@ private object InternalRealCall(Delegate callback, object args, int numArgs)
// expensive DynamicInvoke call.
if(numArgsEx == 0)
{
- Action action = callback as Action;
- if (action != null)
+ if (callback is Action action)
{
action();
}
else
{
- Dispatcher.ShutdownCallback shutdownCallback = callback as Dispatcher.ShutdownCallback;
- if(shutdownCallback != null)
+ if (callback is Dispatcher.ShutdownCallback shutdownCallback)
{
shutdownCallback();
}
@@ -86,21 +84,19 @@ private object InternalRealCall(Delegate callback, object args, int numArgs)
}
else if(numArgsEx == 1)
{
- DispatcherOperationCallback dispatcherOperationCallback = callback as DispatcherOperationCallback;
- if(dispatcherOperationCallback != null)
+ if (callback is DispatcherOperationCallback dispatcherOperationCallback)
{
result = dispatcherOperationCallback(singleArg);
}
else
{
- SendOrPostCallback sendOrPostCallback = callback as SendOrPostCallback;
- if(sendOrPostCallback != null)
+ if (callback is SendOrPostCallback sendOrPostCallback)
{
sendOrPostCallback(singleArg);
}
else
{
- if(numArgs == -1)
+ if (numArgs == -1)
{
// Explicitly pass an object[] to DynamicInvoke so that
// it will not try to wrap the arg in another object[].
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/TraceLevelStore.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/TraceLevelStore.cs
index d8caf22fe51..9cea4e4aa0f 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/TraceLevelStore.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/TraceLevelStore.cs
@@ -105,8 +105,7 @@ internal Key(object element)
public override int GetHashCode()
{
#if DEBUG
- WeakReference wr = _element as WeakReference;
- object element = (wr != null) ? wr.Target : _element;
+ object element = (_element is WeakReference wr) ? wr.Target : _element;
if (element != null)
{
int hashcode = element.GetHashCode();
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakEventTable.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakEventTable.cs
index 997497163ac..d5c7b3e8c4a 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakEventTable.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakEventTable.cs
@@ -516,8 +516,7 @@ internal WeakEventManager Manager
public override int GetHashCode()
{
#if DEBUG
- WeakReference wr = _source as WeakReference;
- object source = (wr != null) ? wr.Target : _source;
+ object source = (_source is WeakReference wr) ? wr.Target : _source;
if (source != null)
{
int hashcode = unchecked(_manager.GetHashCode() + RuntimeHelpers.GetHashCode(source));
@@ -585,9 +584,8 @@ public override int GetHashCode()
public override bool Equals(object o)
{
- if (o is EventNameKey)
+ if (o is EventNameKey that)
{
- EventNameKey that = (EventNameKey)o;
return (this._eventSourceType == that._eventSourceType && this._eventName == that._eventName);
}
else
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakReferenceKey.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakReferenceKey.cs
index f2d05031f72..29825da25e5 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakReferenceKey.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/WeakReferenceKey.cs
@@ -27,11 +27,10 @@ public override bool Equals(object o)
if (o == this)
return true;
- WeakReferenceKey key = o as WeakReferenceKey;
- if (key != null)
+ if (o is WeakReferenceKey key)
{
T item = this.Item;
-
+
if (item == null)
return false; // a stale key matches nothing (except itself)
diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Collections/ObjectModel/WeakReadOnlyCollection.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Collections/ObjectModel/WeakReadOnlyCollection.cs
index a2765032ca1..a0a634f2e52 100644
--- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Collections/ObjectModel/WeakReadOnlyCollection.cs
+++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Collections/ObjectModel/WeakReadOnlyCollection.cs
@@ -121,11 +121,12 @@ bool ICollection.IsSynchronized {
object ICollection.SyncRoot {
get {
if( _syncRoot == null) {
- ICollection c = list as ICollection;
- if( c != null) {
+ if (list is ICollection c)
+ {
_syncRoot = c.SyncRoot;
}
- else {
+ else
+ {
System.Threading.Interlocked.CompareExchange