Skip to content

Commit

Permalink
1. method parameter attributes was not generated
Browse files Browse the repository at this point in the history
2. primary constructor properties
  • Loading branch information
beakona committed Mar 14, 2024
1 parent 148c707 commit 1d2530f
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 276 deletions.
163 changes: 56 additions & 107 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,139 +1,88 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace AutoInterfaceSample.Test
{
public class Program
{
public static void Main()
{
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_TestClass_1.Info);
//IArbitrary<int> p = new Person();
//int f;
//int g = 1;
//p.Method(1, out f, ref g, "t", 1, 2, 3);

IPrintable p = new MyPrinter();
//var c = p.Count;
//Count = 3;
p.Print();
//p.PrintComplex();
}
}

public interface IPrintable
{
public void Print();
}

public class SimplePrinter : IPrintable
{
public void Print() { Console.WriteLine("OK"); }
}

public partial class MyPrinter : IPrintable
public partial record TestRecord([property: BeaKona.AutoInterface] ILogger Logger)
{
[BeaKona.AutoInterface]
private readonly IPrintable _simplePrinter = new SimplePrinter();
}

public partial class Person2 /*: IPrintableComplex*/
{
//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Public)]
//private readonly SimplePrinter aspect1 = new SimplePrinter();

//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Explicit)]
//private readonly SimplePrinter aspect2 = new SimplePrinter();

//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true)]
//private readonly SimplePrinter aspect3 = new SimplePrinter();
//[field: BeaKona.AutoInterface]
//public ILogger Logger { get; }

//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Any)]
//private readonly SimplePrinter aspect4 = new SimplePrinter();

//void IPrintableComplex.PrintComplex() => Console.WriteLine("OKC2");

public void PrintComplex() { Console.WriteLine("Oh, K."); }
//void IPrintableComplex.PrintComplex() { Console.WriteLine("Oh, K."); }
}


public class SignalPlotXYConst<TX, TY, T> where TX : struct, IComparable
{
//[BeaKona.AutoInterface]
//private readonly ILogger logger2 = new SimpleLogger();
}

public interface ISome
public sealed class LogEventProperty<T>
{
}

public interface ISome2
[AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.GenericParameter, AllowMultiple = true)]
public class TestAttribute : Attribute
{
}

public struct Heatmap
public sealed class SimpleLogger : ILogger
{
}

public class Colormap
{
}

public interface IArbitrary<T>
{
T Length { get; }
int? Method(int a, out int b, ref int c, dynamic d, params int[] p);

SignalPlotXYConst<TXi, TYi?, T>? Method2<TXi, TYi>(TXi x, TYi[] ys, in int s) where TXi : struct, IComparable where TYi : struct, IComparable, ISome, ISome2;

Heatmap AddHeatmap(double?[,] intensities, Colormap? colormap = null, bool? lockScales = true);
Heatmap AddHeatmap(double[,] intensities, Colormap? colormap = null, bool? lockScales = null);
}

public class PrinterV1
{
public void Print()
public bool BindProperty<[Test] T>(string? propertyName, object? value, bool destructureObjects, [NotNullWhen(true)] out LogEventProperty<T>? property, [Test] params int[] values)
{
property = default;
return false;
}

public int Length => 1;

public int? Method(int a, out int b, ref int c, dynamic d, params int[] p)
[Test]
public int Count
{
b = a;
return a;
[return: Test]
[Test]
get => 1;
[return: Test]
[Test]
set
{
}
}

public SignalPlotXYConst<TXc, TYc?, int>? Method2<TXc, TYc>(TXc x, TYc[] ys, in int s) where TXc : struct, IComparable where TYc : struct, IComparable, ISome, ISome2
public int Length
{
return null;
get => 1;
set { }
}
}

public Heatmap AddHeatmap(double?[,] intensities, Colormap? colormap = null, bool? lockScales = true)
public class Program
{
public static void Main()
{
return new Heatmap();
}
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_TestClass_1.Info);

public Heatmap AddHeatmap(double[,] intensities, Colormap? colormap = null, bool? lockScales = null)
{
return new Heatmap();
ILogger p = new TestRecord(new SimpleLogger());
var result = p.BindProperty<int>("test", 1, false, out var property, 1, 2, 3);
}
}

public partial class Person
public interface ILogger
{
[BeaKona.AutoInterface(typeof(IArbitrary<int>), PreferCoalesce = true)]
//[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(IPrintable), true)]
//[BeaKona.AutoInterface(typeof(IPrintable), false)]
//[BeaKona.AutoInterface(typeof(IPrintable))]//, TemplateBody = "void TestB1() {}"
//[BeaKona.AutoInterface(typeof(IPrintable2))]//, TemplateBody = "void TestB2() {}"
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter, Filter = "Length", Language = "scriban", Body = "return 1;")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print(\\d)?", Body = "LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
private readonly PrinterV1? aspect1 = new PrinterV1();
[Test]
[return: Test]
[return: Test]
bool BindProperty<[Test] T>(string? propertyName, object? value, bool destructureObjects, [NotNullWhen(true)] out LogEventProperty<T>? property, [Test] params int[] values);

[Test]
int Count
{
[return: Test]
[Test]
get;
[return: Test]
[Test]
set;
}

//[BeaKona.AutoInterface(typeof(IPrintable), IncludeBaseInterfaces = true)]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterface(typeof(ITestable))]
//private readonly PrinterV1? aspect2 = new PrinterV1();
int Length
{
[return: Test]
get;
[return: Test]
set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ namespace BeaKona;

[Conditional("CodeGeneration")]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public sealed class AutoInterfaceTemplateAttribute : Attribute
public sealed class AutoInterfaceTemplateAttribute(AutoInterfaceTargets targets) : Attribute
{
public AutoInterfaceTemplateAttribute(AutoInterfaceTargets targets)
{
this.Targets = targets;
}

public AutoInterfaceTargets Targets { get; }
public AutoInterfaceTargets Targets { get; } = targets;
public string? Filter { get; set; }
public string? Language { get; set; }
public string? Body { get; set; }
Expand Down
33 changes: 10 additions & 23 deletions BeaKona.AutoInterfaceGenerator/AutoInterfaceRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@

namespace BeaKona.AutoInterfaceGenerator;

internal sealed class AutoInterfaceRecord : IMemberInfo
internal sealed class AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeSymbol interfaceType, TemplateDefinition? template, IEnumerable<PartialTemplate> templateParts, bool bySignature, bool preferCoalesce, bool allowMissingMembers, MemberMatchTypes memberMatch) : IMemberInfo
{
public AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeSymbol interfaceType, TemplateDefinition? template, List<PartialTemplate> templateParts, bool bySignature, bool preferCoalesce, bool allowMissingMembers, MemberMatchTypes memberMatch)
{
this.Member = member;
this.ReceiverType = receiverType;
this.InterfaceType = interfaceType;
this.Template = template;
this.TemplateParts = templateParts?.ToArray() ?? [];
this.BySignature = bySignature;
this.PreferCoalesce = preferCoalesce;
this.AllowMissingMembers = allowMissingMembers;
this.MemberMatch = memberMatch;
}

public ISymbol Member { get; }
public ITypeSymbol ReceiverType { get; }
public INamedTypeSymbol InterfaceType { get; }
public TemplateDefinition? Template { get; }
public PartialTemplate[] TemplateParts { get; }
public bool BySignature { get; }
public bool PreferCoalesce { get; }
public bool AllowMissingMembers { get; }
public MemberMatchTypes MemberMatch { get; }
public ISymbol Member { get; } = member;
public ITypeSymbol ReceiverType { get; } = receiverType;
public INamedTypeSymbol InterfaceType { get; } = interfaceType;
public TemplateDefinition? Template { get; } = template;
public PartialTemplate[] TemplateParts { get; } = templateParts?.ToArray() ?? [];
public bool BySignature { get; } = bySignature;
public bool PreferCoalesce { get; } = preferCoalesce;
public bool AllowMissingMembers { get; } = allowMissingMembers;
public MemberMatchTypes MemberMatch { get; } = memberMatch;
}
Loading

0 comments on commit 1d2530f

Please sign in to comment.