Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Inconsistency happens when CSharpType is created from System.Nullable<T> #4678

Open
ArcturusZhang opened this issue May 6, 2024 · 0 comments · May be fixed by #4680
Open

[Bug] Inconsistency happens when CSharpType is created from System.Nullable<T> #4678

ArcturusZhang opened this issue May 6, 2024 · 0 comments · May be fixed by #4680
Labels
MGC v3 Version 3 of AutoRest C# generator.

Comments

@ArcturusZhang
Copy link
Member

ArcturusZhang commented May 6, 2024

Describe the issue or request

We decide to hide the System.Nullable<T> layer in our type system, for instance, we will not generate model a nullable int type as CSharpType { IsFrameworkType: true, FrameworkType: typeof(Nullable<>), Arguments: [ typeof(int) ]
Instead, we do this:

CSharpType { IsFrameworkType: true, FrameworkType: typeof(int), IsNullable: true }

But when we create an instance of CSharpType from typeof(int?), we still get an instance as a generic type of System.Nullable<T>.
The issue exists in this implementation is that if we do this:

CSharpType type = typeof(int?);
Assert.IsTrue(type.IsNullable); // this will fail.

This creates an inconsistency, and when we are creating types, we have to notice that we should not do the above, instead, we should do:

CSharpType type = new CSharpType(typeof(int), true); // this creates a nullable int
Assert.IsTrue(type.IsNullable); // this succeeds.

Unfortunately this is not covered by any test cases. We should add more to validate such an important infrastructure is working as expected.

@ArcturusZhang ArcturusZhang added the v3 Version 3 of AutoRest C# generator. label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MGC v3 Version 3 of AutoRest C# generator.
Projects
None yet
1 participant