Skip to content

Commit 9372d96

Browse files
author
Per Gårdebrink
committed
Allow types with explicitly defined interface implementations
1 parent 7417513 commit 9372d96

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/CommandLine/Core/ReflectionExtensions.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,21 @@ public static bool IsMutable(this Type type)
133133
if(type == typeof(object))
134134
return true;
135135

136-
var props = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.CanWrite);
137-
var fields = type.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Any();
136+
// Find all inherited defined properties and fields on the type
137+
var inheritedTypes = type.GetTypeInfo().FlattenHierarchy().Select(i => i.GetTypeInfo());
138138

139-
return props || fields;
139+
foreach (var inheritedType in inheritedTypes)
140+
{
141+
if (
142+
inheritedType.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.CanWrite) ||
143+
inheritedType.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Any()
144+
)
145+
{
146+
return true;
147+
}
148+
}
149+
150+
return false;
140151
}
141152

142153
public static object CreateDefaultForImmutable(this Type type)

0 commit comments

Comments
 (0)