Skip to content

Commit

Permalink
Consider interface base types for IVT checks when generating proxies
Browse files Browse the repository at this point in the history
Fixes #789
  • Loading branch information
AArnott committed Jun 10, 2022
1 parent af40eb6 commit 342a4a6
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/StreamJsonRpc/SkipClrVisibilityChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ internal static ImmutableHashSet<AssemblyName> GetSkipVisibilityChecksRequiremen
CheckForNonPublicTypes(typeInfo, assembliesDeclaringInternalTypes, visitedTypes);

// Enumerate members on the interface that we're going to need to implement.
foreach (MethodInfo methodInfo in typeInfo.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
foreach (TypeInfo iteratedTypeInfo in ThisAndBaseTypes(typeInfo))
{
CheckForNonPublicTypes(methodInfo.ReturnType.GetTypeInfo(), assembliesDeclaringInternalTypes, visitedTypes);
foreach (ParameterInfo parameter in methodInfo.GetParameters())
foreach (MethodInfo methodInfo in iteratedTypeInfo.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
CheckForNonPublicTypes(parameter.ParameterType.GetTypeInfo(), assembliesDeclaringInternalTypes, visitedTypes);
CheckForNonPublicTypes(methodInfo.ReturnType.GetTypeInfo(), assembliesDeclaringInternalTypes, visitedTypes);
foreach (ParameterInfo parameter in methodInfo.GetParameters())
{
CheckForNonPublicTypes(parameter.ParameterType.GetTypeInfo(), assembliesDeclaringInternalTypes, visitedTypes);
}
}
}

Expand Down Expand Up @@ -131,6 +134,25 @@ internal void SkipVisibilityChecksFor(AssemblyName assemblyName)
}
}

private static IEnumerable<TypeInfo> ThisAndBaseTypes(TypeInfo startingPoint)
{
if (startingPoint.IsInterface)
{
yield return startingPoint.GetTypeInfo();
foreach (Type iface in startingPoint.GetInterfaces())
{
yield return iface.GetTypeInfo();
}
}
else
{
for (TypeInfo? t = startingPoint.GetTypeInfo(); t is not null && t != typeof(object).GetTypeInfo(); t = t.BaseType?.GetTypeInfo())
{
yield return t;
}
}
}

private static void CheckForNonPublicTypes(TypeInfo typeInfo, ImmutableHashSet<AssemblyName>.Builder assembliesDeclaringInternalTypes, HashSet<TypeInfo> visitedTypes)
{
Requires.NotNull(typeInfo, nameof(typeInfo));
Expand Down

0 comments on commit 342a4a6

Please sign in to comment.