Skip to content

Modernize C# snippets (System.ComponentModel) - #13016

Draft
gewarren wants to merge 1 commit into
dotnet:mainfrom
gewarren:modernize-system-componentmodel
Draft

Modernize C# snippets (System.ComponentModel)#13016
gewarren wants to merge 1 commit into
dotnet:mainfrom
gewarren:modernize-system-componentmodel

Conversation

@gewarren

@gewarren gewarren commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Contributes to #12713.


Internal previews

Toggle expand/collapse
File Preview link
snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs Preview published page
snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs Preview published page
snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs Preview published page
snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs Preview published page
snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs Preview published page
snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs Preview published page
snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs Preview published page
snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs Preview published page
snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs Preview published page
snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs Preview published page
snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs Preview published page
snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs Preview published page
snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs Preview published page

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.csproj files for several snippet directories targeting net10.0 / net10.0-windows to 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants