@@ -12,12 +12,16 @@ public static string GenerateAttributesCode()
12
12
_ = builder . AppendLine ( $ "#nullable enable") ;
13
13
_ = builder . AppendLine ( GenerateAttributionsSuppressComments ( ) ) ;
14
14
15
- _ = builder . AppendLine ( GenerateEmbeddedAttribute ( ) ) ;
15
+ //Another line to separate code from rules
16
16
_ = builder . AppendLine ( ) ;
17
- _ = builder . AppendLine ( GenerateExcludeFromGeneratedInterfaceAttribute ( ) ) ;
17
+
18
+ _ = builder . AppendLine ( GenerateEmbeddedAttribute ( ) ) ;
18
19
_ = builder . AppendLine ( ) ;
19
- _ = builder . AppendLine ( GenerateGenerateInterfaceAttribute ( ) ) ;
20
+ _ = builder . AppendLine ( GenerateInterfaceAttributes ( ) ) ;
20
21
22
+ //Another line to separate code from rules
23
+ _ = builder . AppendLine ( ) ;
24
+
21
25
_ = builder . Append ( GenerateAttributionsSuppressionRestoreComments ( ) ) ;
22
26
23
27
return builder . ToString ( ) ;
@@ -41,63 +45,57 @@ internal sealed class EmbeddedAttribute : System.Attribute {}
41
45
""" ;
42
46
}
43
47
44
- public static string GenerateExcludeFromGeneratedInterfaceAttribute ( )
48
+ public static string GenerateInterfaceAttributes ( )
45
49
{
46
50
return
47
51
"""
48
52
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
49
53
{
50
54
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
51
- [Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
55
+ [Microsoft.CodeAnalysis.EmbeddedAttribute]
56
+ [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
52
57
public sealed class ExcludeFromGeneratedInterfaceAttribute : System.Attribute
53
58
{
54
59
}
55
- }
56
- """ ;
57
- }
58
60
59
- public static string GenerateGenerateInterfaceAttribute ( )
60
- {
61
- return """
62
- namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
63
- {
64
61
[System.AttributeUsage(System.AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
65
- [Microsoft.CodeAnalysis.EmbeddedAttribute, System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
62
+ [Microsoft.CodeAnalysis.EmbeddedAttribute]
63
+ [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute]
66
64
public sealed class GenerateInterfaceAttribute : System.Attribute
67
65
{
68
66
/// <summary>
69
67
/// Set this to override the default interface name. Or leave it null to use the class name with an 'I' prepended to it.
70
68
/// </summary>
71
69
public string? InterfaceName { get; set; }
72
-
70
+
73
71
/// <summary>
74
72
/// Set this to override the namespace to generate the interface in. By default, it will be the same as the class.
75
73
/// </summary>
76
74
public string? Namespace { get; set; }
77
-
75
+
78
76
/// <summary>
79
- /// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
77
+ /// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
80
78
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
81
79
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
82
80
/// </summary>
83
81
public string? Interfaces { get; set; }
84
-
82
+
85
83
/// <summary>
86
84
/// Set this to specify the generated interface inherits from System.IDisposable.
87
85
/// This will be appended to the list of interfaces the generated interface inherits from.
88
86
/// This is in addition to the <see cref="Interfaces"/> property.
89
- /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
90
- /// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
87
+ /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
88
+ /// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
91
89
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
92
90
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
93
91
/// </summary>
94
92
public bool IsIDisposable { get; set; }
95
-
93
+
96
94
/// <summary>
97
95
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
98
96
/// This is in addition to the <see cref="Interfaces"/> property.
99
- /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
100
- /// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
97
+ /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
98
+ /// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
101
99
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
102
100
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
103
101
/// </summary>
@@ -112,9 +110,9 @@ private static string GenerateAttributionsSuppressComments()
112
110
return """
113
111
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
114
112
#pragma warning disable SA1402 // FileMayOnlyContainASingleType
113
+ #pragma warning disable SA1403 // SA1403FileMayOnlyContainASingleNamespace
115
114
#pragma warning disable SA1502 // ElementMustNotBeOnSingleLine
116
- #pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
117
-
115
+ #pragma warning disable SA1013 // ClosingBracesMustBeSpacedCorrectly
118
116
""" ;
119
117
}
120
118
@@ -123,6 +121,7 @@ private static string GenerateAttributionsSuppressionRestoreComments()
123
121
return """
124
122
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
125
123
#pragma warning restore SA1402 // FileMayOnlyContainASingleType
124
+ #pragma warning restore SA1403 // SA1403FileMayOnlyContainASingleNamespace
126
125
#pragma warning restore SA1502 // ElementMustNotBeOnSingleLine
127
126
#pragma warning restore SA1013 // ClosingBracesMustBeSpacedCorrectly
128
127
""" ;
0 commit comments