-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Avoid using Type.IsEquivalentTo on code changed by #1963 #1997
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
Conversation
@@ -82,7 +82,7 @@ internal static bool IsOrleansShallowCopyable(this Type t) | |||
|
|||
private static bool IsTypeFieldsShallowCopyable(TypeInfo typeInfo) | |||
{ | |||
return typeInfo.GetFields().All(f => !(f.FieldType.IsEquivalentTo(typeInfo)) && IsOrleansShallowCopyable(f.FieldType)); | |||
return typeInfo.GetFields().All(f => !f.FieldType.GetTypeInfo().IsEquivalentTo(typeInfo.AsType()) && IsOrleansShallowCopyable(f.FieldType)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the tests in the corefx repository: https://github.com/dotnet/corefx/blob/master/src/System.Reflection/tests/TypeInfo/TypeInfo_IsEquivalentTo.cs#L17
this was compatible with .NET core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And either GetTypeInfo()
or AsType()
call seems unnecessary. (Previously the Type
was compared with TypeInfo
, and now - TypeInfo
is being compared with Type
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that example you are linking is actually doing GetTypeInfo and then passing a type (not a typeinfo) to the IsEquivalentTo method, which is exactly what I'm doing too. BTW, I did this change in my coreclr branch because it did not compile for me, I'm not speculating. This works in full dotNET because TypeInfo inherits from Type, but that's not the case in netcore, and it's why we use the GetTypeInfo extension method and the AsType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this equality check isn't symmetric, but I believed that it is..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, it's not. That's probably why they aren't just using IEquatable in that test.
With this new insight, do you recommend reverting your original PR or keep it this way? or use a different comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to revert original PR, as its purpose was in extracting allocation causing code into separate method. So it's OK as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but what about doing this at least:
return typeInfo.GetFields().All(f => f.FieldType != typeInfo.AsType()) && IsOrleansShallowCopyable(f.FieldType));
This way we don't get the TypeInfo unecessarily in the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with that approach and added some test coverage
In preparation for the .NET Core port (broken during dotnet#1963). Added test coverage for this check.
cc842ef
to
1d2bd47
Compare
Use TypeInfo and Type correctly in preparation for the .NET Core port (broken during #1963).
Minor cleanup: Replace DNXCORE50 deprecated constant with NETSTANDARD1_6
/cc @dVakulen