System.Web.AspNetHostingPermission.FromXml C# (CSharp) Method

FromXml() public method

public FromXml ( SecurityElement securityElement ) : void
securityElement System.Security.SecurityElement
return void
        public override void FromXml(SecurityElement securityElement) {
            if (securityElement == null) {
                throw new ArgumentNullException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
            }

            if (!securityElement.Tag.Equals("IPermission")) {
                throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
            }

            string className = securityElement.Attribute("class");
            if (className == null) {
                throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
            }

            if (className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) < 0) {
                throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"securityElement"));
            }

            string version = securityElement.Attribute("version");
            if (string.Compare(version, "1", StringComparison.OrdinalIgnoreCase) != 0) {
                throw new ArgumentException(SR.GetString(SR.AspNetHostingPermissionBadXml,"version"));
            }

            string level = securityElement.Attribute("Level");
            if (level == null) {
                _level = AspNetHostingPermissionLevel.None;
            }
            else {
                _level = (AspNetHostingPermissionLevel) Enum.Parse(typeof(AspNetHostingPermissionLevel), level);
            }
        }

Usage Example

		private void CommonTests (AspNetHostingPermission p)
		{
			Assert.IsNotNull (p.Copy (), "Copy");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsNotNull (p.Intersect (p), "Intersect");
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			Assert.IsNotNull (p.Union (p), "Union");
		}
All Usage Examples Of System.Web.AspNetHostingPermission::FromXml