Get [Source] from Has<T> and Not<T> as well

wip/source-generators
copygirl 12 months ago
parent ef64ba4e08
commit d51c0331bb
  1. 19
      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<ITypeSymbol>();
Source = null;
UniqueReplacement = replacement;
TermTypes = Array.Empty<ITypeSymbol>();
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

Loading…
Cancel
Save