From 37c8103ae4290e22aa7fc145d84bf75652fbb256 Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sat, 11 Jan 2025 21:41:54 +0100 Subject: [PATCH 1/2] Convert typeof to nameof (IDE0082) --- src/Microsoft.DotNet.Wpf/src/.editorconfig | 3 --- .../System/Windows/Media3D/ModelVisual3D.cs | 2 +- .../System/Windows/Media3D/Viewport3DVisual.cs | 2 +- .../System/Windows/Controls/MenuItem.cs | 2 +- .../System/Windows/Controls/Primitives/MenuBase.cs | 2 +- .../System/Windows/Controls/Primitives/StatusBar.cs | 2 +- .../System/Windows/DeferrableContentConverter.cs | 2 +- .../System/Windows/Documents/TableColumnCollection.cs | 2 +- .../System/Windows/Documents/TextRangeSerialization.cs | 6 +++--- .../System/Windows/FrameworkTemplate.cs | 3 +-- .../System/Windows/TemplateContentLoader.cs | 4 ++-- 11 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index de3d6d28fd2..d4619e30e4d 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -242,9 +242,6 @@ dotnet_diagnostic.IDE0077.severity = suggestion # IDE0078: Use pattern matching dotnet_diagnostic.IDE0078.severity = suggestion -# IDE0082: 'typeof' can be converted to 'nameof' -dotnet_diagnostic.IDE0082.severity = suggestion - # IDE0100: Remove redundant equality dotnet_diagnostic.IDE0100.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs index 80469c929c1..bf29e3ec89e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs @@ -77,7 +77,7 @@ void IAddChild.AddChild(Object value) if (visual3D == null) { - throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, typeof(Visual3D).Name)); + throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, nameof(Visual3D))); } Children.Add(visual3D); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs index b41428c75dd..013f57f6b40 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Viewport3DVisual.cs @@ -493,7 +493,7 @@ internal override HitTestResultBehavior HitTestPointInternal( /// protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) { - throw new NotSupportedException(SR.Format(SR.HitTest_Invalid, typeof(GeometryHitTestParameters).Name, this.GetType().Name)); + throw new NotSupportedException(SR.Format(SR.HitTest_Invalid, nameof(GeometryHitTestParameters), this.GetType().Name)); } internal Point WorldToViewport(Point4D point) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs index 2be4fc0100e..6ee069af262 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs @@ -2099,7 +2099,7 @@ protected override DependencyObject GetContainerForItemOverride() } else { - throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, typeof(MenuItem).Name, typeof(Separator).Name, itemContainer)); + throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, nameof(MenuItem), nameof(Separator), itemContainer)); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/MenuBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/MenuBase.cs index 9f85482c19c..d393645a765 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/MenuBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/MenuBase.cs @@ -502,7 +502,7 @@ protected override DependencyObject GetContainerForItemOverride() } else { - throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, typeof(MenuItem).Name, typeof(Separator).Name, itemContainer)); + throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, nameof(MenuItem), nameof(Separator), itemContainer)); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/StatusBar.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/StatusBar.cs index 52d92abc756..738281e6f73 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/StatusBar.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/StatusBar.cs @@ -121,7 +121,7 @@ protected override DependencyObject GetContainerForItemOverride() } else { - throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, typeof(StatusBarItem).Name, typeof(Separator).Name, itemContainer)); + throw new InvalidOperationException(SR.Format(SR.InvalidItemContainer, this.GetType().Name, nameof(StatusBarItem), nameof(Separator), itemContainer)); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DeferrableContentConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DeferrableContentConverter.cs index db939b3225a..fc707eb7f4f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DeferrableContentConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DeferrableContentConverter.cs @@ -78,7 +78,7 @@ private static T RequireService(IServiceProvider provider) where T : class T result = provider.GetService(typeof(T)) as T; if (result == null) { - throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext, typeof(DeferrableContentConverter).Name, typeof(T).Name)); + throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext, nameof(DeferrableContentConverter), typeof(T).Name)); } return result; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumnCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumnCollection.cs index 4fbad5e3992..eb768b8499c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumnCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableColumnCollection.cs @@ -276,7 +276,7 @@ int IList.Add(object value) if (item == null) { - throw new ArgumentException(SR.Format(SR.TableCollectionElementTypeExpected, typeof(TableColumn).Name), nameof(value)); + throw new ArgumentException(SR.Format(SR.TableCollectionElementTypeExpected, nameof(TableColumn)), nameof(value)); } return ((IList)_columnCollection).Add(value); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeSerialization.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeSerialization.cs index 33cec3afdd2..25a346d9338 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeSerialization.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeSerialization.cs @@ -192,7 +192,7 @@ private static void WriteXamlTextSegment(XmlWriter xmlWriter, ITextPointer range if (elementLevel == EmptyDocumentDepth && typeof(Run).IsAssignableFrom(rangeStart.ParentType)) { elementLevel++; - xmlWriter.WriteStartElement(typeof(Run).Name); + xmlWriter.WriteStartElement(nameof(Run)); } // Create text navigator for reading the range's content @@ -1185,8 +1185,8 @@ private static void WriteEmbeddedObject(object embeddedObject, XmlWriter xmlWrit // Write Source property as the complex property to specify the BitmapImage // cache option as "OnLoad" instead of the default "OnDeman". Otherwise, // we couldn't load the image by disposing WpfPayload package. - xmlWriter.WriteStartElement($"{typeof(Image).Name}.{Image.SourceProperty.Name}"); - xmlWriter.WriteStartElement(typeof(System.Windows.Media.Imaging.BitmapImage).Name); + xmlWriter.WriteStartElement($"{nameof(Image)}.{Image.SourceProperty.Name}"); + xmlWriter.WriteStartElement(nameof(Media.Imaging.BitmapImage)); xmlWriter.WriteAttributeString(System.Windows.Media.Imaging.BitmapImage.UriSourceProperty.Name, imageSource); xmlWriter.WriteAttributeString(System.Windows.Media.Imaging.BitmapImage.CacheOptionProperty.Name, "OnLoad"); xmlWriter.WriteEndElement(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs index d7f0ff7c4e4..4c68f566050 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkTemplate.cs @@ -375,8 +375,7 @@ private void ValidateVisualTree(FrameworkElementFactory templateRoot) if (templateRoot != null && typeof(FrameworkContentElement).IsAssignableFrom(templateRoot.Type)) { - throw new ArgumentException(SR.Format(SR.VisualTreeRootIsFrameworkElement, - typeof(FrameworkElement).Name, templateRoot.Type.Name)); + throw new ArgumentException(SR.Format(SR.VisualTreeRootIsFrameworkElement, nameof(FrameworkElement), templateRoot.Type.Name)); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs index 84ef9362679..1acda16307e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs @@ -22,14 +22,14 @@ private static T RequireService(IServiceProvider provider) where T : class T result = provider.GetService(typeof(T)) as T; if (result == null) { - throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext,typeof(TemplateContentLoader).Name, typeof(T).Name)); + throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext,nameof(TemplateContentLoader), typeof(T).Name)); } return result; } public override XamlReader Save(object value, IServiceProvider serviceProvider) { - throw new NotSupportedException(SR.Format(SR.DeferringLoaderNoSave, typeof(TemplateContentLoader).Name)); + throw new NotSupportedException(SR.Format(SR.DeferringLoaderNoSave, nameof(TemplateContentLoader))); } } } From 2fe5edff6d63692b2f459534193cb353226a469c Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sun, 12 Jan 2025 11:03:06 +0100 Subject: [PATCH 2/2] Add whitespace in TemplateContentLoader --- .../System/Windows/TemplateContentLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs index 1acda16307e..c5c239afbc9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateContentLoader.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. @@ -22,7 +22,7 @@ private static T RequireService(IServiceProvider provider) where T : class T result = provider.GetService(typeof(T)) as T; if (result == null) { - throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext,nameof(TemplateContentLoader), typeof(T).Name)); + throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext, nameof(TemplateContentLoader), typeof(T).Name)); } return result; }