public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.PublisherIdentityPermission"); if (m_unrestricted) { esd.AddAttribute("Unrestricted", "true"); } else if (m_certs != null) { if (m_certs.Length == 1) { esd.AddAttribute("X509v3Certificate", m_certs[0].GetRawCertDataString()); } else { int n; for (n = 0; n < m_certs.Length; n++) { SecurityElement child = new SecurityElement("Cert"); child.AddAttribute("X509v3Certificate", m_certs[n].GetRawCertDataString()); esd.AddChild(child); } } } return(esd); }
public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.ZoneIdentityPermission"); if (SecurityZone != SecurityZone.NoZone) { esd.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), this.SecurityZone)); } else { int nEnum = 0; uint nFlag; for (nFlag = 1; nFlag < AllZones; nFlag <<= 1) { if ((m_zones & nFlag) != 0) { SecurityElement child = new SecurityElement("Zone"); child.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), (SecurityZone)nEnum)); esd.AddChild(child); } nEnum++; } } return(esd); }
public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.SiteIdentityPermission"); if (m_unrestricted) { esd.AddAttribute("Unrestricted", "true"); } else if (m_sites != null) { if (m_sites.Length == 1) { esd.AddAttribute("Site", m_sites[0].ToString()); } else { int n; for (n = 0; n < m_sites.Length; n++) { SecurityElement child = new SecurityElement("Site"); child.AddAttribute("Site", m_sites[n].ToString()); esd.AddChild(child); } } } return(esd); }
private static void SaveXML(object config, string path) { var root = new System.Security.SecurityElement("root"); root.AddChild(new System.Security.SecurityElement("record")); var xml = root.Children[0] as System.Security.SecurityElement; var props = config.GetType().GetProperties(); foreach (var item in props) { if (item.Name.Contains("GuideTimes")) { //dictonary var temp = item.GetGetMethod().Invoke(config, null); string value = ""; foreach (var v in temp as Dictionary <ulong, string> ) { value = value + v.Key.ToString() + ":" + v.Value + ","; } xml.AddChild(new System.Security.SecurityElement(item.Name, value)); } else { var value = item.GetGetMethod().Invoke(config, null); xml.AddChild(new System.Security.SecurityElement(item.Name, value.ToString())); } } XMLParser.SaveText(path, root.ToString()); }
internal SecurityElement ToXml() { SecurityElement e = new SecurityElement("PublicKeyBlob"); e.AddChild(new SecurityElement("Key", Hex.EncodeHexString(PublicKey))); return(e); }
/// <summary> /// Recupera os dados do xml. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static System.Security.SecurityElement FromXml(System.Xml.XmlReader reader) { var element = new System.Security.SecurityElement(reader.Name); for (var i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); element.AddAttribute(reader.Name, reader.Value); } reader.MoveToContent(); if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { var child = FromXml(reader); element.AddChild(child); } reader.ReadEndElement(); } else { reader.Skip(); } return(element); }
public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.StrongNameIdentityPermission"); if (m_unrestricted) { esd.AddAttribute("Unrestricted", "true"); } else if (m_strongNames != null) { if (m_strongNames.Length == 1) { if (m_strongNames[0].m_publicKeyBlob != null) { esd.AddAttribute("PublicKeyBlob", Hex.EncodeHexString(m_strongNames[0].m_publicKeyBlob.PublicKey)); } if (m_strongNames[0].m_name != null) { esd.AddAttribute("Name", m_strongNames[0].m_name); } if ((Object)m_strongNames[0].m_version != null) { esd.AddAttribute("AssemblyVersion", m_strongNames[0].m_version.ToString()); } } else { int n; for (n = 0; n < m_strongNames.Length; n++) { SecurityElement child = new SecurityElement("StrongName"); if (m_strongNames[n].m_publicKeyBlob != null) { child.AddAttribute("PublicKeyBlob", Hex.EncodeHexString(m_strongNames[n].m_publicKeyBlob.PublicKey)); } if (m_strongNames[n].m_name != null) { child.AddAttribute("Name", m_strongNames[n].m_name); } if ((Object)m_strongNames[n].m_version != null) { child.AddAttribute("AssemblyVersion", m_strongNames[n].m_version.ToString()); } esd.AddChild(child); } } } return(esd); }
/// <include file='doc\PrincipalPermission.uex' path='docs/doc[@for="PrincipalPermission.ToXml"]/*' /> public SecurityElement ToXml() { SecurityElement root = new SecurityElement("Permission"); XMLUtil.AddClassAttribute(root, this.GetType()); root.AddAttribute("version", "1"); int count = m_array.Length; for (int i = 0; i < count; ++i) { root.AddChild(m_array[i].ToXml()); } return(root); }
public SecurityElement ToXml() { SecurityElement root = new SecurityElement("IPermission"); XMLUtil.AddClassAttribute(root, this.GetType(), "System.Security.Permissions.PrincipalPermission"); // 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("System.Security.Permissions.PrincipalPermission"), "Class name changed!"); root.AddAttribute("version", "1"); int count = m_array.Length; for (int i = 0; i < count; ++i) { root.AddChild(m_array[i].ToXml()); } return(root); }
private static void SaveXMLList <T>(string path, List <T> data, string attrName = "record") { var root = new System.Security.SecurityElement("root"); var i = 0; var props = typeof(T).GetProperties(); foreach (var item in data) { var xml = new System.Security.SecurityElement(attrName); foreach (var prop in props) { var type = prop.PropertyType; String result = String.Empty; object obj = prop.GetGetMethod().Invoke(item, null); //var obj = prop.GetValue(item, null); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { result = typeof(Utils).GetMethod("PackMap") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, ':', ',' }).ToString(); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { result = typeof(Utils).GetMethod("PackList") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, ',' }).ToString(); } else { result = obj.ToString(); } xml.AddChild(new System.Security.SecurityElement(prop.Name, result)); } root.AddChild(xml); i++; } XMLParser.SaveText(path, root.ToString()); }
public SecurityElement ToXml() { SecurityElement root = new SecurityElement( "IPermission" ); XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Permissions.PrincipalPermission" ); // 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( "System.Security.Permissions.PrincipalPermission" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); int count = m_array.Length; for (int i = 0; i < count; ++i) { root.AddChild( m_array[i].ToXml() ); } return root; }
/// <include file='doc\PrincipalPermission.uex' path='docs/doc[@for="PrincipalPermission.ToXml"]/*' /> public SecurityElement ToXml() { SecurityElement root = new SecurityElement( "Permission" ); XMLUtil.AddClassAttribute( root, this.GetType() ); root.AddAttribute( "version", "1" ); int count = m_array.Length; for (int i = 0; i < count; ++i) { root.AddChild( m_array[i].ToXml() ); } return root; }
// 可以扩展成递归模式,多个类型嵌套的 public static void SaveXML <T>(string path, List <T> data) { var root = new System.Security.SecurityElement("root"); string attrName = typeof(T).Name; var props = typeof(T).GetProperties(); var keyProp = props[0]; foreach (var prop in props) { if (XmlData.mKeyFieldName == prop.Name) { keyProp = prop; break; } } foreach (var item in data) { // 下面在LoadXML时,key id必须先加载,所以这里第一个创建 id var xml = new System.Security.SecurityElement(attrName); object obj = keyProp.GetGetMethod().Invoke(item, null); xml.AddChild(new System.Security.SecurityElement(keyProp.Name, obj.ToString())); foreach (var prop in props) { if (prop == keyProp) { continue; } var type = prop.PropertyType; String result = String.Empty; obj = prop.GetGetMethod().Invoke(item, null); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { result = typeof(XmlFileUtils).GetMethod("PackMap") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, KEY_VALUE_SPRITER, MAP_SPRITER }).ToString(); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { result = typeof(XmlFileUtils).GetMethod("PackList") .MakeGenericMethod(type.GetGenericArguments()) .Invoke(null, new object[] { obj, LIST_SPRITER }).ToString(); } else if (type.BaseType == typeof(Enum)) { Type underType = Enum.GetUnderlyingType(type); if (underType == typeof(Int32)) { obj = EnumConvertUtils.EnumToInt(obj) + ""; } result = obj.ToString(); } else { result = obj.ToString(); } xml.AddChild(new System.Security.SecurityElement(prop.Name, result)); } root.AddChild(xml); } XMLParser.SaveText(path, root.ToString()); }
internal SecurityElement ToXml() { SecurityElement e = new SecurityElement( "PublicKeyBlob" ); e.AddChild( new SecurityElement( "Key", Hex.EncodeHexString( PublicKey ) ) ); return e; }