-
Notifications
You must be signed in to change notification settings - Fork 44
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
EnumerableItemType seems not working for Dictionary #67
Comments
The following code "works", but nullability is lost: GetInterface(typeof(IEnumerable<>).FullName).GetRuntimeMethods().Single()
.ReturnParameter.ToContextualParameter() |
Not sure "EnumerableItemType" sould be used for that, we had a discussion about how we could detect the nullability of generic arguments in a generic way, but it turns out it's harder than expected, and I didn't find a way to make it agnostic enough... I disliked the concept of |
@jeremyVignelles Yes, as I am testing more cases, the nullability is broken somehow:
But
Do you know why the nullability of string gets lost? Btw. I understand that you dislike bool TryGetInterfaceGenericArguments(this ContextualType type, string genericInterfaceName, out ContextualType[] genericIntefaceArguments) (This method could be used instead of |
The real design of how NRT works is really not intuitive. It's based on [Nullable] attributes that can be set on properties and types, but when it comes to generics, things are really complicated : on If you have Now imagine I have a In other words, if you have If you want, we can chat about it in private on gitter or discord if you have ideas or if you need more explanations. |
@jeremyVignelles I am not sure about that. If I understand your statement correctly, ILSpy (icsharpcode/ILSpy#1425) will not be able to determine nullability of the following: interface IBar<T> { }
class Bar : IBar<string> { }
class BarN : IBar<string?> { } But ILSpy decompiles it correctly. (I known that is not easy problem, I have started implementing NRT for reflection, but after realizing the real size of it, I have stopped and tried to search whether someone else have already implemented it. Then, I have found dotnet/runtime#29723, which points (back) to this library.) |
You can try it out here : There is no difference between Now, with this code: #nullable enable
interface IBar<T> {
T GetT();
}
class Bar : IBar<string> {
public string GetT() => "";
}
class BarN : IBar<string?> {
public string? GetT() => "";
} the classes differ only on the GetT() annotations see here Things get worse if you type BarN.GetT as a |
"There is no difference between Bar and BarN in the generated code." There are different flags, check the IL:
But I do not know, how to access custom attributes in the implements part via reflection. "My guess is that NRT were not made for the disassembly/reflection use case." I agree. |
Nullable attribute on the auto generated constructor. So yeah, we might be able to know parts of the story, but we would still need to know what we're trying to read. Working with Nullable attributes is already done by this library, but knowing where attributes are placed and where to glue things together and how to access a value is really tricky |
returns
null
.The reason seems to be that
returns
System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Int32]
.And the current implementation looks like:
Namotion.Reflection/src/Namotion.Reflection/Context/ContextualType.cs
Lines 160 to 165 in 4279901
The text was updated successfully, but these errors were encountered: