Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Have a Type.IsConvertible property. (#15365)
Browse files Browse the repository at this point in the history
dotnet/corefx#25671 asks for this as a public API, but this just seeks
to make it available to corefx.

Motivation discussed at dotnet/corefx#25663 and dotnet/corefx#25670

Mirror PR to corert will need and overload making runtime types return
false there.
  • Loading branch information
JonHanna authored and jkotas committed Dec 5, 2017
1 parent 6eaf27d commit 7e202dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/mscorlib/shared/System/Reflection/TypeDelegator.cs
Expand Up @@ -112,6 +112,9 @@ public TypeDelegator(Type delegatingType)
protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject;
public override bool IsByRefLike => typeImpl.IsByRefLike;
public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType;

public override bool IsCollectible => typeImpl.IsCollectible;

public override Type GetElementType() => typeImpl.GetElementType();
protected override bool HasElementTypeImpl() => typeImpl.HasElementType;

Expand Down
2 changes: 2 additions & 0 deletions src/mscorlib/shared/System/Type.cs
Expand Up @@ -102,6 +102,8 @@ public virtual Type[] GetGenericParameterConstraints()
public bool IsContextful => IsContextfulImpl();
protected virtual bool IsContextfulImpl() => false;

public virtual bool IsCollectible => true;

public virtual bool IsEnum => IsSubclassOf(typeof(Enum));
public bool IsMarshalByRef => IsMarshalByRefImpl();
protected virtual bool IsMarshalByRefImpl() => false;
Expand Down
7 changes: 2 additions & 5 deletions src/mscorlib/src/System/RtType.cs
Expand Up @@ -2459,7 +2459,7 @@ private RuntimeTypeCache Cache
IntPtr gcHandle = Interlocked.CompareExchange(ref m_cache, newgcHandle, IntPtr.Zero);
// Leak the handle if the type is collectible. It will be reclaimed when
// the type goes away.
if (gcHandle != IntPtr.Zero && !IsCollectible())
if (gcHandle != IntPtr.Zero && !IsCollectible)
GCHandle.InternalFree(newgcHandle);
}

Expand Down Expand Up @@ -3151,10 +3151,7 @@ internal sealed override RuntimeTypeHandle GetTypeHandleInternal()
return new RuntimeTypeHandle(this);
}

internal bool IsCollectible()
{
return RuntimeTypeHandle.IsCollectible(GetTypeHandleInternal());
}
public sealed override bool IsCollectible => RuntimeTypeHandle.IsCollectible(GetTypeHandleInternal());

protected override TypeCode GetTypeCodeImpl()
{
Expand Down

0 comments on commit 7e202dc

Please sign in to comment.