The source generator already reads AttributeClass.TypeArguments (committed in b7ada7a5d81), so the moment the Trecs core package can declare SingleEntityAttribute<T1..T4> / ForEachEntityAttribute<T1..T4> / FromWorldAttribute<T1..T4>, users get the C# 11 generic-attribute shorthand:
[SingleEntity<TuskTags.Player>] // vs. [SingleEntity(typeof(TuskTags.Player))]
[ForEachEntity<TuskTags.Fish, Eating>] // vs. [ForEachEntity(typeof(Fish), typeof(Eating))]
[FromWorld<TuskTags.Fish>]
Why it isn't shipped today
Unity 6's bundled Roslyn predates 4.4, so generic attributes are stuck behind -langversion:preview. We tested both paths:
-langversion:11 — rejected outright: CS1617 Invalid option '11' for /langversion.
-langversion:preview — accepts generic attributes, but simultaneously activates stricter C# 11 ref-safety analysis. That surfaces ~10 pre-existing CS8347 / CS8168 errors in NativeWorldAccessor.cs and EntitySubmitter.cs (Cannot return local 'bag' by reference, may expose variables referenced by parameter), which is a real refactor outside the scope of this feature.
What's needed when we revisit
- Confirm Unity ships Roslyn 4.4+ (or fix the ref-safety regressions to opt into
preview cleanly).
- Add
csc.rsp with -langversion:latest (or :11) at Packages/com.trecs.core/Scripts/.
- Re-add the four-arity generic attribute classes to
SingleEntityAttribute.cs, ForEachEntityAttribute.cs, FromWorldAttribute.cs — capped at 4 to match WithTags<T1, T2, T3, T4>. ForEachEntity's generic variants need Set / MatchByComponents properties; the others are bare.
- No source-gen changes required — TypeArguments parsing is already wired through
InlineTagsParser, IterationCriteriaParser, the FromWorld paths in JobGenerator/AutoJobGenerator, and AutoSystemGenerator.HasAnyAttributeCriteria. The conflict diagnostic (TRECS053) already covers [X<T>] mixed with named Tag / Tags.
- Tests are already in place —
RunOnceGeneratorTests.RunOnce_GenericAttribute* exercise the path via stubs.
The source generator already reads
AttributeClass.TypeArguments(committed in b7ada7a5d81), so the moment the Trecs core package can declareSingleEntityAttribute<T1..T4>/ForEachEntityAttribute<T1..T4>/FromWorldAttribute<T1..T4>, users get the C# 11 generic-attribute shorthand:Why it isn't shipped today
Unity 6's bundled Roslyn predates 4.4, so generic attributes are stuck behind
-langversion:preview. We tested both paths:-langversion:11— rejected outright:CS1617 Invalid option '11' for /langversion.-langversion:preview— accepts generic attributes, but simultaneously activates stricter C# 11 ref-safety analysis. That surfaces ~10 pre-existingCS8347/CS8168errors inNativeWorldAccessor.csandEntitySubmitter.cs(Cannot return local 'bag' by reference,may expose variables referenced by parameter), which is a real refactor outside the scope of this feature.What's needed when we revisit
previewcleanly).csc.rspwith-langversion:latest(or:11) atPackages/com.trecs.core/Scripts/.SingleEntityAttribute.cs,ForEachEntityAttribute.cs,FromWorldAttribute.cs— capped at 4 to matchWithTags<T1, T2, T3, T4>. ForEachEntity's generic variants needSet/MatchByComponentsproperties; the others are bare.InlineTagsParser,IterationCriteriaParser, theFromWorldpaths inJobGenerator/AutoJobGenerator, andAutoSystemGenerator.HasAnyAttributeCriteria. The conflict diagnostic (TRECS053) already covers[X<T>]mixed with namedTag/Tags.RunOnceGeneratorTests.RunOnce_GenericAttribute*exercise the path via stubs.