public static Type GetTypeOfContent(string xml) { CustomXmlDeserializer deserializer = new CustomXmlDeserializer(null); deserializer.doc.LoadXml(xml); string culture = deserializer.doc.DocumentElement.GetAttribute("culture"); deserializer.cult = new CultureInfo(culture); XmlElement element = deserializer.doc.DocumentElement; Type objType; string typeFullName = element.GetAttribute("type"); string assemblyFullName = element.GetAttribute("assembly"); if (string.IsNullOrEmpty(assemblyFullName)) { // type is directly loadable objType = Type.GetType(typeFullName, true); } else { Assembly asm = Assembly.Load(assemblyFullName); objType = asm.GetType(typeFullName, true); } return(objType); }
public static object Deserialize(string xml, int maxSupportedVer, ITypeConverter typeConverter, out int actualVersion) { CustomXmlDeserializer deserializer = new CustomXmlDeserializer(typeConverter); deserializer.doc.LoadXml(xml); string version = deserializer.doc.DocumentElement.GetAttribute("version"); actualVersion = Convert.ToInt32(version); if (maxSupportedVer < actualVersion) { return null; } string culture = deserializer.doc.DocumentElement.GetAttribute("culture"); deserializer.cult = new CultureInfo(culture); return deserializer.DeserializeCore(deserializer.doc.DocumentElement); }
public static T LoadFromXml <T>(string filename, int maxversion, out int actualversion) { try { // load XML document and parse it // deserialize a Test1 instance having a version number of at most maxversion T obj = (T)CustomXmlDeserializer.Deserialize(XmlFileReader.ReadXmlFile(filename).OuterXml, maxversion, out actualversion); return(obj); } catch (Exception ex) { throw new Exception("Fehler beim Lesen von Xml Datei", ex); } }
public static object Deserialize(string xml, int maxSupportedVer, ITypeConverter typeConverter, out int actualVersion) { CustomXmlDeserializer deserializer = new CustomXmlDeserializer(typeConverter); deserializer.doc.LoadXml(xml); string version = deserializer.doc.DocumentElement.GetAttribute("version"); actualVersion = Convert.ToInt32(version); if (maxSupportedVer < actualVersion) { return(null); } string culture = deserializer.doc.DocumentElement.GetAttribute("culture"); deserializer.cult = new CultureInfo(culture); return(deserializer.DeserializeCore(deserializer.doc.DocumentElement)); }
public static Type GetTypeOfContent(string xml) { CustomXmlDeserializer deserializer = new CustomXmlDeserializer(null); deserializer.doc.LoadXml(xml); string culture = deserializer.doc.DocumentElement.GetAttribute("culture"); deserializer.cult = new CultureInfo(culture); XmlElement element = deserializer.doc.DocumentElement; Type objType; string typeFullName = element.GetAttribute("type"); string assemblyFullName = element.GetAttribute("assembly"); if (string.IsNullOrEmpty(assemblyFullName)) { // type is directly loadable objType = Type.GetType(typeFullName, true); } else { Assembly asm = Assembly.Load(assemblyFullName); objType = asm.GetType(typeFullName, true); } return objType; }
public static Type GetTypeFromXml(string filename) { return(CustomXmlDeserializer.GetTypeOfContent(XmlFileReader.ReadXmlFile(filename).OuterXml)); }