diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs index 5bb50ef..c7080c9 100644 --- a/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs +++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/BaseGenerator.cs @@ -71,6 +71,7 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators protected INamedTypeSymbol GetType(string name) { + // The GetTypeByMetadataName method returns null if no type matches the full name or if 2 or more types (in different assemblies) match the full name. var symbol = _context.GeneratorExecutionContext.Compilation.GetTypeByMetadataName(name); if (symbol is null) { diff --git a/src/ProxyInterfaceSourceGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs b/src/ProxyInterfaceSourceGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs index e5fd78f..a03e901 100644 --- a/src/ProxyInterfaceSourceGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs +++ b/src/ProxyInterfaceSourceGenerator/SyntaxReceiver/ProxySyntaxReceiver.cs @@ -8,6 +8,8 @@ namespace ProxyInterfaceSourceGenerator.SyntaxReceiver { internal class ProxySyntaxReceiver : ISyntaxReceiver { + private static readonly string[] Modifiers = new[] { "public", "partial" }; + public IDictionary CandidateInterfaces { get; } = new Dictionary(); public void OnVisitSyntaxNode(SyntaxNode syntaxNode) @@ -20,9 +22,14 @@ namespace ProxyInterfaceSourceGenerator.SyntaxReceiver private static bool TryGet(InterfaceDeclarationSyntax interfaceDeclarationSyntax, out ProxyData data) { - data = new(string.Empty, string.Empty, string.Empty, false); - - // TODO : how to check if the InterfaceDeclarationSyntax has 'partial' ? + data = new(string.Empty, string.Empty, string.Empty, false); + + if (interfaceDeclarationSyntax.Modifiers.Select(m => m.ToString()).Except(Modifiers).Count() != 0) + { + // InterfaceDeclarationSyntax should be "public" and "partial" + return false; + } + var attributeLists = interfaceDeclarationSyntax.AttributeLists.FirstOrDefault(x => x.Attributes.Any(a => a.Name.ToString().Equals("ProxyInterfaceGenerator.Proxy"))); if (attributeLists is null) { @@ -45,7 +52,7 @@ namespace ProxyInterfaceSourceGenerator.SyntaxReceiver ( ns, interfaceDeclarationSyntax.Identifier.ToString(), - argumentList.Arguments[0].Expression.ChildNodes().First().GetText().ToString(), + ((TypeOfExpressionSyntax)argumentList.Arguments[0].Expression).Type.ToString(), false //bool.Parse(argumentList.Arguments[1].Expression.GetText().ToString()) );