/// <summary> /// Deserialize an object from a byte array /// </summary> /// <typeparam name="T"></typeparam> /// <param name="bytes"></param> /// <param name="options">The serialization options</param> /// <param name="typeMaps">A list of type mappings</param> /// <returns></returns> public object Deserialize(Type type, byte[] bytes, SerializerOptions options, params TypeMap[] typeMaps) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length == 0) { return(null); } TypeRegistry typeRegistry = null; if (typeMaps != null && typeMaps.Length > 0) { TypeRegistry.Configure((config) => { foreach (var typeMap in typeMaps) { config.Mappings.Add(typeMap); } }); } return(Deserialize(type, bytes, options, typeRegistry)); }
private TypeRegistry ConvertToTypeRegistry(SerializationTypeRegistry typeRegistry) { if (typeRegistry == null) { return(null); } var registry = TypeRegistry.Configure(c => { foreach (var factory in typeRegistry.Factories) { var newFactory = _objectFactory.CreateEmptyObject <TypeFactory>(factory.Source, factory.Factory); c.Factories.Add(newFactory); } foreach (var map in typeRegistry.Mappings) { var newMap = _objectFactory.CreateEmptyObject <TypeMap>(); newMap.Source = map.Source; newMap.Destination = map.Destination; c.Mappings.Add(newMap); } }); return(registry); }