예제 #1
0
        public override void FromXml(SecurityElement elem)
        {
            if (elem == null)
            {
                throw new ArgumentNullException("elem");
            }
            if (elem.Tag != XmlConstants.IPermission)
            {
                throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedTag, elem.Tag, XmlConstants.IPermission), "elem");
            }

            string className = elem.Attribute(XmlConstants.Class);

            if (!className.StartsWith(GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))
            {
                throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedValue, className, XmlConstants.Class, GetType().FullName), "elem");
            }

            string version = elem.Attribute(XmlConstants.Version);

            if (version != null && version != XmlConstants.VersionNumber)
            {
                throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedValue, className, XmlConstants.Version, XmlConstants.VersionNumber), "elem");
            }

            string unrestricted = elem.Attribute(XmlConstants.Unrestricted);

            if (unrestricted != null && bool.Parse(unrestricted))
            {
                Init(true, null);
            }
            else
            {
                List <XamlAccessLevel> allowedAccess = null;
                if (elem.Children != null)
                {
                    allowedAccess = new List <XamlAccessLevel>(elem.Children.Count);
                    foreach (SecurityElement child in elem.Children)
                    {
                        allowedAccess.Add(XamlAccessLevel.FromXml(child));
                    }
                }
                Init(false, allowedAccess);
            }
        }
예제 #2
0
        public override void FromXml(SecurityElement elem)
        {
            if (elem == null)
            {
                throw new ArgumentNullException("elem");
            }
            if (elem.Tag != "IPermission")
            {
                throw new ArgumentException(System.Xaml.SR.Get("SecurityXmlUnexpectedTag", new object[] { elem.Tag, "IPermission" }), "elem");
            }
            string str = elem.Attribute("class");

            if (!str.StartsWith(base.GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))
            {
                throw new ArgumentException(System.Xaml.SR.Get("SecurityXmlUnexpectedValue", new object[] { str, "class", base.GetType().FullName }), "elem");
            }
            string str2 = elem.Attribute("version");

            if ((str2 != null) && (str2 != "1"))
            {
                throw new ArgumentException(System.Xaml.SR.Get("SecurityXmlUnexpectedValue", new object[] { str, "version", "1" }), "elem");
            }
            string str3 = elem.Attribute("Unrestricted");

            if ((str3 != null) && bool.Parse(str3))
            {
                this.Init(true, null);
            }
            else
            {
                List <XamlAccessLevel> allowedAccess = null;
                if (elem.Children != null)
                {
                    allowedAccess = new List <XamlAccessLevel>(elem.Children.Count);
                    foreach (SecurityElement element in elem.Children)
                    {
                        allowedAccess.Add(XamlAccessLevel.FromXml(element));
                    }
                }
                this.Init(false, allowedAccess);
            }
        }