Skip to content

Commit 005426d

Browse files
Rename IsInterface to avoid Reflection issues
This is a narrow change to address a user reported issue on System.Runtime and the common implementation detail, System.RuntimeType.
1 parent 315dbcf commit 005426d

File tree

10 files changed

+24
-22
lines changed

10 files changed

+24
-22
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ internal static CustomAttributeEncoding TypeToCustomAttributeEncoding(RuntimeTyp
170170
if (type.IsClass)
171171
return CustomAttributeEncoding.Object;
172172

173-
if (type.IsInterface)
173+
if (type.IsActualInterface)
174174
return CustomAttributeEncoding.Object;
175175

176176
if (type.IsActualValueType)
@@ -2263,7 +2263,7 @@ internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType? caType)
22632263

22642264
internal static StructLayoutAttribute? GetStructLayoutCustomAttribute(RuntimeType type)
22652265
{
2266-
if (type.IsInterface || type.HasElementType || type.IsGenericParameter)
2266+
if (type.IsActualInterface || type.HasElementType || type.IsGenericParameter)
22672267
return null;
22682268

22692269
LayoutKind layoutKind = LayoutKind.Auto;

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Signature LazyCreateSignature()
105105

106106
internal RuntimeMethodInfo? GetParentDefinition()
107107
{
108-
if (!IsVirtual || m_declaringType.IsInterface)
108+
if (!IsVirtual || m_declaringType.IsActualInterface)
109109
return null;
110110

111111
RuntimeType? parent = (RuntimeType?)m_declaringType.BaseType;
@@ -323,7 +323,7 @@ internal void InvokePropertySetter(object? obj, BindingFlags invokeAttr, Binder?
323323

324324
public override MethodInfo GetBaseDefinition()
325325
{
326-
if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface)
326+
if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsActualInterface)
327327
return this;
328328

329329
int slot = RuntimeMethodHandle.GetSlot(this);

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/DynamicInterfaceCastableHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static bool IsInterfaceImplemented(IDynamicInterfaceCastable castable,
3030
throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, castable.GetType(), interfaceType));
3131

3232
RuntimeType implType = handle.GetRuntimeType();
33-
if (!implType.IsInterface)
33+
if (!implType.IsActualInterface)
3434
throw new InvalidOperationException(SR.Format(SR.IDynamicInterfaceCastable_NotInterface, implType.ToString()));
3535

3636
if (!implType.IsDefined(typeof(DynamicInterfaceCastableImplementationAttribute), inherit: false))

src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ private unsafe RuntimeMethodInfo[] PopulateMethods(Filter filter)
579579
RuntimeType declaringType = ReflectedType;
580580
Debug.Assert(declaringType != null);
581581

582-
if (declaringType.IsInterface)
582+
if (declaringType.IsActualInterface)
583583
{
584584
#region IsInterface
585585

@@ -998,7 +998,7 @@ private RuntimeType[] PopulateInterfaces(Filter filter)
998998
continue;
999999
}
10001000

1001-
Debug.Assert(interfaceType.IsInterface);
1001+
Debug.Assert(interfaceType.IsActualInterface);
10021002
list.Add(interfaceType);
10031003
}
10041004

@@ -1028,7 +1028,7 @@ private RuntimeType[] PopulateInterfaces(Filter filter)
10281028
for (int i = 0; i < constraints.Length; i++)
10291029
{
10301030
RuntimeType constraint = (RuntimeType)constraints[i];
1031-
if (constraint.IsInterface)
1031+
if (constraint.IsActualInterface)
10321032
al.Add(constraint);
10331033

10341034
Type[] temp = constraint.GetInterfaces();
@@ -1113,7 +1113,7 @@ private RuntimeEventInfo[] PopulateEvents(Filter filter)
11131113
RuntimeType declaringType = ReflectedType;
11141114
ListBuilder<RuntimeEventInfo> list = default;
11151115

1116-
if (!declaringType.IsInterface)
1116+
if (!declaringType.IsActualInterface)
11171117
{
11181118
while (RuntimeTypeHandle.IsGenericVariable(declaringType))
11191119
declaringType = declaringType.GetBaseType()!;
@@ -1206,7 +1206,7 @@ private RuntimePropertyInfo[] PopulateProperties(Filter filter)
12061206

12071207
ListBuilder<RuntimePropertyInfo> list = default;
12081208

1209-
if (!declaringType.IsInterface)
1209+
if (!declaringType.IsActualInterface)
12101210
{
12111211
while (RuntimeTypeHandle.IsGenericVariable(declaringType))
12121212
declaringType = declaringType.GetBaseType()!;
@@ -1258,8 +1258,8 @@ private void PopulateProperties(
12581258

12591259
int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(declaringType);
12601260

1261-
Debug.Assert((declaringType.IsInterface && isInterface && csPropertyInfos == null) ||
1262-
(!declaringType.IsInterface && !isInterface && usedSlots.Length >= numVirtuals));
1261+
Debug.Assert((declaringType.IsActualInterface && isInterface && csPropertyInfos == null) ||
1262+
(!declaringType.IsActualInterface && !isInterface && usedSlots.Length >= numVirtuals));
12631263

12641264
for (int i = 0; i < tkProperties.Length; i++)
12651265
{
@@ -2697,7 +2697,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
26972697

26982698
TypeHandle.VerifyInterfaceIsImplemented(ifaceRtTypeHandle);
26992699
Debug.Assert(interfaceType.IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
2700-
Debug.Assert(!IsInterface); // VerifyInterfaceIsImplemented enforces this invariant
2700+
Debug.Assert(!IsActualInterface); // VerifyInterfaceIsImplemented enforces this invariant
27012701

27022702
// SZArrays implement the methods on IList`1, IEnumerable`1, and ICollection`1 with
27032703
// SZArrayHelper and some runtime magic. We don't have accurate interface maps for them.
@@ -2739,7 +2739,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
27392739

27402740
// If we resolved to an interface method, use the interface type as reflected type. Otherwise use `this`.
27412741
RuntimeType reflectedType = RuntimeMethodHandle.GetDeclaringType(classRtMethodHandle);
2742-
if (!reflectedType.IsInterface)
2742+
if (!reflectedType.IsActualInterface)
27432743
reflectedType = this;
27442744

27452745
// GetMethodBase will convert this to the instantiating/unboxing stub if necessary
@@ -3432,7 +3432,7 @@ internal unsafe bool IsActualEnum
34323432
}
34333433
}
34343434

3435-
internal new unsafe bool IsInterface
3435+
internal unsafe bool IsActualInterface
34363436
{
34373437
get
34383438
{

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
<Compile Include="System\MathF.NativeAot.cs" />
187187
<Compile Include="System\Object.NativeAot.cs" />
188188
<Compile Include="System\RuntimeArgumentHandle.cs" />
189-
<Compile Include="System\RuntimeType.cs" />
189+
<Compile Include="System\RuntimeType.NativeAot.cs" />
190190
<Compile Include="System\Runtime\ControlledExecution.NativeAot.cs" />
191191
<Compile Include="System\Runtime\DependentHandle.cs" />
192192
<Compile Include="System\Runtime\CompilerServices\EagerStaticClassConstructionAttribute.cs" />

src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs renamed to src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public override RuntimeTypeHandle TypeHandle
213213
}
214214
}
215215

216-
internal new unsafe bool IsInterface
216+
internal unsafe bool IsActualInterface
217217
{
218218
get
219219
{

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private void Init(string name,
269269
if (owner?.UnderlyingSystemType is RuntimeType rtOwner)
270270
{
271271
if (rtOwner.HasElementType || rtOwner.ContainsGenericParameters
272-
|| rtOwner.IsGenericParameter || rtOwner.IsInterface)
272+
|| rtOwner.IsGenericParameter || rtOwner.IsActualInterface)
273273
throw new ArgumentException(SR.Argument_InvalidTypeForDynamicMethod);
274274

275275
_typeOwner = rtOwner;

src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
297297
if (c.IsSubclassOf(this))
298298
return true;
299299

300-
if (IsInterface)
300+
if (IsActualInterface)
301301
{
302302
return c.ImplementInterface(this);
303303
}
@@ -711,7 +711,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
711711
// `class G3<T,U> where T:U where U:Stream`: typeof(G3<,>).GetGenericArguments()[0].BaseType is Object (!)
712712
private RuntimeType? GetBaseType()
713713
{
714-
if (IsInterface)
714+
if (IsActualInterface)
715715
return null;
716716

717717
if (RuntimeTypeHandle.IsGenericVariable(this))
@@ -724,7 +724,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
724724
{
725725
RuntimeType constraint = (RuntimeType)constraints[i];
726726

727-
if (constraint.IsInterface)
727+
if (constraint.IsActualInterface)
728728
continue;
729729

730730
if (constraint.IsGenericParameter)

src/libraries/System.Private.CoreLib/src/System/Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public bool IsInterface
3333
{
3434
#if !MONO
3535
if (this is RuntimeType rt)
36-
return rt.IsInterface;
36+
return rt.IsActualInterface;
3737
#endif
3838
return (GetAttributeFlagsImpl() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
3939
}

src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ protected override bool IsValueTypeImpl()
13211321
return res;
13221322
}
13231323

1324+
internal bool IsActualInterface => IsInterface;
1325+
13241326
// Returns true for actual value types only, ignoring generic parameter constraints.
13251327
internal bool IsActualValueType => RuntimeTypeHandle.IsValueType(this);
13261328

0 commit comments

Comments
 (0)