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

Commit 7e202dc

Browse files
JonHannajkotas
authored andcommitted
Have a Type.IsConvertible property. (#15365)
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.
1 parent 6eaf27d commit 7e202dc

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/mscorlib/shared/System/Reflection/TypeDelegator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindin
112112
protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject;
113113
public override bool IsByRefLike => typeImpl.IsByRefLike;
114114
public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType;
115+
116+
public override bool IsCollectible => typeImpl.IsCollectible;
117+
115118
public override Type GetElementType() => typeImpl.GetElementType();
116119
protected override bool HasElementTypeImpl() => typeImpl.HasElementType;
117120

src/mscorlib/shared/System/Type.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public virtual Type[] GetGenericParameterConstraints()
102102
public bool IsContextful => IsContextfulImpl();
103103
protected virtual bool IsContextfulImpl() => false;
104104

105+
public virtual bool IsCollectible => true;
106+
105107
public virtual bool IsEnum => IsSubclassOf(typeof(Enum));
106108
public bool IsMarshalByRef => IsMarshalByRefImpl();
107109
protected virtual bool IsMarshalByRefImpl() => false;

src/mscorlib/src/System/RtType.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ private RuntimeTypeCache Cache
24592459
IntPtr gcHandle = Interlocked.CompareExchange(ref m_cache, newgcHandle, IntPtr.Zero);
24602460
// Leak the handle if the type is collectible. It will be reclaimed when
24612461
// the type goes away.
2462-
if (gcHandle != IntPtr.Zero && !IsCollectible())
2462+
if (gcHandle != IntPtr.Zero && !IsCollectible)
24632463
GCHandle.InternalFree(newgcHandle);
24642464
}
24652465

@@ -3151,10 +3151,7 @@ internal sealed override RuntimeTypeHandle GetTypeHandleInternal()
31513151
return new RuntimeTypeHandle(this);
31523152
}
31533153

3154-
internal bool IsCollectible()
3155-
{
3156-
return RuntimeTypeHandle.IsCollectible(GetTypeHandleInternal());
3157-
}
3154+
public sealed override bool IsCollectible => RuntimeTypeHandle.IsCollectible(GetTypeHandleInternal());
31583155

31593156
protected override TypeCode GetTypeCodeImpl()
31603157
{

0 commit comments

Comments
 (0)