internal static PermissionSet Decode (IntPtr permissions, int length)
{
// Permission sets from the runtime (declarative security) can be cached
// for performance as they can never change (i.e. they are read-only).
PermissionSet ps = null;
lock (_lockObject) {
if (_declsecCache == null) {
_declsecCache = new Hashtable ();
}
object key = (object) (int) permissions;
ps = (PermissionSet) _declsecCache [key];
if (ps == null) {
// create permissionset and add it to the cache
byte[] data = new byte [length];
Marshal.Copy (permissions, data, 0, length);
ps = Decode (data);
ps.DeclarativeSecurity = true;
_declsecCache.Add (key, ps);
}
}
return ps;
}