When typed id is placed in the global namespace, the project with generated code fails to compile with rather unhelpful build report.
using LeanCode.DomainModels.Ids;
// note no namespace declaration
[TypedId(TypedIdFormat.RawGuid)]
public readonly partial record struct Id;
results with
Restore complete (0.5s)
Example failed with 7 error(s) (0.4s)
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,11): error CS1001: Identifier expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,11): error CS1514: { expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,12): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,28): error CS1001: Identifier expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,28): error CS1514: { expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(4,1): error CS1022: Type or namespace definition, or end-of-file expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(77,2): error CS1513: } expected
Build failed with 7 error(s) in 1.1s
This result comes from using ISymbol.ContainingNamespace.ToDisplayString() here, which resolves to <global namespace> for the global namespace, which is not a valid identifier in C# code.
We should either properly support identifiers in the global namespace or emit a diagnostic report instead of non-compiling code (preferably maybe?).
When typed id is placed in the global namespace, the project with generated code fails to compile with rather unhelpful build report.
results with
This result comes from using
ISymbol.ContainingNamespace.ToDisplayString()here, which resolves to<global namespace>for the global namespace, which is not a valid identifier in C# code.We should either properly support identifiers in the global namespace or emit a diagnostic report instead of non-compiling code (preferably maybe?).