本文整理汇总了C#中System.Security.PermissionSet.SetUnrestricted方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.SetUnrestricted方法的具体用法?C# PermissionSet.SetUnrestricted怎么用?C# PermissionSet.SetUnrestricted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.PermissionSet
的用法示例。
在下文中一共展示了PermissionSet.SetUnrestricted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSerialized
// Internal routine used to create a temporary permission set (given a
// set of security attribute classes as input) and return the serialized
// version. May actually return two sets, split into CAS and non-CAS
// variants.
private static byte[] CreateSerialized(Object[] attrs, ref byte[] nonCasBlob)
{
// Create two new (empty) sets.
PermissionSet casPset = new PermissionSet(false);
PermissionSet nonCasPset = new PermissionSet(false);
// Most security attributes generate a single permission. The
// PermissionSetAttribute class generates an entire permission set we
// need to merge, however.
for (int i = 0; i < attrs.Length; i++)
if (attrs[i] is PermissionSetAttribute)
{
PermissionSet pset = null;
pset = ((PermissionSetAttribute)attrs[i]).CreatePermissionSet();
if (pset == null)
{
throw new ArgumentException( Environment.GetResourceString( "Argument_UnableToGeneratePermissionSet" ) );
}
if (pset.m_normalPermSet != null)
{
for (int j = 0; j <= pset.m_normalPermSet.GetMaxUsedIndex(); ++j)
{
IPermission perm = (IPermission)pset.m_normalPermSet.GetItem(j);
if (perm != null)
{
if (perm is CodeAccessPermission)
casPset.AddPermission(perm);
else
nonCasPset.AddPermission(perm);
}
}
}
if (pset.IsUnrestricted())
casPset.SetUnrestricted(true);
if (pset.m_unrestrictedPermSet != null)
{
for (int j = 0; j <= pset.m_unrestrictedPermSet.GetMaxUsedIndex(); ++j)
{
IPermission perm = (IPermission)pset.m_unrestrictedPermSet.GetItem(j);
if (perm != null)
{
if (perm is CodeAccessPermission)
casPset.AddPermission(perm);
else
nonCasPset.AddPermission(perm);
}
}
}
}
else
{
IPermission perm = ((SecurityAttribute)attrs[i]).CreatePermission();
if (perm is CodeAccessPermission)
casPset.AddPermission(perm);
else
nonCasPset.AddPermission(perm);
}
// Serialize the set(s).
if (!nonCasPset.IsEmpty())
nonCasBlob = nonCasPset.EncodeXml();
return casPset.IsEmpty() ? null : casPset.EncodeXml();
}