Return to Snippet

Revision: 39441
at January 18, 2011 00:36 by jalalx


Initial Code
public static T XmlDeserialize<T>(string filename)
        {

            T o = default(T);
            try
            {
                XmlReader reader = XmlReader.Create(filename);
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                if (serializer.CanDeserialize(reader))
                {
                    o = (T)serializer.Deserialize(reader);
                }
                reader.Close();
            }
            catch
            {
            }
            finally
            {
            }
            return o;
        }

Initial URL

                                

Initial Description
Deserialize an XML object to an T type.

Initial Title
Xml Deserializer

Initial Tags
xml

Initial Language
C#