Skip to content

Commit

Permalink
Remove redundant accessibility checks from AcceptMethodPreScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Sep 9, 2023
1 parent 27016b7 commit c662c90
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/Castle.Core/DynamicProxy/Contributors/MembersCollector.cs
Expand Up @@ -178,10 +178,7 @@ protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerati
/// </remarks>
protected bool AcceptMethodPreScreen(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
{
if (IsInternalAndNotVisibleToDynamicProxy(method))
{
return false;
}
// NOTE: at this point, the method's accessibility should already have been checked (see `AddMethod` above)

var isOverridable = method.IsVirtual && !method.IsFinal;
if (onlyVirtuals && !isOverridable)
Expand All @@ -205,12 +202,6 @@ protected bool AcceptMethodPreScreen(MethodInfo method, bool onlyVirtuals, IProx
return false;
}

//can only proxy methods that are public or protected (or internals that have already been checked above)
if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly || method.IsFamilyAndAssembly) == false)
{
return false;
}

if (method.DeclaringType == typeof(MarshalByRefObject))
{
return false;
Expand All @@ -223,11 +214,5 @@ protected bool AcceptMethodPreScreen(MethodInfo method, bool onlyVirtuals, IProx

return true;
}

private static bool IsInternalAndNotVisibleToDynamicProxy(MethodInfo method)
{
return ProxyUtil.IsInternal(method) &&
ProxyUtil.AreInternalsVisibleToDynamicProxy(method.DeclaringType.Assembly) == false;
}
}
}

0 comments on commit c662c90

Please sign in to comment.