public static string GetXml <T>(List <T> liValues, string parentRoot, string childRoot) { XDocument xDoc = new XDocument(); var partentRoot = new XElement(parentRoot); foreach (T genType in liValues) { PropertyInfo[] propInfo = genType.GetType().GetProperties(); var childroot = new XElement(childRoot); foreach (PropertyInfo prop in propInfo) { if (prop.PropertyType.FullName.ToUpper() == typeof(System.String).ToString().ToUpper() || prop.PropertyType.FullName.ToUpper() == typeof(System.Int32).ToString().ToUpper() || prop.PropertyType.FullName.ToUpper() == typeof(System.Double).ToString().ToUpper()) { if (prop.Name.ToLower() != "parentrootnode" && prop.Name.ToLower() != "parentnode" && prop.Name.ToLower() != "childnode") { if (!string.IsNullOrEmpty(string.Format("{0}", prop.GetValue(genType, null)))) { childroot.SetAttributeValue(prop.Name, GTKString.ToEscapeSpecialChars(prop.GetValue(genType, null).ToString())); } } } } partentRoot.Add(childroot); } xDoc.Add(partentRoot); return(xDoc.ToString()); }
/// <summary> /// GetEntityXml /// </summary> /// <typeparam name="T"></typeparam> /// <param name="genClass"></param> /// <param name="RootNode"></param> /// <returns></returns> public static XElement GetEntityXml <T>(T genClass, string childRoot) { XDocument xDoc = new XDocument(); PropertyInfo[] propInfo = genClass.GetType().GetProperties(); var childroot = new XElement(childRoot); foreach (PropertyInfo prop in propInfo) { if (prop.Name.ToLower() != "parentrootnode" && prop.Name.ToLower() != "parentnode" && prop.Name.ToLower() != "childnode") { if (!string.IsNullOrEmpty(string.Format("{0}", prop.GetValue(genClass, null)))) { childroot.SetAttributeValue(prop.Name, GTKString.ToEscapeSpecialChars(prop.GetValue(genClass, null).ToString())); } } } // xDoc.Add(childroot); return(childroot); }