diff --git a/src-examples/ProxyInterfaceConsumerViaNuGet/ProxyInterfaceConsumerViaNuGet.csproj b/src-examples/ProxyInterfaceConsumerViaNuGet/ProxyInterfaceConsumerViaNuGet.csproj
index 4ad7f2b..82e25f8 100644
--- a/src-examples/ProxyInterfaceConsumerViaNuGet/ProxyInterfaceConsumerViaNuGet.csproj
+++ b/src-examples/ProxyInterfaceConsumerViaNuGet/ProxyInterfaceConsumerViaNuGet.csproj
@@ -12,7 +12,10 @@
-
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
\ No newline at end of file
diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs
index 50a7712..1f65fd6 100644
--- a/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs
+++ b/src/ProxyInterfaceSourceGenerator/Extensions/NamedTypeSymbolExtensions.cs
@@ -46,18 +46,12 @@ internal static class NamedTypeSymbolExtensions
$"{namedTypeSymbol.Name}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>";
}
- public static string ResolveFullProxyClassName(this INamedTypeSymbol namedTypeSymbol)
- {
- return !namedTypeSymbol.IsGenericType ?
- $"{namedTypeSymbol}Proxy" :
- $"{namedTypeSymbol}Proxy<{string.Join(", ", namedTypeSymbol.TypeArguments.Select(ta => ta.Name))}>";
- }
-
public static List ResolveImplementedInterfaces(this INamedTypeSymbol symbol, bool proxyBaseClasses)
{
- //Members implemented by us or base classes should go here.
+ // Members implemented by us or base classes should go here.
var publicMembers = symbol.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public).ToList();
- //Direct interfaces, recursive interfaces or base class interfaces should go here.
+
+ // Direct interfaces, recursive interfaces or base class interfaces should go here.
var interfaces = new List(symbol.Interfaces);
var baseType = symbol.BaseType;
while (proxyBaseClasses && baseType != null && baseType.SpecialType != SpecialType.System_Object)
@@ -67,12 +61,12 @@ internal static class NamedTypeSymbolExtensions
baseType = baseType.BaseType;
}
- //Filter explicitly implemented interfaces.
+ // Filter explicitly implemented interfaces.
var realizedInterfaces = new List();
- foreach (var iface in interfaces)
+ foreach (var @interface in interfaces)
{
var isRealized = true;
- var allMembers = iface.AllInterfaces.Aggregate(iface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers()));
+ var allMembers = @interface.AllInterfaces.Aggregate(@interface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers()));
foreach (var member in allMembers)
{
var implementation = symbol.FindImplementationForInterfaceMember(member);
@@ -82,11 +76,13 @@ internal static class NamedTypeSymbolExtensions
break;
}
}
+
if (isRealized)
{
- realizedInterfaces.Add(iface);
+ realizedInterfaces.Add(@interface);
}
}
+
return realizedInterfaces;
}
}
\ No newline at end of file
diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs
index be828a3..cbf5c74 100644
--- a/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs
+++ b/src/ProxyInterfaceSourceGenerator/Extensions/SymbolExtensions.cs
@@ -30,7 +30,7 @@ internal static class SymbolExtensions
}
//https://stackoverflow.com/questions/27105909/get-fully-qualified-metadata-name-in-roslyn
- public static string GetFullMetadataName(this ISymbol s)
+ public static string GetFullMetadataName(this ISymbol? s)
{
if (s == null || IsRootNamespace(s))
{
@@ -69,9 +69,6 @@ internal static class SymbolExtensions
public static bool IsPublic(this ISymbol? symbol) =>
symbol is { DeclaredAccessibility: Accessibility.Public };
- private static bool IsRootNamespace(ISymbol symbol)
- {
- INamespaceSymbol s = null;
- return ((s = symbol as INamespaceSymbol) != null) && s.IsGlobalNamespace;
- }
+ private static bool IsRootNamespace(ISymbol symbol) =>
+ symbol is INamespaceSymbol { IsGlobalNamespace: true };
}
\ No newline at end of file
diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/TypeSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/TypeSymbolExtensions.cs
index efb2886..7327ae1 100644
--- a/src/ProxyInterfaceSourceGenerator/Extensions/TypeSymbolExtensions.cs
+++ b/src/ProxyInterfaceSourceGenerator/Extensions/TypeSymbolExtensions.cs
@@ -23,11 +23,6 @@ internal static class TypeSymbolExtensions
public static bool IsString(this ITypeSymbol ts) =>
ts.ToString().ToLowerInvariant() == "string" || ts.ToString().ToLowerInvariant() == "string?";
- public static string ToFullyQualifiedDisplayString(this ITypeSymbol property)
- {
- return property.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat);
- }
-
- internal static bool IsClass(this ITypeSymbol ts) =>
- ts.IsReferenceType && ts.TypeKind == TypeKind.Class;
+ public static string ToFullyQualifiedDisplayString(this ITypeSymbol property) =>
+ property.ToDisplayString(NullableFlowState.None, SymbolDisplayFormat.FullyQualifiedFormat);
}
\ No newline at end of file
diff --git a/src/ProxyInterfaceSourceGenerator/FileGenerators/PartialInterfacesGenerator.cs b/src/ProxyInterfaceSourceGenerator/FileGenerators/PartialInterfacesGenerator.cs
index 9d8c2af..27f7c65 100644
--- a/src/ProxyInterfaceSourceGenerator/FileGenerators/PartialInterfacesGenerator.cs
+++ b/src/ProxyInterfaceSourceGenerator/FileGenerators/PartialInterfacesGenerator.cs
@@ -11,9 +11,9 @@ namespace ProxyInterfaceSourceGenerator.FileGenerators;
internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
{
- private IReadOnlyCollection ImplementedInterfaces = new List();
- public PartialInterfacesGenerator(Context context, bool supportsNullable) :
- base(context, supportsNullable)
+ private IReadOnlyCollection _implementedInterfaces = new List();
+
+ public PartialInterfacesGenerator(Context context, bool supportsNullable) : base(context, supportsNullable)
{
}
@@ -59,8 +59,8 @@ internal class PartialInterfacesGenerator : BaseGenerator, IFilesGenerator
ProxyData proxyData)
{
var extendsProxyClasses = GetExtendsProxyData(proxyData, classSymbol);
- ImplementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces(proxyData.ProxyBaseClasses);
- var implementedInterfacesNames = ImplementedInterfaces.Select(i => i.ToFullyQualifiedDisplayString());
+ _implementedInterfaces = classSymbol.Symbol.ResolveImplementedInterfaces(proxyData.ProxyBaseClasses);
+ var implementedInterfacesNames = _implementedInterfaces.Select(i => i.ToFullyQualifiedDisplayString()).ToArray();
var implements = implementedInterfacesNames.Any() ? $" : {string.Join(", ", implementedInterfacesNames)}" : string.Empty;
var @new = extendsProxyClasses.Any() ? "new " : string.Empty;
var (namespaceStart, namespaceEnd) = NamespaceBuilder.Build(ns);
@@ -96,16 +96,17 @@ methods}
private Func InterfaceFilter() where T : ISymbol
{
var hashSet = new HashSet();
- foreach (var iface in ImplementedInterfaces)
+ foreach (var @interface in _implementedInterfaces)
{
- var members = iface.AllInterfaces.Aggregate(iface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers()));
+ var members = @interface.AllInterfaces.Aggregate(@interface.GetMembers(), (xs, x) => xs.AddRange(x.GetMembers()));
foreach (var member in members)
{
hashSet.Add(member.Name);
}
}
- //Member is not already implemented in another interface.
- return (T t) => !hashSet.Contains(t.Name);
+
+ // Member is not already implemented in another interface.
+ return t => !hashSet.Contains(t.Name);
}
private string GenerateProperties(ClassSymbol targetClassSymbol, bool proxyBaseClasses)
diff --git a/src/ProxyInterfaceSourceGenerator/Models/Context.cs b/src/ProxyInterfaceSourceGenerator/Models/Context.cs
index dc13584..f08797c 100644
--- a/src/ProxyInterfaceSourceGenerator/Models/Context.cs
+++ b/src/ProxyInterfaceSourceGenerator/Models/Context.cs
@@ -7,8 +7,6 @@ internal record Context
{
public GeneratorExecutionContext GeneratorExecutionContext { get; init; }
- // public List GeneratedData { get; } = new List();
-
public IDictionary Candidates { get; init; } = default!;
public Dictionary ReplacedTypes { get; } = new();
diff --git a/src/ProxyInterfaceSourceGenerator/Models/ContextData.cs b/src/ProxyInterfaceSourceGenerator/Models/ContextData.cs
deleted file mode 100644
index 7910286..0000000
--- a/src/ProxyInterfaceSourceGenerator/Models/ContextData.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace ProxyInterfaceSourceGenerator.Models;
-
-internal record ContextData
-{
- public string? InterfaceName { get; init; }
-
- public string? ClassName { get; init; }
-
- public FileData FileData { get; init; } = default!;
-}
\ No newline at end of file
diff --git a/src/ProxyInterfaceSourceGenerator/Models/ProxyData.cs b/src/ProxyInterfaceSourceGenerator/Models/ProxyData.cs
index b31976e..3a4a407 100644
--- a/src/ProxyInterfaceSourceGenerator/Models/ProxyData.cs
+++ b/src/ProxyInterfaceSourceGenerator/Models/ProxyData.cs
@@ -4,6 +4,26 @@ namespace ProxyInterfaceSourceGenerator.Models;
internal class ProxyData
{
+ public string Namespace { get; }
+
+ public string NamespaceDot { get; }
+
+ public string ShortInterfaceName { get; }
+
+ public string FullInterfaceName { get; }
+
+ public string FullQualifiedTypeName { get; }
+
+ public string ShortMetadataName { get; }
+
+ public string FullMetadataTypeName { get; }
+
+ public List Usings { get; }
+
+ public bool ProxyBaseClasses { get; }
+
+ public ProxyClassAccessibility Accessibility { get; }
+
public ProxyData(string @namespace,
string namespaceDot,
string shortInterfaceName,
@@ -26,24 +46,4 @@ internal class ProxyData
ProxyBaseClasses = proxyBaseClasses;
Accessibility = accessibility;
}
-
- public string Namespace { get; }
-
- public string NamespaceDot { get; }
-
- public string ShortInterfaceName { get; }
-
- public string FullInterfaceName { get; }
-
- public string FullQualifiedTypeName { get; }
-
- public string ShortMetadataName { get; }
-
- public string FullMetadataTypeName { get; }
-
- public List Usings { get; }
-
- public bool ProxyBaseClasses { get; }
-
- public ProxyClassAccessibility Accessibility { get; }
}
\ No newline at end of file