From 8ce3e74e8112a94773df22827849bf274fc88198 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 24 Feb 2013 16:53:54 -0500 Subject: More DI --- .../Serialization/DynamicProtobufSerializer.cs | 157 --------------------- 1 file changed, 157 deletions(-) delete mode 100644 MediaBrowser.Common/Serialization/DynamicProtobufSerializer.cs (limited to 'MediaBrowser.Common/Serialization/DynamicProtobufSerializer.cs') diff --git a/MediaBrowser.Common/Serialization/DynamicProtobufSerializer.cs b/MediaBrowser.Common/Serialization/DynamicProtobufSerializer.cs deleted file mode 100644 index 359cf9da0..000000000 --- a/MediaBrowser.Common/Serialization/DynamicProtobufSerializer.cs +++ /dev/null @@ -1,157 +0,0 @@ -using ProtoBuf; -using ProtoBuf.Meta; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Common.Serialization -{ - /// - /// Creates a compiled protobuf serializer based on a set of assemblies - /// - public class DynamicProtobufSerializer - { - /// - /// Gets or sets the type model. - /// - /// The type model. - public TypeModel TypeModel { get; set; } - - /// - /// Serializes to stream. - /// - /// The obj. - /// The stream. - /// obj - public void SerializeToStream(object obj, Stream stream) - { - if (obj == null) - { - throw new ArgumentNullException("obj"); - } - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - TypeModel.Serialize(stream, obj); - } - - /// - /// Deserializes from stream. - /// - /// The stream. - /// The type. - /// System.Object. - /// stream - public object DeserializeFromStream(Stream stream, Type type) - { - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - return TypeModel.Deserialize(stream, null, type); - } - - /// - /// Deserializes from stream. - /// - /// - /// The stream. - /// ``0. - public T DeserializeFromStream(Stream stream) - where T : class - { - return DeserializeFromStream(stream, typeof(T)) as T; - } - - /// - /// Serializes to file. - /// - /// - /// The obj. - /// The file. - /// file - public void SerializeToFile(T obj, string file) - { - if (string.IsNullOrEmpty(file)) - { - throw new ArgumentNullException("file"); - } - - using (Stream stream = File.Open(file, FileMode.Create)) - { - SerializeToStream(obj, stream); - } - } - - /// - /// Deserializes from file. - /// - /// - /// The file. - /// ``0. - /// file - public T DeserializeFromFile(string file) - where T : class - { - if (string.IsNullOrEmpty(file)) - { - throw new ArgumentNullException("file"); - } - - using (Stream stream = File.OpenRead(file)) - { - return DeserializeFromStream(stream); - } - } - - /// - /// Serializes to bytes. - /// - /// - /// The obj. - /// System.Byte[][]. - /// obj - public byte[] SerializeToBytes(T obj) - where T : class - { - if (obj == null) - { - throw new ArgumentNullException("obj"); - } - - using (var stream = new MemoryStream()) - { - SerializeToStream(obj, stream); - return stream.ToArray(); - } - } - - /// - /// Creates the specified assemblies. - /// - /// DynamicProtobufSerializer. - /// assemblies - public static DynamicProtobufSerializer Create(IEnumerable types) - { - if (types == null) - { - throw new ArgumentNullException("types"); - } - - var model = TypeModel.Create(); - var attributeType = typeof(ProtoContractAttribute); - - // Find all ProtoContracts in the current assembly - foreach (var type in types.Where(t => Attribute.IsDefined(t, attributeType))) - { - model.Add(type, true); - } - - return new DynamicProtobufSerializer { TypeModel = model.Compile() }; - } - } -} -- cgit v1.2.3