diff --git a/AutoInterfaceSample/Program.cs b/AutoInterfaceSample/Program.cs index 8df6d2c..2fe5b57 100644 --- a/AutoInterfaceSample/Program.cs +++ b/AutoInterfaceSample/Program.cs @@ -17,58 +17,83 @@ public interface IPrintable2 } } -namespace AutoInterfaceSample +namespace AutoInterfaceSample.Test.TT { - public class Program + namespace T2 { - public static void Main() + public interface ITest2 { - //System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info); - IPrintable p = new Person(); - p.Print1(); + void Play(); } } - public class PrinterV1 : IPrintable, X.C.D.E.F.G.IPrintable2 + namespace T3 { - public int Length => 100; - public int Count => 200; - public void Print1() + public interface ITest2 { + void Play(); } - public void Print2() - { - } - public void Print3() - { - } - public void PrintTest() - { - } - } - public partial class Person //: IPrintable//, IPrintable2 - { - private void LogDebug(string name) + namespace T4.T5 { - } + public class Program + { + public static void Main() + { + //System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info); + IPrintable p = new Person(); + p.Print1(); + } + } - //[BeaKona.AutoInterface] - [BeaKona.AutoInterface(typeof(ITestable))] - //[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 IPrintable? aspect1 = new PrinterV1(); + public class PrinterV1 : IPrintable, X.C.D.E.F.G.IPrintable2, T2.ITest2 + { + public int Length => 100; + public int Count => 200; + public void Print1() + { + } + public void Print2() + { + } + public void Print3() + { + } + public void PrintTest() + { + } + public void Play() + { + } + } - [BeaKona.AutoInterface(typeof(IPrintable), IncludeBaseInterfaces = false)] - [BeaKona.AutoInterface(typeof(X.C.D.E.F.G.IPrintable2))] - //[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(); + public partial class Person //: IPrintable//, IPrintable2 + { + private void LogDebug(string name) + { + } + + //[BeaKona.AutoInterface] + [BeaKona.AutoInterface(typeof(ITestable))] + //[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 IPrintable? aspect1 = new PrinterV1(); + + [BeaKona.AutoInterface(typeof(IPrintable), IncludeBaseInterfaces = false)] + [BeaKona.AutoInterface(typeof(X.C.D.E.F.G.IPrintable2))] + //[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(); + + [BeaKona.AutoInterface(typeof(T2.ITest2))] + private readonly T2.ITest2? aspect3 = new PrinterV1(); + } + } } } diff --git a/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs b/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs index 6f5a363..d13858f 100644 --- a/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs +++ b/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs @@ -716,13 +716,22 @@ public void WriteNamespaceBeginning(SourceBuilder builder, INamespaceSymbol @nam { if (@namespace != null && @namespace.ConstituentNamespaces.Length > 0) { - builder.AppendIndentation(); - builder.Append("namespace"); - builder.Append(' '); - builder.AppendLine(GetSourceIdentifier(@namespace)); - builder.AppendIndentation(); - builder.AppendLine('{'); - builder.IncrementIndentation(); + List containingNamespaces = new(); + for (INamespaceSymbol? ct = @namespace; ct != null && ct.IsGlobalNamespace == false; ct = ct.ContainingNamespace) + { + containingNamespaces.Insert(0, ct); + } + + if (containingNamespaces.Count > 0) + { + builder.AppendIndentation(); + builder.Append("namespace"); + builder.Append(' '); + builder.AppendLine(string.Join(".", containingNamespaces.Select(i => GetSourceIdentifier(i)))); + builder.AppendIndentation(); + builder.AppendLine('{'); + builder.IncrementIndentation(); + } } }