/// <summary>Creates an XML encoding of the security object, its current state, and the policy level within which the code exists.</summary> /// <returns>An XML encoding of the security object, including any state information.</returns> /// <param name="level">The policy level within which the code group exists. </param> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public SecurityElement ToXml(PolicyLevel level) { SecurityElement securityElement = new SecurityElement("CodeGroup"); securityElement.AddAttribute("class", base.GetType().AssemblyQualifiedName); securityElement.AddAttribute("version", "1"); if (this.Name != null) { securityElement.AddAttribute("Name", this.Name); } if (this.Description != null) { securityElement.AddAttribute("Description", this.Description); } if (this.MembershipCondition != null) { securityElement.AddChild(this.MembershipCondition.ToXml()); } if (this.PolicyStatement != null && this.PolicyStatement.PermissionSet != null) { securityElement.AddChild(this.PolicyStatement.PermissionSet.ToXml()); } foreach (object obj in this.Children) { CodeGroup codeGroup = (CodeGroup)obj; securityElement.AddChild(codeGroup.ToXml()); } this.CreateXml(securityElement, level); return(securityElement); }
public SecurityElement ToXml() { Hashtable fullNames = new Hashtable(); // only StrongNameMembershipCondition so no need to loop if (full_trust_assemblies.Count > 0) { if (!fullNames.Contains("StrongNameMembershipCondition")) { fullNames.Add("StrongNameMembershipCondition", typeof(StrongNameMembershipCondition).FullName); } } SecurityElement namedPSs = new SecurityElement("NamedPermissionSets"); foreach (NamedPermissionSet nps in named_permission_sets) { SecurityElement se = nps.ToXml(); object objectClass = se.Attributes ["class"]; if (!fullNames.Contains(objectClass)) { fullNames.Add(objectClass, nps.GetType().FullName); } namedPSs.AddChild(se); } SecurityElement fta = new SecurityElement("FullTrustAssemblies"); foreach (StrongNameMembershipCondition snmc in full_trust_assemblies) { fta.AddChild(snmc.ToXml(this)); } SecurityElement security_classes = new SecurityElement("SecurityClasses"); if (fullNames.Count > 0) { foreach (DictionaryEntry de in fullNames) { SecurityElement sc = new SecurityElement("SecurityClass"); sc.AddAttribute("Name", (string)de.Key); sc.AddAttribute("Description", (string)de.Value); security_classes.AddChild(sc); } } SecurityElement element = new SecurityElement(typeof(System.Security.Policy.PolicyLevel).Name); element.AddAttribute("version", "1"); element.AddChild(security_classes); element.AddChild(namedPSs); if (root_code_group != null) { element.AddChild(root_code_group.ToXml(this)); } element.AddChild(fta); return(element); }