コード例 #1
0
ファイル: CodeGroup.cs プロジェクト: ForNeVeR/pnet
        public SecurityElement ToXml(PolicyLevel level)
        {
            SecurityElement element;

            element = new SecurityElement("CodeGroup");
            element.AddAttribute
                ("class",
                SecurityElement.Escape(GetType().AssemblyQualifiedName));
            element.AddAttribute("version", "1");
            element.AddChild(membershipCondition.ToXml(level));
            if (policy != null)
            {
                PermissionSet permSet = policy.PermissionSetNoCopy;
                if (permSet is NamedPermissionSet && level != null &&
                    level.GetNamedPermissionSet
                        (((NamedPermissionSet)permSet).Name) != null)
                {
                    element.AddAttribute
                        ("PermissionSetName",
                        ((NamedPermissionSet)permSet).Name);
                }
                else if (!permSet.IsEmpty())
                {
                    element.AddChild(permSet.ToXml());
                }
                if (policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    element.AddAttribute
                        ("Attributes", policy.Attributes.ToString());
                }
                foreach (CodeGroup group in Children)
                {
                    element.AddChild(group.ToXml(level));
                }
            }
            if (name != null)
            {
                element.AddAttribute("Name", SecurityElement.Escape(name));
            }
            if (description != null)
            {
                element.AddAttribute
                    ("Description", SecurityElement.Escape(description));
            }
            CreateXml(element, level);
            return(element);
        }
コード例 #2
0
        [System.Security.SecurityCritical]  // auto-generated
        internal SecurityElement ToXml(PolicyLevel level, String policyClassName)
        {
            if (m_membershipCondition == null && m_element != null)
            {
                ParseMembershipCondition();
            }

            if (m_children == null)
            {
                ParseChildren();
            }

            if (m_policy == null && m_element != null)
            {
                ParsePolicy();
            }

            SecurityElement e = new SecurityElement("CodeGroup");

            System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType(), policyClassName);
            // If you hit this assert then most likely you are trying to change the name of this class.
            // This is ok as long as you change the hard coded string above and change the assert below.
            Contract.Assert(this.GetType().FullName.Equals(policyClassName), "Incorrect class name passed in! Was: " + policyClassName + " Should be " + this.GetType().FullName);

            e.AddAttribute("version", "1");

            e.AddChild(m_membershipCondition.ToXml(level));

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.

            if (m_policy != null)
            {
                PermissionSet      permSet      = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null)
                {
                    e.AddAttribute("PermissionSetName", namedPermSet.Name);
                }
                else
                {
                    if (!permSet.IsEmpty())
                    {
                        e.AddChild(permSet.ToXml());
                    }
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes));
                }
            }

            if (m_children.Count > 0)
            {
                lock (this)
                {
                    IEnumerator enumerator = m_children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        e.AddChild(((CodeGroup)enumerator.Current).ToXml(level));
                    }
                }
            }

            if (m_name != null)
            {
                e.AddAttribute("Name", SecurityElement.Escape(m_name));
            }

            if (m_description != null)
            {
                e.AddAttribute("Description", SecurityElement.Escape(m_description));
            }

            CreateXml(e, level);

            return(e);
        }
コード例 #3
0
        /// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.ToXml1"]/*' />
        public SecurityElement ToXml(PolicyLevel level)
        {
            if (m_membershipCondition == null && m_element != null)
            {
                ParseMembershipCondition();
            }

            if (m_children == null)
            {
                ParseChildren();
            }

            if (m_policy == null && m_element != null)
            {
                ParsePolicy();
            }

            SecurityElement e = new SecurityElement("CodeGroup");

            System.Security.Util.XMLUtil.AddClassAttribute(e, this.GetType());
            e.AddAttribute("version", "1");

            e.AddChild(m_membershipCondition.ToXml(level));

            // Grab the inerts of the policy statement's xml and just stick it
            // into the code group xml directly. We do this to hide the policy statement from
            // users in the config file.

            if (m_policy != null)
            {
                PermissionSet      permSet      = m_policy.GetPermissionSetNoCopy();
                NamedPermissionSet namedPermSet = permSet as NamedPermissionSet;

                if (namedPermSet != null && level != null && level.GetNamedPermissionSetInternal(namedPermSet.Name) != null)
                {
                    e.AddAttribute("PermissionSetName", namedPermSet.Name);
                }
                else
                {
                    if (!permSet.IsEmpty())
                    {
                        e.AddChild(permSet.ToXml());
                    }
                }

                if (m_policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_policy.Attributes));
                }
            }

            if (m_children.Count > 0)
            {
                lock (this)
                {
                    IEnumerator enumerator = m_children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        e.AddChild(((CodeGroup)enumerator.Current).ToXml(level));
                    }
                }
            }

            if (m_name != null)
            {
                e.AddAttribute("Name", SecurityElement.Escape(m_name));
            }

            if (m_description != null)
            {
                e.AddAttribute("Description", SecurityElement.Escape(m_description));
            }

            CreateXml(e, level);

            return(e);
        }