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

wip/source-generators
copygirl 1 year 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) public ParameterInfo(ISymbol symbol)
: base(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); var typeFullName = Symbol.Type.GetFullName(FullNameStyle.Metadata);
if (UniqueParameters.TryGetValue(typeFullName, out var replacement)) if (UniqueParameters.TryGetValue(typeFullName, out var replacement))
{ {
IsOr = false; Source = null;
Kind = ParameterKind.Unique;
TermTypes = Array.Empty<ITypeSymbol>();
UniqueReplacement = replacement; UniqueReplacement = replacement;
TermTypes = Array.Empty<ITypeSymbol>();
Kind = ParameterKind.Unique;
IsOr = false;
} }
else else
{ {
@ -75,7 +72,7 @@ public class ParameterInfo : BaseInfo
FieldType = null; FieldType = null;
IsOr = true; 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)); TermTypes = ImmutableList.Create(new Pair(relation, target));
FieldType = null; FieldType = null;
@ -83,7 +80,7 @@ public class ParameterInfo : BaseInfo
else else
{ {
TermTypes = args.ToImmutableList(); TermTypes = args.ToImmutableList();
FieldType = IsNullable ? args[0] : type; FieldType = (IsNullable || isHas || isNot) ? args[0] : type;
} }
} }
else else
@ -92,6 +89,10 @@ public class ParameterInfo : BaseInfo
FieldType = Symbol.Type; 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 Kind = isHas ? ParameterKind.Has
: isNot ? ParameterKind.Not : isNot ? ParameterKind.Not
: IsNullable ? ParameterKind.Nullable : IsNullable ? ParameterKind.Nullable

Loading…
Cancel
Save