public void FromXml_WrongVersion() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); se.Attributes.Remove("version"); se.Attributes.Add("version", "2"); dp.FromXml(se); }
public void FromXml_NoVersion() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", se.Attribute("class")); dp.FromXml(w); }
public void FromXml_WrongTagCase() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); se.Tag = "IPERMISSION"; // instead of IPermission dp.FromXml(se); // note: normally IPermission classes (in corlib) DO care about the // IPermission tag }
public void FromXml_WrongTag() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); se.Tag = "IMono"; dp.FromXml(se); // note: normally IPermission classes (in corlib) DO care about the // IPermission tag }
// <Snippet1> public void ConstructDnsPermission() { try { // Create a DnsPermission instance. DnsPermission permission = new DnsPermission(PermissionState.None); // Create a SecurityElement instance by calling the ToXml method on the // DnsPermission instance. // Print its attributes, which hold the XML encoding of the DnsPermission // instance. Console.WriteLine("Attributes and Values of 'DnsPermission' instance :"); PrintKeysAndValues(permission.ToXml().Attributes); // Create a SecurityElement instance. SecurityElement securityElementObj = new SecurityElement("IPermission"); // Add attributes and values of the SecurityElement instance corresponding to // the permission instance. securityElementObj.AddAttribute("version", "1"); securityElementObj.AddAttribute("Unrestricted", "true"); securityElementObj.AddAttribute("class", "System.Net.DnsPermission"); // Reconstruct a DnsPermission instance from an XML encoding. DnsPermission permission1 = new DnsPermission(PermissionState.None); permission1.FromXml(securityElementObj); // Print the attributes and values of the constructed DnsPermission object. Console.WriteLine("After reconstruction Attributes and Values of new DnsPermission instance :"); PrintKeysAndValues(permission1.ToXml().Attributes); } catch (NullReferenceException e) { Console.WriteLine("NullReferenceException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch (SecurityException e) { Console.WriteLine("SecurityException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch (Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } }
public void FromXml_NoClass() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("version", se.Attribute("version")); dp.FromXml(w); // note: normally IPermission classes (in corlib) DO NOT care about // attribute "class" name presence in the XML }
public void FromXml_WrongClass() { DnsPermission dp = new DnsPermission(PermissionState.None); SecurityElement se = dp.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", "Wrong" + se.Attribute("class")); w.AddAttribute("version", se.Attribute("version")); dp.FromXml(w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void FromXml_Null() { DnsPermission dp = new DnsPermission(PermissionState.None); dp.FromXml(null); }