Skip to content

Commit 27016b7

Browse files
committed
Optimize ProxyUtil.IsAccessibleMethod
1 parent 1273d4e commit 27016b7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Castle.Core/DynamicProxy/ProxyUtil.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,20 @@ internal static bool IsAccessibleType(Type target)
194194
/// <returns><c>true</c> if the method is accessible to DynamicProxy, <c>false</c> otherwise.</returns>
195195
internal static bool IsAccessibleMethod(MethodBase method)
196196
{
197-
if (method.IsPublic || method.IsFamily || method.IsFamilyOrAssembly)
197+
switch (method.Attributes & MethodAttributes.MemberAccessMask)
198198
{
199-
return true;
200-
}
199+
case MethodAttributes.Assembly:
200+
case MethodAttributes.FamANDAssem:
201+
return AreInternalsVisibleToDynamicProxy(method.DeclaringType.Assembly);
201202

202-
if (method.IsAssembly || method.IsFamilyAndAssembly)
203-
{
204-
return AreInternalsVisibleToDynamicProxy(method.DeclaringType.Assembly);
205-
}
203+
case MethodAttributes.Family:
204+
case MethodAttributes.FamORAssem:
205+
case MethodAttributes.Public:
206+
return true;
206207

207-
return false;
208+
default: // `MethodAttributes.Private` or `MethodAttributes.PrivateScope`
209+
return false;
210+
}
208211
}
209212

210213
/// <summary>

0 commit comments

Comments
 (0)