Skip to content

Commit 239a27b

Browse files
committed
Another test
1 parent dfb2c31 commit 239a27b

File tree

73 files changed

+3377
-93
lines changed

Some content is hidden

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

73 files changed

+3377
-93
lines changed

samples/Samples/Samples.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\..\src\PublicInterfaceGenerator\PublicInterfaceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
11-
<ProjectReference Include="..\..\src\PublicInterfaceGenerator.Attributes\PublicInterfaceGenerator.Attributes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
10+
<ProjectReference Include="..\..\src\PublicInterfaceGenerator\PublicInterfaceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
11+
<!--<ProjectReference Include="..\..\src\PublicInterfaceGenerator.Attributes\PublicInterfaceGenerator.Attributes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />-->
1212
</ItemGroup>
1313
</Project>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
1+
//namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
22

3-
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
4-
public class ExcludeFromGeneratedInterfaceAttribute : Attribute
5-
{
6-
}
3+
//[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
4+
//public class ExcludeFromGeneratedInterfaceAttribute : Attribute
5+
//{
6+
//}
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
6-
7-
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
8-
public class GenerateInterfaceAttribute : Attribute
9-
{
10-
/// <summary>
11-
/// Set this to override the default interface name. Or leave it null to use the class name with an 'I' prepended to it.
12-
/// </summary>
13-
public string? InterfaceName { get; set; }
14-
15-
/// <summary>
16-
/// Set this to override the namespace to generate the interface in. By default, it will be the same as the class.
17-
/// </summary>
18-
public string? Namespace { get; set; }
19-
20-
/// <summary>
21-
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
22-
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
23-
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
24-
/// </summary>
25-
public string? Interfaces { get; set; }
26-
27-
/// <summary>
28-
/// Set this to specify the generated interface inherits from System.IDisposable.
29-
/// This will be appended to the list of interfaces the generated interface inherits from.
30-
/// This is in addition to the <see cref="Interfaces"/> property.
31-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
32-
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
33-
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
34-
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
35-
/// </summary>
36-
public bool IsIDisposable { get; set; }
37-
38-
/// <summary>
39-
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
40-
/// This is in addition to the <see cref="Interfaces"/> property.
41-
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
42-
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
43-
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
44-
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
45-
/// </summary>
46-
public bool IsIAsyncDisposable { get; set; }
47-
48-
public static class Constants
49-
{
50-
public const string GenerateInterfaceAttributeName = nameof(GenerateInterfaceAttribute);
51-
public static string GenerateInterfaceAttributeNameSpace = typeof(GenerateInterfaceAttribute).Namespace;
52-
public static string GenerateInterfaceAttributeFullName = typeof(GenerateInterfaceAttribute).FullName;
53-
54-
public const string ExcludeFromGeneratedInterfaceAttributeName = "ExcludeFromGeneratedInterfaceAttribute";
55-
56-
public const string AttributeProperty_InterfaceName = nameof(InterfaceName);
57-
public const string AttributeProperty_NamespaceName = nameof(Namespace);
58-
public const string AttributeProperty_Interfaces = nameof(Interfaces);
59-
public const string AttributeProperty_IsIDisposable = nameof(IsIDisposable);
60-
public const string AttributeProperty_IsIAsyncDisposable = nameof(IsIAsyncDisposable);
61-
}
62-
}
1+
//using System;
2+
//using System.Collections.Generic;
3+
//using System.Text;
4+
5+
//namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
6+
7+
//[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
8+
//public class GenerateInterfaceAttribute : Attribute
9+
//{
10+
// /// <summary>
11+
// /// Set this to override the default interface name. Or leave it null to use the class name with an 'I' prepended to it.
12+
// /// </summary>
13+
// public string? InterfaceName { get; set; }
14+
15+
// /// <summary>
16+
// /// Set this to override the namespace to generate the interface in. By default, it will be the same as the class.
17+
// /// </summary>
18+
// public string? Namespace { get; set; }
19+
20+
// /// <summary>
21+
// /// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
22+
// /// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
23+
// /// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
24+
// /// </summary>
25+
// public string? Interfaces { get; set; }
26+
27+
// /// <summary>
28+
// /// Set this to specify the generated interface inherits from System.IDisposable.
29+
// /// This will be appended to the list of interfaces the generated interface inherits from.
30+
// /// This is in addition to the <see cref="Interfaces"/> property.
31+
// /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
32+
// /// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
33+
// /// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
34+
// /// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
35+
// /// </summary>
36+
// public bool IsIDisposable { get; set; }
37+
38+
// /// <summary>
39+
// /// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
40+
// /// This is in addition to the <see cref="Interfaces"/> property.
41+
// /// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
42+
// /// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
43+
// /// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
44+
// /// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
45+
// /// </summary>
46+
// public bool IsIAsyncDisposable { get; set; }
47+
//}
48+
49+
//public static class Constants
50+
//{
51+
// public const string GenerateInterfaceAttributeName = nameof(GenerateInterfaceAttribute);
52+
// public static string GenerateInterfaceAttributeNameSpace = typeof(GenerateInterfaceAttribute).Namespace;
53+
// public static string GenerateInterfaceAttributeFullName = typeof(GenerateInterfaceAttribute).FullName;
54+
55+
// public const string ExcludeFromGeneratedInterfaceAttributeName = "ExcludeFromGeneratedInterfaceAttribute";
56+
57+
// public const string AttributeProperty_InterfaceName = nameof(InterfaceName);
58+
// public const string AttributeProperty_NamespaceName = nameof(Namespace);
59+
// public const string AttributeProperty_Interfaces = nameof(Interfaces);
60+
// public const string AttributeProperty_IsIDisposable = nameof(IsIDisposable);
61+
// public const string AttributeProperty_IsIAsyncDisposable = nameof(IsIAsyncDisposable);
62+
//}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator;
6+
public class AttributeGenerationHelper
7+
{
8+
public static string GenerateAttributesCode()
9+
{
10+
var builder = new StringBuilder();
11+
12+
_ = builder.AppendLine(GenerateEmbeddedAttribute());
13+
_ = builder.AppendLine();
14+
_ = builder.AppendLine(GenerateExcludeFromGeneratedInterfaceAttribute());
15+
_ = builder.AppendLine();
16+
_ = builder.AppendLine(GenerateGenerateInterfaceAttribute());
17+
18+
return builder.ToString();
19+
}
20+
21+
public static string GenerateEmbeddedAttribute()
22+
{
23+
return
24+
"""
25+
namespace Microsoft.CodeAnalysis
26+
{
27+
internal sealed class EmbeddedAttribute : System.Attribute {}
28+
}
29+
""";
30+
}
31+
32+
public static string GenerateExcludeFromGeneratedInterfaceAttribute()
33+
{
34+
return
35+
"""
36+
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
37+
{
38+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
39+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
40+
public class ExcludeFromGeneratedInterfaceAttribute : Attribute
41+
{
42+
}
43+
}
44+
""";
45+
}
46+
47+
public static string GenerateGenerateInterfaceAttribute()
48+
{
49+
return """
50+
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes
51+
{
52+
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
53+
[Microsoft.CodeAnalysis.EmbeddedAttribute]
54+
public class GenerateInterfaceAttribute : Attribute
55+
{
56+
/// <summary>
57+
/// Set this to override the default interface name. Or leave it null to use the class name with an 'I' prepended to it.
58+
/// </summary>
59+
public string? InterfaceName { get; set; }
60+
61+
/// <summary>
62+
/// Set this to override the namespace to generate the interface in. By default, it will be the same as the class.
63+
/// </summary>
64+
public string? Namespace { get; set; }
65+
66+
/// <summary>
67+
/// Set this to specify the interfaces the generated interface will inherit from. For example, IDisposable.
68+
/// This should be a syntax-valid list as you would type it out normally because it will be concatenated directly into the interface definition.
69+
/// For example: ""MyNamespace.MyInterface1, MyNamespace.MyInterface2""
70+
/// </summary>
71+
public string? Interfaces { get; set; }
72+
73+
/// <summary>
74+
/// Set this to specify the generated interface inherits from System.IDisposable.
75+
/// This will be appended to the list of interfaces the generated interface inherits from.
76+
/// This is in addition to the <see cref="Interfaces"/> property.
77+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
78+
/// either set this to false and include "System.IDisposable" in the <see cref="Interfaces"/> property string,
79+
/// or set this to true and don't include "System.IDisposable" in the <see cref="Interfaces"/> string.
80+
/// Failure to do this will result in System.IDisposable being appended to the generated interface twice.
81+
/// </summary>
82+
public bool IsIDisposable { get; set; }
83+
84+
/// <summary>
85+
/// Set this to specify the generated interface inherits from <see cref="System.IAsyncDisposable"/>.
86+
/// This is in addition to the <see cref="Interfaces"/> property.
87+
/// If you are also specifying interfaces with the <see cref="Interfaces"/> property,
88+
/// either set this to false and include "System.IAsyncDisposable" in the <see cref="Interfaces"/> property string,
89+
/// or set this to true and don't include "System.IAsyncDisposable" in the <see cref="Interfaces"/> string.
90+
/// Failure to do this will result in System.IAsyncDisposable being appended to the generated interface twice.
91+
/// </summary>
92+
public bool IsIAsyncDisposable { get; set; }
93+
}
94+
}
95+
""";
96+
}
97+
98+
public static class GenerateInterfaceAttributeConstants
99+
{
100+
public const string GenerateInterfaceAttributeName = "GenerateInterfaceAttribute";
101+
public static string GenerateInterfaceAttributeNameSpace = "ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes";
102+
public static string GenerateInterfaceAttributeFullName = $"{GenerateInterfaceAttributeNameSpace}.{GenerateInterfaceAttributeName}";
103+
104+
public const string ExcludeFromGeneratedInterfaceAttributeName = "ExcludeFromGeneratedInterfaceAttribute";
105+
106+
public const string AttributeProperty_InterfaceName = "InterfaceName";
107+
public const string AttributeProperty_NamespaceName = "Namespace";
108+
public const string AttributeProperty_Interfaces = "Interfaces";
109+
public const string AttributeProperty_IsIDisposable = "IsIDisposable";
110+
public const string AttributeProperty_IsIAsyncDisposable = "IsIAsyncDisposable";
111+
}
112+
}

src/PublicInterfaceGenerator/GeneratorParsers/ClassParser.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
using Microsoft.CodeAnalysis;
77

8-
using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
9-
108
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.GeneratorParsers;
119

1210
public static class ClassParser
@@ -32,38 +30,38 @@ public static class ClassParser
3230
{
3331
var attributeClassName = attributeData.AttributeClass?.Name;
3432
if (string.IsNullOrWhiteSpace(attributeClassName)
35-
|| attributeClassName != GenerateInterfaceAttribute.Constants.GenerateInterfaceAttributeName
36-
|| attributeData.AttributeClass!.ToDisplayString() != GenerateInterfaceAttribute.Constants.GenerateInterfaceAttributeFullName)
33+
|| attributeClassName != AttributeGenerationHelper.GenerateInterfaceAttributeConstants.GenerateInterfaceAttributeName
34+
|| attributeData.AttributeClass!.ToDisplayString() != AttributeGenerationHelper.GenerateInterfaceAttributeConstants.GenerateInterfaceAttributeFullName)
3735
{
3836
continue;
3937
}
4038

4139
foreach (KeyValuePair<string, TypedConstant> namedArgument in attributeData.NamedArguments)
4240
{
43-
if (namedArgument.Key == GenerateInterfaceAttribute.Constants.AttributeProperty_InterfaceName
41+
if (namedArgument.Key == AttributeGenerationHelper.GenerateInterfaceAttributeConstants.AttributeProperty_InterfaceName
4442
&& namedArgument.Value.Value?.ToString() is { } infName)
4543
{
4644
interfaceName = infName;
4745
}
48-
else if (namedArgument.Key == GenerateInterfaceAttribute.Constants.AttributeProperty_NamespaceName
46+
else if (namedArgument.Key == AttributeGenerationHelper.GenerateInterfaceAttributeConstants.AttributeProperty_NamespaceName
4947
&& namedArgument.Value.Value?.ToString() is { } nsName)
5048
{
5149
namespaceName = nsName;
5250
}
53-
else if (namedArgument.Key == GenerateInterfaceAttribute.Constants.AttributeProperty_Interfaces
51+
else if (namedArgument.Key == AttributeGenerationHelper.GenerateInterfaceAttributeConstants.AttributeProperty_Interfaces
5452
&& namedArgument.Value.Value?.ToString() is { } interfaces)
5553
{
5654
interfacesNames = interfaces;
5755
}
58-
else if (namedArgument.Key == GenerateInterfaceAttribute.Constants.AttributeProperty_IsIDisposable
56+
else if (namedArgument.Key == AttributeGenerationHelper.GenerateInterfaceAttributeConstants.AttributeProperty_IsIDisposable
5957
&& namedArgument.Value.Value?.ToString() is { } isIDisposable)
6058
{
6159
if (bool.TryParse(isIDisposable, out bool parsedIsIDisposable))
6260
{
6361
inheritsFromIDisposable = parsedIsIDisposable;
6462
}
6563
}
66-
else if (namedArgument.Key == GenerateInterfaceAttribute.Constants.AttributeProperty_IsIAsyncDisposable
64+
else if (namedArgument.Key == AttributeGenerationHelper.GenerateInterfaceAttributeConstants.AttributeProperty_IsIAsyncDisposable
6765
&& namedArgument.Value.Value?.ToString() is { } isIAsyncDisposable)
6866
{
6967
if (bool.TryParse(isIAsyncDisposable, out bool parsedIsIAsyncDisposable))

src/PublicInterfaceGenerator/GeneratorParsers/EventParser.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
using Microsoft.CodeAnalysis;
77

8-
using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
9-
108
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.GeneratorParsers;
119

1210
public static class EventParser
@@ -37,7 +35,7 @@ private static bool IsSymbolValid(IEventSymbol symbol)
3735
//Only public
3836
return false;
3937
}
40-
else if (symbol.GetAttributes().Any(x => x.AttributeClass?.Name is GenerateInterfaceAttribute.Constants.ExcludeFromGeneratedInterfaceAttributeName))
38+
else if (symbol.GetAttributes().Any(x => x.AttributeClass?.Name is AttributeGenerationHelper.GenerateInterfaceAttributeConstants.ExcludeFromGeneratedInterfaceAttributeName))
4139
{
4240
//Don't include methods that have the [IgnoreInGeneratedInterface] attribute
4341
return false;

src/PublicInterfaceGenerator/GeneratorParsers/MethodParser.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
using Microsoft.CodeAnalysis;
66

7-
using ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.Attributes;
8-
97
namespace ProgrammerAl.SourceGenerators.PublicInterfaceGenerator.GeneratorParsers;
108

119
public static class MethodParser
@@ -103,7 +101,7 @@ private static bool IsSymbolValid(
103101
// Don't include those here because events are handled separately
104102
return false;
105103
}
106-
else if (symbol.GetAttributes().Any(x => x.AttributeClass?.Name is GenerateInterfaceAttribute.Constants.ExcludeFromGeneratedInterfaceAttributeName))
104+
else if (symbol.GetAttributes().Any(x => x.AttributeClass?.Name is AttributeGenerationHelper.GenerateInterfaceAttributeConstants.ExcludeFromGeneratedInterfaceAttributeName))
107105
{
108106
//Don't include methods that have the [IgnoreInGeneratedInterface] attribute
109107
return false;

0 commit comments

Comments
 (0)