Skip to content

Conversation

jdom
Copy link
Member

@jdom jdom commented Jul 28, 2016

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

@@ -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));
Copy link
Contributor

@dVakulen dVakulen Jul 29, 2016

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.

Copy link
Contributor

@dVakulen dVakulen Jul 29, 2016

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)

Copy link
Member Author

@jdom jdom Jul 29, 2016

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

Copy link
Contributor

@dVakulen dVakulen Jul 29, 2016

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..

Copy link
Member Author

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?

Copy link
Contributor

@dVakulen dVakulen Jul 29, 2016

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.

Copy link
Member Author

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

Copy link
Member Author

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

jdom added 2 commits July 29, 2016 18:37
In preparation for the .NET Core port (broken during dotnet#1963).
Added test coverage for this check.
@jdom jdom force-pushed the netcore-preparation branch from cc842ef to 1d2bd47 Compare July 30, 2016 01:38
@jdom jdom changed the title Use GetTypeInfo() on code changed by #1963 Avoid using Type.IsEquivalentTo on code changed by #1963 Aug 1, 2016
@jason-bragg jason-bragg merged commit 358f077 into dotnet:master Aug 1, 2016
@jdom jdom deleted the netcore-preparation branch August 1, 2016 18:00
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants