From d51c0331bb7ae8b3be224bb8f8e85e3c0a5e1458 Mon Sep 17 00:00:00 2001 From: copygirl Date: Sat, 6 May 2023 19:10:45 +0200 Subject: [PATCH] Get [Source] from Has and Not as well --- .../Structure/ParameterInfo.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gaemstone.SourceGen/Structure/ParameterInfo.cs b/src/gaemstone.SourceGen/Structure/ParameterInfo.cs index 6615c6a..3a99022 100644 --- a/src/gaemstone.SourceGen/Structure/ParameterInfo.cs +++ b/src/gaemstone.SourceGen/Structure/ParameterInfo.cs @@ -43,17 +43,14 @@ public class ParameterInfo : BaseInfo public ParameterInfo(ISymbol symbol) : base(symbol) { - Source = Get("Source")?.AttributeClass!.TypeArguments[0] - // If the type of the parameter has the [Singleton] attribute, use it as the default Source. - ?? (Symbol.Type.HasAttribute("gaemstone.ECS.SingletonAttribute") ? Symbol.Type : null); - var typeFullName = Symbol.Type.GetFullName(FullNameStyle.Metadata); if (UniqueParameters.TryGetValue(typeFullName, out var replacement)) { - IsOr = false; - Kind = ParameterKind.Unique; - TermTypes = Array.Empty(); + Source = null; UniqueReplacement = replacement; + TermTypes = Array.Empty(); + Kind = ParameterKind.Unique; + IsOr = false; } else { @@ -75,7 +72,7 @@ public class ParameterInfo : BaseInfo FieldType = null; IsOr = true; } - else if ((isHas || isNot) && (args is [ INamedTypeSymbol relation, INamedTypeSymbol target ])) + else if ((isHas || isNot) && (args is [ ITypeSymbol relation, ITypeSymbol target ])) { TermTypes = ImmutableList.Create(new Pair(relation, target)); FieldType = null; @@ -83,7 +80,7 @@ public class ParameterInfo : BaseInfo else { TermTypes = args.ToImmutableList(); - FieldType = IsNullable ? args[0] : type; + FieldType = (IsNullable || isHas || isNot) ? args[0] : type; } } else @@ -92,6 +89,10 @@ public class ParameterInfo : BaseInfo FieldType = Symbol.Type; } + Source = Get("Source")?.AttributeClass!.TypeArguments[0] + // If the type of the parameter has the [Singleton] attribute, use it as the default Source. + ?? ((FieldType?.HasAttribute("gaemstone.ECS.SingletonAttribute") == true) ? FieldType : null); + Kind = isHas ? ParameterKind.Has : isNot ? ParameterKind.Not : IsNullable ? ParameterKind.Nullable