Пример #1
0
        public static XmlSerializableObject Load(System.IO.Stream stream, Type objectType, bool useSoapSerialization)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            object o;

            if (useSoapSerialization)
            {
                SoapFormatter Serializer = new SoapFormatter();

                o = Serializer.Deserialize(stream);
            }
            else
            {
                XmlSerializer Serializer = new XmlSerializer(objectType);

                o = Serializer.Deserialize(stream);
            }
            stream.Flush();
            stream.Close();
            XmlSerializableObject result = ((XmlSerializableObject)o);

            result.OnLoaded();
            return(result);
        }
Пример #2
0
        public static XmlSerializableObject Load(string fileName, Type objectType, bool useSoapSerialization)
        {
            if (System.IO.File.Exists(fileName))
            {
                FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                XmlSerializableObject res = Load(fileStream, objectType, useSoapSerialization);
                fileStream.Dispose();
                return(res);
            }
            throw new System.ArgumentException("File " + fileName + " not found", "fileName");
        }