コード例 #1
0
 public static T Xml <T>(this SerializationExtensionPoint <T> extensionPoint, string path)
 {
     using (var stream = File.OpenRead(path))
     {
         return(Xml(extensionPoint, stream));
     }
 }
コード例 #2
0
 public static void Xml <T>(this SerializationExtensionPoint <T> extensionPoint, string path, T value)
 {
     using (var stream = File.OpenWrite(path))
     {
         Xml(extensionPoint, stream, value);
     }
 }
コード例 #3
0
        public void Type()
        {
            var extensionPoint = new SerializationExtensionPoint<object>(typeof(int));

            Assert.Null(extensionPoint.ExtendedValue);
            Assert.Same(typeof(int), extensionPoint.ExtendedType);
        }
コード例 #4
0
        public void Type()
        {
            var extensionPoint = new SerializationExtensionPoint <object>(typeof(int));

            Assert.Null(extensionPoint.ExtendedValue);
            Assert.Same(typeof(int), extensionPoint.ExtendedType);
        }
コード例 #5
0
        public void Instance()
        {
            int instance = 1;
            var extensionPoint = new SerializationExtensionPoint<int>(instance);

            Assert.Equal(instance, extensionPoint.ExtendedValue);
            Assert.Equal(typeof(int), extensionPoint.ExtendedType);
        }
コード例 #6
0
        public void Instance()
        {
            int instance       = 1;
            var extensionPoint = new SerializationExtensionPoint <int>(instance);

            Assert.Equal(instance, extensionPoint.ExtendedValue);
            Assert.Equal(typeof(int), extensionPoint.ExtendedType);
        }
コード例 #7
0
        public static T Binary <T>(this SerializationExtensionPoint <T> extensionPoint, byte[] data)
        {
            var serializer = new BinaryFormatter();

            using (var stream = new MemoryStream(data))
            {
                return((T)serializer.Deserialize(stream));
            }
        }
コード例 #8
0
 public static void Binary <T>(this SerializationExtensionPoint <T> extensionPoint, Stream output)
 {
     if (extensionPoint.ExtendedValue != null)
     {
         var serializer = new BinaryFormatter();
         serializer.Serialize(output, extensionPoint.ExtendedValue);
         output.Flush();
     }
 }
コード例 #9
0
        public static T Xml <T>(this SerializationExtensionPoint <T> extensionPoint)
        {
            using (var stream = new MemoryStream())
            {
                Xml(extensionPoint, stream, extensionPoint.ExtendedValue);

                stream.Position = 0;

                return(Xml(extensionPoint, stream));
            }
        }
コード例 #10
0
        public static T Binary <T>(this SerializationExtensionPoint <T> extensionPoint)
        {
            var serializer = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, extensionPoint.ExtendedValue);

                stream.Position = 0;

                var newInstance = (T)serializer.Deserialize(stream);

                return(newInstance);
            }
        }
コード例 #11
0
        public static T DataContract <T>(this SerializationExtensionPoint <T> extensionPoint)
        {
            var serializer = new DataContractSerializer(extensionPoint.ExtendedType);

            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, extensionPoint.ExtendedValue);

                stream.Position = 0;

                var newInstance = (T)serializer.ReadObject(stream);

                return(newInstance);
            }
        }
コード例 #12
0
        public static void Xml <T>(this SerializationExtensionPoint <T> extensionPoint, Stream stream, T value)
        {
            var serializer = new XmlSerializer(extensionPoint.ExtendedType);

            serializer.Serialize(stream, value);
        }
コード例 #13
0
        public static T Xml <T>(this SerializationExtensionPoint <T> extensionPoint, Stream stream)
        {
            var serializer = new XmlSerializer(extensionPoint.ExtendedType);

            return((T)serializer.Deserialize(stream));
        }