Modernize C# snippets (System.ComponentModel) - #13016
Draft
gewarren wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates C# snippet sources under snippets/csharp/System.ComponentModel* to use more modern C# syntax and adds SDK-style snippet projects so the samples can compile against .NET 10 (including Windows Forms where applicable), contributing to #12713.
Changes:
- Modernizes multiple System.ComponentModel-related snippet sources (target-typed
new, expression-bodied members, simplified formatting, and cleanup of unused usings). - Adds
Project.csprojfiles for several snippet directories targetingnet10.0/net10.0-windowsto enable snippet compilation. - Minor refactors to sample model types and event handlers for readability/modern style.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs | Reformats and modernizes the indexer-based PropertyDescriptorCollection sample. |
| snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs | Reformats and modernizes the index-based PropertyDescriptorCollection sample. |
| snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs | Modernizes the INotifyPropertyChanged WinForms sample code. |
| snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs | Reformats and modernizes the indexer-based EventDescriptorCollection sample. |
| snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs | Reformats and modernizes the index-based EventDescriptorCollection sample. |
| snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs | Modernizes a few event handler snippets to use interpolated strings / target-typed new. |
| snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs | Modernizes BindableAttribute constructor snippet (attributes + property formatting). |
| snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs | Modernizes BindableAttribute constructor snippet (attributes + property formatting). |
| snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs | Modernizes AttributeCollection.Matches overload sample (formatting + control flow). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs | Modernizes AttributeCollection.Matches sample (formatting + control flow). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Matches/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs | Modernizes AttributeCollection indexer sample (formatting/structure). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs | Modernizes AttributeCollection indexer sample (formatting/structure). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Item/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs | Modernizes AttributeCollection.Contains overload sample (formatting + control flow). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs | Modernizes AttributeCollection.Contains sample (formatting + control flow). |
| snippets/csharp/System.ComponentModel/AttributeCollection/Contains/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs | Modernizes the AddingNewEventArgs WinForms sample and its DemoCustomer model. |
| snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/Project.csproj | Adds a .NET 10 Windows Forms snippet project for compilation. |
| snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs | Modernizes the CollectionEditor-related EditorAttribute samples. |
| snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs | Modernizes the sample object + builder loop (auto-properties, target-typed new). |
| snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Project.csproj | Adds a .NET 10 snippet project for compilation. |
| snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs | Modernizes the basic sample type snippet (auto-properties / formatting). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
26
to
30
| public Form1() | ||
| { | ||
| InitializeComponent(); | ||
|
|
||
| // Set up the "Change Item" button. | ||
| this.changeItemBtn.Text = "Change Item"; | ||
| this.changeItemBtn.Dock = DockStyle.Bottom; |
Comment on lines
93
to
96
| // These fields hold the values for the public properties. | ||
| private Guid idValue = Guid.NewGuid(); | ||
| private string customerName = String.Empty; | ||
| private string companyNameValue = String.Empty; | ||
| private string phoneNumberValue = String.Empty; | ||
| private string customerName = string.Empty; | ||
|
|
||
| // The constructor is private to enforce the factory pattern. |
Comment on lines
+1
to
3
| // <snippet1> | ||
| namespace DSMSampleBasic | ||
| { |
Comment on lines
+16
to
+20
| // Gets the designer attribute from the collection. | ||
| DesignerAttribute myDesigner; | ||
| // You must supply a valid fully qualified assembly name here. | ||
| myDesigner = (DesignerAttribute)attributes[Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")]; | ||
| textBox1.Text = myDesigner.DesignerTypeName; |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
Comment on lines
+3
to
+7
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net10.0-windows</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributes to #12713.
Internal previews
Toggle expand/collapse