Modernize C# snippets - #13053
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A disposable resource leak and multiple formatting and comment issues remain unresolved.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Modernizes legacy System.Drawing C# snippets with current syntax, disposal patterns, and formatting conventions.
Changes:
- Introduces target-typed construction, collection expressions, aliases, and initializers.
- Improves disposable-resource handling.
- Normalizes imports, indentation, comments, and whitespace.
File summaries
| File | Review |
|---|---|
snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs |
Modernizes printing and disposal. Nit: rename stale pd_PrintPage handler. |
snippets/csharp/System.Drawing.Printing/PrinterSettings/Overview/source.cs |
Updates syntax and formatting. |
snippets/csharp/System.Drawing.Printing/PrinterSettings/IsDefaultPrinter/Form1.cs |
Modernizes fields, loops, and handlers. |
snippets/csharp/System.Drawing.Printing/PrintDocument/PrinterSettings/source.cs |
Updates printing syntax. |
snippets/csharp/System.Drawing.Printing/PrintDocument/PrintController/source.cs |
Normalizes formatting and construction. |
snippets/csharp/System.Drawing.Printing/PrintDocument/Print/source.cs |
Modernizes file-printing code. |
snippets/csharp/System.Drawing.Printing/PrintDocument/Overview/source.cs |
Applies target-typed construction. |
snippets/csharp/System.Drawing.Printing/PrintDocument/DefaultPageSettings/source.cs |
Modernizes page-setting syntax. |
snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs |
Updates initialization and fields. Nit: rename stale printDocument1_PrintPage handler. |
snippets/csharp/System.Drawing.Printing/PageSettings/Margins/source.cs |
Modernizes document and margin construction. |
snippets/csharp/System.Drawing.Printing/PageSettings/Landscape/source.cs |
Modernizes construction and comments. |
snippets/csharp/System.Drawing.Printing/PageSettings/Color/source.cs |
Modernizes collections and disposal. |
snippets/csharp/System.Drawing.Printing/Margins/Overview/source.cs |
Modernizes margin construction. |
snippets/csharp/System.Drawing.Printing/Margins/Bottom/source.cs |
Normalizes formatting. |
snippets/csharp/System.Drawing.Imaging/ImageCodecInfo/GetImageEncoders/form1.cs |
Modernizes construction. Nit: added punctuation fragments the explanatory comment. |
snippets/csharp/System.Drawing.Imaging/ImageAttributes/SetBrushRemapTable/form1.cs |
Modernizes imaging objects. Nits: three comments contain malformed sentence breaks. |
snippets/csharp/System.Drawing.Imaging/EncoderParameter/Overview/Form1.cs |
Applies target-typed construction. |
snippets/csharp/System.Drawing.Imaging/Encoder/Transformation/form1.cs |
Adds disposal and modern syntax. Nit: wrapped comment became fragmented. |
snippets/csharp/System.Drawing.Imaging/Encoder/SaveFlag/form1.cs |
Modernizes multiframe encoding. Moderate: the overwritten MultiFrame parameter is not disposed. Nit: fragmented comment. |
snippets/csharp/System.Drawing.Imaging/Encoder/Compression/form1.cs |
Modernizes TIFF compression code. Nit: wrapped comment became fragmented. |
snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs |
Modernizes color-depth encoding. Nit: wrapped comment became fragmented. |
snippets/csharp/System.Drawing.Imaging/ColorMatrix/Overview/Class1.cs |
Uses collection and object initializers. |
snippets/csharp/System.Drawing.Imaging/ColorMatrix/.ctor/Form1.cs |
Modernizes matrix and bitmap construction. |
snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs |
Modernizes gradient brushes. Nit: five target-typed constructions are incorrectly indented. |
snippets/csharp/System.Drawing.Drawing2D/Matrix/Overview/Class1.cs |
Applies target-typed construction. |
snippets/csharp/System.Drawing.Drawing2D/Matrix/Multiply/form1.cs |
Modernizes matrix examples. Nits: three wrapped comments are split into fragments. |
snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Overview/Class1.cs |
Modernizes gradients and initializers. Nits: two comments have misplaced punctuation. |
snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Clone/form1.cs |
Updates brush and matrix construction. Nits: four malformed wrapped comments, including bell- shaped. |
snippets/csharp/System.Drawing.Drawing2D/HatchBrush/Overview/Class1.cs |
Modernizes brush construction. |
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs |
Modernizes paths, arrays, and iterators. Nits: repeated comment fragmentation and six unindented constructions. |
snippets/csharp/System.Drawing.Drawing2D/FillMode/Overview/Class1.cs |
Modernizes paths and drawing objects. |
snippets/csharp/System.Drawing.Drawing2D/AdjustableArrowCap/.ctor/form1.cs |
Uses object and collection initializers. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueetext.cs |
Modernizes initialization. Nit: a sentence lost its terminating period. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrolrootdesigner.cs |
Simplifies nullable event subscription. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrol.cs |
Normalizes control syntax. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborderdesigner.cs |
Uses collection expressions. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborder.cs |
Modernizes editor initialization. Nit: a sentence lost its terminating period. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/lightshapeselectioncontrol.cs |
Normalizes formatting and control code. |
snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/imarqueewidget.cs |
Cleans comments and formatting. |
snippets/csharp/System.Drawing.Design/UITypeEditor/Overview/angleeditor.cs |
Modernizes syntax and spacing. |
snippets/csharp/System.Drawing.Design/ToolboxItemCollection/.ctor/class1.cs |
Modernizes collection construction. |
snippets/csharp/System.Drawing.Design/IToolboxService/Overview/textdatatextboxcomponent.cs |
Modernizes delegates and collections. |
snippets/csharp/System.Drawing.Design/IToolboxService/Overview/itoolboxservicecontrol.cs |
Modernizes collections. Nit: punctuation separates “controls collection” and obscures the note. |
snippets/csharp/System.Drawing.Design/IPropertyValueUIService/Overview/propertyuicomponent.cs |
Simplifies null handling and properties. |
snippets/csharp/System.Drawing.Design/CategoryNameCollection/Overview/toolboxcategorynamescontrol.cs |
Reorders imports and adjusts indentation. |
snippets/csharp/System.Drawing.Design/BitmapEditor/Overview/usercontrol1.cs |
Normalizes imports and indentation. |
Review details
Suppressed comments (22)
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:327
- The period creates “contained in. the first marker”. Keep the prepositional phrase in the same sentence.
// Retrieve and list the number of points contained in.
// the first marker to the right side of the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:363
- The new period splits “the array of points” into fragments. Keep the wrapped noun phrase intact.
// Set up variables for drawing the array.
// of points to the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:393
- The period turns “Draw the markers … to the screen” into two fragments. Preserve it as one wrapped sentence.
// Draw the Markers and their start and end points.
// to the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:449
- The inserted period produces “list the results to. the screen.” Keep the phrase together across the wrap.
// Iterate the subpaths and types, and list the results to.
// the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:573
- The new period splits the possessive phrase “the path's points” into fragments. Keep the wrapped comment as one sentence.
// Set up variables for listing all of the path's.
// points to the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:604
- The first line is now a complete sentence ending in “therein”, while the next line remains the fragment “to the screen.” Join them into one description.
// Iterate to the 3rd subpath and list the number of points therein.
// to the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:652
- The period splits “the array of points” into fragments. Keep the wrapped noun phrase intact.
// Set up variables for drawing the array of.
// points to the screen.
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:317
- The argument line is unindented at column 1, contrary to
snippets/.editorconfig:8-12. Keep this short target-typed construction on one indented line.
(myPath);
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:384
- The argument line is unindented at column 1, contrary to
snippets/.editorconfig:8-12. Keep this short target-typed construction on one indented line.
(myPath);
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:442
- The argument line is unindented at column 1, contrary to
snippets/.editorconfig:8-12. Keep this short target-typed construction on one indented line.
(myPath);
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:673
- The argument line is unindented at column 1, contrary to
snippets/.editorconfig:8-12. Keep this short target-typed construction on one indented line.
(myPath);
snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs:594
- The argument line is unindented at column 1, contrary to
snippets/.editorconfig:8-12. Keep this short target-typed construction on one indented line.
(myPath);
snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs:111
- The constructor argument starts at column 1, violating the four-space indentation required by
snippets/.editorconfig:8-12. Keep the target-typed construction on one properly indented line.
(myPathPointArray)
snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs:146
- The constructor argument starts at column 1, violating the four-space indentation required by
snippets/.editorconfig:8-12. Keep the target-typed construction on one properly indented line.
(myPathPointArray)
snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs:225
- The constructor argument starts at column 1, violating the four-space indentation required by
snippets/.editorconfig:8-12. Keep the target-typed construction on one properly indented line.
(myPathPointArray)
snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs:186
- The constructor argument starts at column 1, violating the four-space indentation required by
snippets/.editorconfig:8-12. Keep the target-typed construction on one properly indented line.
(myPathPointArray)
snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs:26
- The period after “one” leaves the following
EncoderParameterline as a fragment. Keep the wrapped sentence intact.
// objects. In this case, there is only one.
// EncoderParameter object in the array.
snippets/csharp/System.Drawing.Imaging/Encoder/Compression/form1.cs:24
- The period after “one” leaves the following
EncoderParameterline as a fragment. Keep the wrapped sentence intact.
// objects. In this case, there is only one.
// EncoderParameter object in the array.
snippets/csharp/System.Drawing.Imaging/Encoder/SaveFlag/form1.cs:26
- The period after “one” leaves the next line as the fragment “EncoderParameter object in the array.” Keep the wrapped sentence intact.
// objects. In this case, there is only one.
// EncoderParameter object in the array.
snippets/csharp/System.Drawing.Imaging/Encoder/Transformation/form1.cs:24
- The period after “one” leaves the next line as the fragment “EncoderParameter object in the array.” Keep the wrapped sentence intact.
// objects. In this case, there is only one.
// EncoderParameter object in the array.
snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs:125
- The field was renamed from
printDocument1to_printDocument, but its handler still uses the staleprintDocument1_PrintPagename. Rename the handler consistently; there are no other references in this snippet project.
snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs:32 - Renaming the field from
pdleaves the handler namedpd_PrintPage, even though nopdmember now exists. Rename the handler as well so the event source remains identifiable.
- Files reviewed: 46/47 changed files
- Comments generated: 20
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributes to #12713.
Internal previews
Toggle expand/collapse
Build report