Skip to content

Commit

Permalink
AutoInterfaceAttribute have named attribute IncludeBaseInterfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Jul 27, 2021
1 parent 578ae64 commit 45d899c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
6 changes: 3 additions & 3 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ private void LogDebug(string name)
{
}

[BeaKona.AutoInterface]
//[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface]
[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(IPrintable), true)]
//[BeaKona.AutoInterface(typeof(IPrintable), false)]
Expand All @@ -63,7 +63,7 @@ private void LogDebug(string name)
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print(\\d)?", Body = "LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
private readonly IPrintable<int>? aspect1 = new PrinterV1();

[BeaKona.AutoInterface(typeof(IPrintable<int>), true)]
[BeaKona.AutoInterface(typeof(IPrintable<int>), IncludeBaseInterfaces = false)]
[BeaKona.AutoInterface(typeof(IPrintable2))]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
Expand Down
25 changes: 9 additions & 16 deletions BeaKona.AutoInterfaceGenerator/AutoInterfaceSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,27 +336,12 @@ private static List<AutoInterfaceRecord> CollectRecords(GeneratorExecutionContex
{
type = receiverType.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
}
else if (attribute.ConstructorArguments.Length == 1)
{
if (attribute.ConstructorArguments[0].Value is ITypeSymbol targetType)
{
type = targetType;
}
else if (attribute.ConstructorArguments[0].Value is bool includeBaseInterfaces2)
{
includeBaseInterfaces = includeBaseInterfaces2;
}
}
else
{
if (attribute.ConstructorArguments[0].Value is ITypeSymbol targetType)
{
type = targetType;
}
if (attribute.ConstructorArguments[1].Value is bool includeBaseInterfaces2)
{
includeBaseInterfaces = includeBaseInterfaces2;
}
}

if (type == null)
Expand All @@ -374,7 +359,7 @@ private static List<AutoInterfaceRecord> CollectRecords(GeneratorExecutionContex
string? templateFileName = null;
string? templateLanguage = null;

#region collect named arguments [only one argument for now]
#region collect named arguments

foreach (KeyValuePair<string, TypedConstant> arg in attribute.NamedArguments)
{
Expand Down Expand Up @@ -404,6 +389,14 @@ private static List<AutoInterfaceRecord> CollectRecords(GeneratorExecutionContex
}
}
break;
case "IncludeBaseInterfaces":
{
if (arg.Value.Value is bool b)
{
includeBaseInterfaces = b;
}
}
break;
}
}

Expand Down
13 changes: 1 addition & 12 deletions BeaKona.AutoInterfaceGenerator/InjectedCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ public AutoInterfaceAttribute()
{
}

public AutoInterfaceAttribute(bool includeBaseInterfaces)
{
this.IncludeBaseInterfaces = includeBaseInterfaces;
}

public AutoInterfaceAttribute(Type type)
{
this.Type = type;
}

public AutoInterfaceAttribute(Type type, bool includeBaseInterfaces)
{
this.Type = type;
this.IncludeBaseInterfaces = includeBaseInterfaces;
}

public Type? Type { get; }
public bool IncludeBaseInterfaces { get; }
public bool IncludeBaseInterfaces { get; set; }
public string? TemplateLanguage { get; set; }
public string? TemplateBody { get; set; }
public string? TemplateFileName { get; set; }
Expand Down

0 comments on commit 45d899c

Please sign in to comment.