예제 #1
0
        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);
        }
예제 #2
0
 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);
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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));
        }
예제 #5
0
 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;
 }
예제 #6
0
 public static Type GetTypeFromXml(string filename)
 {
     return(CustomXmlDeserializer.GetTypeOfContent(XmlFileReader.ReadXmlFile(filename).OuterXml));
 }