Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closure #693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Castle.Core/DynamicProxy/Internal/InvocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static MethodInfo GetMethodOnType(Type type, MethodInfo proxiedMethod)

var cacheKey = new CacheKey(proxiedMethod, type);

return cache.GetOrAdd(cacheKey, ck => ObtainMethod(proxiedMethod, type));
return cache.GetOrAdd(cacheKey, static ck => ObtainMethod(ck.Method, ck.Type));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Theoretically generated code could be reduced by changing ObtainMethod such that it accepts a single CacheKey argument, then it could be used directly here in place of the lambda function wrapping it. But that's a different refactoring perhaps for another time.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean method group? I don't mind doing that if you like.

Copy link
Member

@stakx stakx Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, yes. I meant replacing the whole ck => ObtainMethod(ck.Method, ck.Type) with just ObtainMethod, which might be possible if that method were made to accept a singleCacheKey argument instead of two. But I just mentioned in it passing, no need to change that.

}

private static MethodInfo ObtainMethod(MethodInfo proxiedMethod, Type type)
Expand Down
4 changes: 2 additions & 2 deletions src/Castle.Core/DynamicProxy/ProxyUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public static bool IsAccessible(Type type)
/// <param name="asm">The assembly to inspect.</param>
internal static bool AreInternalsVisibleToDynamicProxy(Assembly asm)
{
return internalsVisibleToDynamicProxy.GetOrAdd(asm, a =>
return internalsVisibleToDynamicProxy.GetOrAdd(asm, static a =>
{
var internalsVisibleTo = asm.GetCustomAttributes<InternalsVisibleToAttribute>();
var internalsVisibleTo = a.GetCustomAttributes<InternalsVisibleToAttribute>();
return internalsVisibleTo.Any(attr => attr.AssemblyName.Contains(ModuleScope.DEFAULT_ASSEMBLY_NAME));
});
}
Expand Down
Loading