当前位置: 首页>>代码示例>>C#>>正文


C# PermissionSet.SetUnrestricted方法代码示例

本文整理汇总了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();
        }
开发者ID:ArildF,项目名称:masters,代码行数:73,代码来源:permissionset.cs


注:本文中的System.Security.PermissionSet.SetUnrestricted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。