Skip to content

Commit 06595ae

Browse files
committed
Added debugging attributes to validator/messaging generated classes
1 parent 7d87d87 commit 06595ae

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/ObservableValidatorValidateAllPropertiesGenerator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public void Execute(GeneratorExecutionContext context)
4545
// Prepare the attributes to add to the first class declaration
4646
AttributeListSyntax[] classAttributes = new[]
4747
{
48+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
49+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))),
4850
AttributeList(SingletonSeparatedList(
4951
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
5052
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
@@ -68,9 +70,13 @@ public void Execute(GeneratorExecutionContext context)
6870
//
6971
// using System;
7072
// using System.ComponentModel;
73+
// using System.Diagnostics;
74+
// using System.Diagnostics.CodeAnalysis;
7175
//
7276
// namespace Microsoft.Toolkit.Mvvm.ComponentModel.__Internals
7377
// {
78+
// [DebuggerNonUserCode]
79+
// [ExcludeFromCodeCoverage]
7480
// [EditorBrowsable(EditorBrowsableState.Never)]
7581
// [Obsolete("This type is not intended to be used directly by user code")]
7682
// internal static partial class __ObservableValidatorExtensions
@@ -90,7 +96,9 @@ public void Execute(GeneratorExecutionContext context)
9096
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
9197
Comment("// See the LICENSE file in the project root for more information."),
9298
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))),
93-
UsingDirective(IdentifierName("System.ComponentModel"))).AddMembers(
99+
UsingDirective(IdentifierName("System.ComponentModel")),
100+
UsingDirective(IdentifierName("System.Diagnostics")),
101+
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis"))).AddMembers(
94102
NamespaceDeclaration(IdentifierName("Microsoft.Toolkit.Mvvm.ComponentModel.__Internals")).AddMembers(
95103
ClassDeclaration("__ObservableValidatorExtensions").AddModifiers(
96104
Token(SyntaxKind.InternalKeyword),

Microsoft.Toolkit.Mvvm.SourceGenerators/Messaging/IMessengerRegisterAllGenerator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public void Execute(GeneratorExecutionContext context)
4444
// Prepare the attributes to add to the first class declaration
4545
AttributeListSyntax[] classAttributes = new[]
4646
{
47+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
48+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))),
4749
AttributeList(SingletonSeparatedList(
4850
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
4951
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
@@ -70,9 +72,13 @@ public void Execute(GeneratorExecutionContext context)
7072
//
7173
// using System;
7274
// using System.ComponentModel;
75+
// using System.Diagnostics;
76+
// using System.Diagnostics.CodeAnalysis;
7377
//
7478
// namespace Microsoft.Toolkit.Mvvm.Messaging.__Internals
7579
// {
80+
// [DebuggerNonUserCode]
81+
// [ExcludeFromCodeCoverage]
7682
// [EditorBrowsable(EditorBrowsableState.Never)]
7783
// [Obsolete("This type is not intended to be used directly by user code")]
7884
// internal static partial class __IMessengerExtensions
@@ -100,7 +106,9 @@ public void Execute(GeneratorExecutionContext context)
100106
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
101107
Comment("// See the LICENSE file in the project root for more information."),
102108
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))),
103-
UsingDirective(IdentifierName("System.ComponentModel"))).AddMembers(
109+
UsingDirective(IdentifierName("System.ComponentModel")),
110+
UsingDirective(IdentifierName("System.Diagnostics")),
111+
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis"))).AddMembers(
104112
NamespaceDeclaration(IdentifierName("Microsoft.Toolkit.Mvvm.Messaging.__Internals")).AddMembers(
105113
ClassDeclaration("__IMessengerExtensions").AddModifiers(
106114
Token(SyntaxKind.InternalKeyword),

0 commit comments

Comments
 (0)