Incorrect results for generic value types
adamjones1 opened this issue · comments
I'm not sure if I'm using the library wrong but as far as I can tell I appear to be getting some incorrect results.
public class MyType
{
public (string, Uri?) MyProp { get; }
}
public static void Main(string[] args)
{
var prop = typeof(MyType).GetProperty("MyProp").ToContextualProperty();
Console.WriteLine(prop.Nullability);
Console.WriteLine(prop.GenericArguments[0].Nullability);
Console.WriteLine(prop.GenericArguments[1].Nullability);
}
I'm getting the string
as Unknown and the Uri
as NotNullable. This doesn't look like it's an issue if I change the tuple to Dictionary<,>
though so maybe it's specific to ValueTuples?
Actually looks like it applies more generally to any generic value type with multiple type parameters. I get the same issue if I change MyType
to
public struct GenericValueType<T1, T2> { }
public class MyType
{
public GenericValueType<string, Uri?> MyProp { get; }
}
There are some tests regarding generics:
https://github.com/RicoSuter/Namotion.Reflection/blob/master/src/Namotion.Reflection.Tests/NullabilityTests.cs#L120
So this needs some investigation
Maybe its a problem with structs?
Yep, I edited the issue title to be specific to value types. Looks like all the generic types (with >1 type parameter) in the tests are reference types.