Update documentation of Type.IsAssignableFrom
and Type.IsAssignableTo
when used with ref struct types
#11113
Labels
Type of issue
Missing information
Description
This issue is based on dotnet/runtime#113787
The summary and remarks documentation of this method (and
IsAssignableTo
) are somewhat ambiguous when testing types that areref struct
.The summary stands for:
And the remarks:
However, that is technically not true for
ref struct
types, astypeof(object).IsAssignableFrom(typeof(MyRefStruct))
returnstrue
, but isn't possible to assign such value to a variable of typeobject
becauseref struct
types can't be boxed.Instead, in the issue linked, it's stated that
IsAssignableFrom
(and[...]To
):I find such distinction quite important to include in the documentation, as I got taken by surprise when the method returned
true
, yet I was not able to assign such value, despite the summary documentation stating that if the method returnedtrue
I could assign the value. Such surprise was, that when asked in a C# discord channel, a few users started arguing if this was a bug or not in the implementation, as it was left to some interpretation (starting at message).So I think the documentation should be improved, but I'm not entirely sure how:
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.type.isassignablefrom?view=net-9.0#returns
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/Type.xml
Document Version Independent Id
6821d06b-b052-e2cc-441e-755615bfb8bb
Platform Id
959fc1c0-d8d1-3c0f-3707-bec285810120
Article author
@dotnet-bot
The text was updated successfully, but these errors were encountered: