Skip to content

Commit 2611dd2

Browse files
committed
case where namespace is not generated properly
1 parent fb4e57a commit 2611dd2

3 files changed

Lines changed: 40 additions & 24 deletions

File tree

AutoInterfaceSample/Program.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
using TestInterfaces;
1+
//using TestInterfaces.A.B;
2+
3+
namespace X.C
4+
{
5+
namespace D
6+
{
7+
namespace E.F
8+
{
9+
namespace G
10+
{
11+
public interface IPrintable2
12+
{
13+
void Print3();
14+
}
15+
}
16+
}
17+
}
18+
}
219

320
namespace AutoInterfaceSample
421
{
@@ -7,12 +24,12 @@ public class Program
724
public static void Main()
825
{
926
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info);
10-
IPrintable<int> p = new Person();
27+
TestInterfaces.A.B.IPrintable<int> p = new Person();
1128
p.Print1();
1229
}
1330
}
1431

15-
public class PrinterV1 : IPrintable<int>, IPrintable2
32+
public class PrinterV1 : TestInterfaces.A.B.IPrintable<int>, X.C.D.E.F.G.IPrintable2
1633
{
1734
public int Length => 100;
1835
public int Count => 200;
@@ -37,18 +54,18 @@ private void LogDebug(string name)
3754
}
3855

3956
//[BeaKona.AutoInterface]
40-
[BeaKona.AutoInterface(typeof(ITestable))]
57+
[BeaKona.AutoInterface(typeof(TestInterfaces.A.B.ITestable))]
4158
//[BeaKona.AutoInterface(typeof(ITestable))]
4259
//[BeaKona.AutoInterface(typeof(IPrintable), true)]
4360
//[BeaKona.AutoInterface(typeof(IPrintable), false)]
4461
//[BeaKona.AutoInterface(typeof(IPrintable))]//, TemplateBody = "void TestB1() {}"
4562
//[BeaKona.AutoInterface(typeof(IPrintable2))]//, TemplateBody = "void TestB2() {}"
4663
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter, Filter = "Length", Language = "scriban", Body = "return 1;")]
4764
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print(\\d)?", Body = "LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
48-
private readonly IPrintable<int>? aspect1 = new PrinterV1();
65+
private readonly TestInterfaces.A.B.IPrintable<int>? aspect1 = new PrinterV1();
4966

50-
[BeaKona.AutoInterface(typeof(IPrintable<int>), IncludeBaseInterfaces = false)]
51-
[BeaKona.AutoInterface(typeof(IPrintable2))]
67+
[BeaKona.AutoInterface(typeof(TestInterfaces.A.B.IPrintable<int>), IncludeBaseInterfaces = false)]
68+
[BeaKona.AutoInterface(typeof(X.C.D.E.F.G.IPrintable2))]
5269
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
5370
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
5471
//[BeaKona.AutoInterface(typeof(ITestable))]

BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8-
using System.Text;
98

109
namespace BeaKona.AutoInterfaceGenerator
1110
{
@@ -445,14 +444,14 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
445444
{
446445
IMemberInfo reference = references.First();
447446

448-
if (property.GetMethod is IMethodSymbol)
447+
if (property.GetMethod is not null)
449448
{
450449
builder.AppendIndentation();
451450
builder.Append("get => ");
452451
this.WritePropertyCall(builder, reference, property, scope, SemanticFacts.IsNullable(this.Compilation, property.Type), true);
453452
builder.AppendLine(';');
454453
}
455-
if (property.SetMethod is IMethodSymbol)
454+
if (property.SetMethod is not null)
456455
{
457456
builder.AppendIndentation();
458457
builder.Append("set => ");
@@ -462,7 +461,7 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
462461
}
463462
else
464463
{
465-
if (property.GetMethod is IMethodSymbol)
464+
if (property.GetMethod is not null)
466465
{
467466
builder.AppendIndentation();
468467
if (getterTemplate != null)
@@ -503,7 +502,7 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
503502
builder.AppendLine(';');
504503
}
505504
}
506-
if (property.SetMethod is IMethodSymbol)
505+
if (property.SetMethod is not null)
507506
{
508507
builder.AppendIndentation();
509508
builder.AppendLine("set");
@@ -872,6 +871,16 @@ private string GetSourceIdentifier(ISymbol symbol)
872871
{
873872
return "this";
874873
}
874+
else if (symbol is INamespaceSymbol ns)
875+
{
876+
return ns.Name;
877+
//return string.Join("+", ns.ConstituentNamespaces.Select(i => i.Name));
878+
//return $"<{@namespace.Name};{symbol}>" + this.GetSourceIdentifier(@namespace.Name);
879+
}
880+
else if (symbol.DeclaringSyntaxReferences.Length == 0)
881+
{
882+
return symbol.Name;
883+
}
875884
else
876885
{
877886
foreach (SyntaxReference syntaxReference in symbol.DeclaringSyntaxReferences)
@@ -941,19 +950,14 @@ private string GetSourceIdentifier(ISymbol symbol)
941950
}
942951
else if (syntax is NamespaceDeclarationSyntax @namespace)
943952
{
944-
return this.GetSourceIdentifier(@namespace.Name);
953+
throw new NotSupportedException(syntax.GetType().ToString());
945954
}
946955
else
947956
{
948957
throw new NotSupportedException(syntax.GetType().ToString());
949958
}
950959
}
951960

952-
if (symbol.DeclaringSyntaxReferences.Length == 0)
953-
{
954-
return symbol.Name;
955-
}
956-
957961
throw new NotSupportedException();
958962
}
959963
}

TestInterfaces/Interfaces.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace TestInterfaces
3+
namespace TestInterfaces.A.B
44
{
55
public interface ITestable
66
{
@@ -14,9 +14,4 @@ public interface IPrintable<T> : ITestable
1414
void Print1();
1515
void Print2();
1616
}
17-
18-
public interface IPrintable2
19-
{
20-
void Print3();
21-
}
2217
}

0 commit comments

Comments
 (0)