Doing a Demand probably makes a little more sense, although not a whole lot. An alternative could be to change the Create() method to distinguish between public, private and internal access and when internal access is requested explicitly look for the InternalsVisibleToAttribute on the target assembly to see if it grants us access, but that seems like a lot of complexity for what is essentially a special case (internal access).

This commit is contained in:
jfrijters 2009-05-31 07:54:26 +00:00
Родитель 6c87412e66
Коммит 75e635dc2b
1 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -271,8 +271,6 @@ namespace IKVM.Runtime
static class DynamicMethodUtils
{
private static bool? restrictedMemberAccess;
internal static DynamicMethod Create(string name, Type owner, bool nonPublic, Type returnType, Type[] paramTypes)
{
try
@ -305,11 +303,15 @@ static class DynamicMethodUtils
{
get
{
if (!restrictedMemberAccess.HasValue)
try
{
restrictedMemberAccess = System.Security.SecurityManager.IsGranted(new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess));
new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess).Demand();
return true;
}
catch (System.Security.SecurityException)
{
return false;
}
return restrictedMemberAccess.Value;
}
}
}