Skip to content

Commit ec6a9f8

Browse files
Analyzer that detects that ITypedDataObject is not implemented (#12860)
* Fixes #12608
1 parent 2577e67 commit ec6a9f8

File tree

89 files changed

+2281
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2281
-380
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Whilst most .NET Core/.NET components are cross-platform Windows Forms implement
1717
Please do:
1818

1919
* **DO** follow our [coding style][coding-style] (C# code-specific)<br/>
20-
We strive to wrap the lines around 120 mark, and it's acceptable to stretch to no more than 150 chars (with some exceptions being URLs). [EditorGuidelines VS extension](https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelines) makes it easier to visualise (see https://github.com/dotnet/winforms/pull/4836).
20+
We strive to wrap the lines around 120 mark, and it's acceptable to stretch to no more than 150 chars (with some exceptions being URLs). [EditorGuidelines VS extension](https://marketplace.dev.azure.com/items?itemName=PaulHarrington.EditorGuidelines) makes it easier to visualise (see https://github.com/dotnet/winforms/pull/4836).
2121
* **DO** give priority to the current style of the project or file you're changing even if it diverges from the general guidelines.
2222
* **DO** include tests when adding new features. When fixing bugs, start with
2323
adding a test that highlights how the current behavior is broken.

Diff for: Directory.Packages.props

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
5656
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
5757
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
58+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
59+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
60+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
61+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
62+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
63+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
64+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
65+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.SourceGenerators.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
5866
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesVersion)" />
5967
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" />
6068
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisPublicApiAnalyzersVersion)" />

Diff for: Winforms.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,10 @@ Global
11871187
{C4C031D5-F79A-44B6-811E-0797E7D5C1C1} = {E4C6C5F5-46E9-4C63-9628-26752B4D9C11}
11881188
{0FD53580-3175-4F8F-8372-BE46C9122EE0} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
11891189
{B653C860-9B52-4597-9921-24DA79A4E6B1} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
1190+
{607E02DD-4256-4E73-B9A4-4CE2673B3703} = {DF68A171-D27B-4E6A-8A7E-63A651622355}
11901191
{656C66A4-59CD-4E14-8AE4-1F5BCEECB553} = {8B4B1E09-B3C7-4044-B223-94EDEC1CAA20}
11911192
{D4D97D78-D213-45DF-B003-9C4C9F2E5E1C} = {8B4B1E09-B3C7-4044-B223-94EDEC1CAA20}
11921193
{442C867C-51C0-8CE5-F067-DF065008E3DA} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7}
1193-
{607E02DD-4256-4E73-B9A4-4CE2673B3703} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
11941194
EndGlobalSection
11951195
GlobalSection(ExtensibilityGlobals) = postSolution
11961196
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}

Diff for: docs/analyzers/WinFormsCSharpAnalyzers.Help.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Windows Forms applications should specify application DPI-awareness via the [app
2222

2323
## `MissingPropertySerializationConfiguration`
2424

25-
`MissingPropertySerializationConfiguration` checks for missing `DesignerSerializationVisibilityAttribute` on properties of classes which are
25+
`MissingPropertySerializationConfiguration` checks for missing `DesignerSerializationVisibilityAttribute` on properties of classes which are
2626
derived from `Control` and could potentially serialize design-time data by the designer without the user being aware of it.
2727

2828
### [WFO1000](https://aka.ms/winforms-warnings/WFO1000): Missing property serialization configuration.
@@ -32,7 +32,23 @@ set to `DesignerSerializationVisibility.Content` or `DesignerSerializationVisibi
3232

3333
|Item|Value|
3434
|-|-|
35-
| Category | ApplicationConfiguration |
35+
| Category | WinForms Security |
36+
| Enabled | True |
37+
| Severity | Warning |
38+
| CodeFix | False |
39+
---
40+
41+
## `ImplementITypedDataObjectInAdditionToIDataObject`
42+
43+
`ImplementITypedDataObjectInAdditionToIDataObject` checks custom implementations of the managed `IDataObject` interface and suggests to also implement the `ITypedDataObject` interface.
44+
45+
### [WFO1001](https://aka.ms/winforms-warnings/WFO1001): `IDataObject` type does not implement `ITypedDataObject`.
46+
47+
Types should implement `ITypedDataObject` to support best practices when interacting with data. Types will not work with typed APIs in Clipboard and other data exchange scenarios if they only implement `IDataObject`.
48+
49+
|Item|Value|
50+
|-|-|
51+
| Category | WinForms Security |
3652
| Enabled | True |
3753
| Severity | Warning |
3854
| CodeFix | False |

Diff for: docs/developer-guide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Windows Forms requires the following workloads and components be selected when i
2424
```
2525

2626
* Useful Visual Studio extensions:
27-
* [Editor guidelines](https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelines), see https://github.com/dotnet/winforms/pull/4836 for more information
28-
* [VS Color Output](https://marketplace.visualstudio.com/items?itemName=MikeWard-AnnArbor.VSColorOutput64)
29-
* [Productivity Power Tools](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.ProductivityPowerPack2022)
27+
* [Editor guidelines](https://marketplace.dev.azure.com/items?itemName=PaulHarrington.EditorGuidelines), see https://github.com/dotnet/winforms/pull/4836 for more information
28+
* [VS Color Output](https://marketplace.dev.azure.com/items?itemName=MikeWard-AnnArbor.VSColorOutput64)
29+
* [Productivity Power Tools](https://marketplace.dev.azure.com/items?itemName=VisualStudioPlatformTeam.ProductivityPowerPack2022)
3030

3131
## Workflow
3232

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
; Unshipped analyzer release
22
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
--------|----------|----------|-------
7+
WFO1001 | WinForms Security | Warning | CSharpDiagnosticDescriptors

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/SR.resx

+10-1
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,13 @@
165165
<data name="WFO2001AnalyzerMessageFormat" xml:space="preserve">
166166
<value>Task is being passed to InvokeAsync without a cancellation token</value>
167167
</data>
168-
</root>
168+
<data name="WFO1001AnalyzerMessageFormat" xml:space="preserve">
169+
<value>Type `{0}` does not implement `ITypedDataObject` interface</value>
170+
</data>
171+
<data name="WFO1001AnalyzerTitle" xml:space="preserve">
172+
<value>`IDataObject` type does not implement `ITypedDataObject`</value>
173+
</data>
174+
<data name="WFO1001AnalyzerDescription" xml:space="preserve">
175+
<value>Types should implement `ITypedDataObject` to support best practices when interacting with data. Types will not work with typed APIs in Clipboard and other data exchange scenarios if they only implement `IDataObject`.</value>
176+
</data>
177+
</root>

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/xlf/SR.cs.xlf

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/xlf/SR.de.xlf

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/xlf/SR.es.xlf

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/xlf/SR.fr.xlf

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/System.Windows.Forms.Analyzers.CSharp/src/Resources/xlf/SR.it.xlf

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)