Skip to content

Commit

Permalink
remove ExpressionHelper, ManagedRuntime and ReflectionHelper.IsRefere…
Browse files Browse the repository at this point in the history
…nceEquatable()
  • Loading branch information
tibel committed Sep 19, 2015
1 parent 7aec156 commit 6b6e195
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 233 deletions.
29 changes: 0 additions & 29 deletions src/Weakly/Expressions/ExpressionHelper.cs

This file was deleted.

85 changes: 0 additions & 85 deletions src/Weakly/Reflection/ManagedRuntime.cs

This file was deleted.

34 changes: 0 additions & 34 deletions src/Weakly/Reflection/ManagedRuntimeType.cs

This file was deleted.

82 changes: 0 additions & 82 deletions src/Weakly/Reflection/ReflectionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -50,86 +49,5 @@ public static bool IsWindowsRuntimeType(this Type type)
{
return type.AssemblyQualifiedName.EndsWith("ContentType=WindowsRuntime", StringComparison.Ordinal);
}

private static readonly Dictionary<Type, bool> ReferenceEquatableTypes = new Dictionary<Type, bool>();

/// <summary>
/// Returns <c>true</c> if this type uses reference equality (i.e., does not override <see cref="object.Equals(object)"/>);
/// returns <c>false</c> if this type or any of its base types override <see cref="object.Equals(object)"/>.
/// This method returns <c>false</c> for any interface type, and returns <c>true</c> for any reference-equatable base class
/// even if a derived class is not reference-equatable;
/// the best way to determine if an object uses reference equality is to pass the exact type of that object.
/// </summary>
/// <param name="type">The type to test for reference equality. May not be <c>null</c>.</param>
/// <returns>
/// Returns <c>true</c> if this type uses reference equality (i.e., does not override <see cref="object.Equals(object)"/>);
/// returns <c>false</c> if this type or any of its base types override <see cref="object.Equals(object)"/>.
/// </returns>
public static bool IsReferenceEquatable(this Type type)
{
if (type.IsPointer)
return false;

var typeInfo = type.GetTypeInfo();
if (!typeInfo.IsClass)
return false;

lock (ReferenceEquatableTypes)
{
bool isReferenceEquatable;
if (!ReferenceEquatableTypes.TryGetValue(type, out isReferenceEquatable))
{
isReferenceEquatable = OverridesEquals(new FullTypeInfo { Type = type, TypeInfo = typeInfo });
ReferenceEquatableTypes[type] = isReferenceEquatable;
}

return isReferenceEquatable;
}
}

private static bool OverridesEquals(FullTypeInfo specificType)
{
foreach (var type in TypeAndBaseTypesExceptObject(specificType))
{
foreach (var method in type.TypeInfo.DeclaredMethods)
{
if (!method.IsPublic || method.IsStatic || !method.IsVirtual || !method.IsHideBySig
|| !method.Name.Equals("Equals", StringComparison.Ordinal))
continue;

var baseDefinition = method.GetRuntimeBaseDefinition();
if (baseDefinition == method)
continue;

if (baseDefinition.DeclaringType == typeof(object))
return true;
}
}

return false;
}

private static IEnumerable<FullTypeInfo> TypeAndBaseTypesExceptObject(FullTypeInfo type)
{
if (type.Type == null || type.Type == typeof(object))
yield break;

while (true)
{
yield return type;

type.Type = type.TypeInfo.BaseType;
if (type.Type == null || type.Type == typeof(object))
yield break;

type.TypeInfo = type.Type.GetTypeInfo();
}
}

private struct FullTypeInfo
{
public Type Type { get; set; }
public TypeInfo TypeInfo { get; set; }
}
}
}
3 changes: 0 additions & 3 deletions src/Weakly/Weakly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@
<Compile Include="Events\WeakNotifyCollectionChangedHandler.cs" />
<Compile Include="Events\WeakNotifyPropertyChangedHandler.cs" />
<Compile Include="NamedObject.cs" />
<Compile Include="Reflection\ManagedRuntime.cs" />
<Compile Include="Reflection\ReflectionHelper.cs" />
<Compile Include="Expressions\ExpressionHelper.cs" />
<Compile Include="IO\MemoryTributary.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflection\ReflectionPath.cs" />
<Compile Include="Reflection\ManagedRuntimeType.cs" />
<Compile Include="Tasks\TaskEventArgs.cs" />
<Compile Include="Tasks\TaskHelper.cs" />
<Compile Include="Tasks\ApmHelper.cs" />
Expand Down

0 comments on commit 6b6e195

Please sign in to comment.