public static void WriteObject <T>(string path, Stream stream, T instance, Format format) { SerializationPathStack.Push(path); AbstractWriterSerializer ys = null; try { if (format == Format.Binary) { WriteYuzuBinarySignature(stream); ys = new Yuzu.Binary.BinarySerializer { Options = defaultYuzuCommonOptions }; } else if (format == Format.JSON) { ys = new Yuzu.Json.JsonSerializer { Options = defaultYuzuCommonOptions, JsonOptions = defaultYuzuJSONOptions }; } ys.ToStream(instance, stream); } finally { SerializationPathStack.Pop(); } }
public static T ReadObject <T>(string path, Stream stream, object obj = null) { var ms = new MemoryStream(); stream.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); stream = ms; SerializationPathStack.Push(path); try { AbstractDeserializer d = null; if (CheckYuzuBinarySignature(stream)) { d = new GeneratedDeserializersBIN.BinaryDeserializerGen { Options = defaultYuzuCommonOptions }; } else { foreach (var db in DeserializerBuilders) { d = db(path, stream); if (d != null) { break; } } } var bd = d as BinaryDeserializer; if (obj == null) { if (bd != null) { return(bd.FromReader <T>(new BinaryReader(stream))); } else { return(d.FromStream <T>(stream)); } } else { if (bd != null) { return((T)bd.FromReader(obj, new BinaryReader(stream))); } else { return((T)d.FromStream(obj, stream)); } } } finally { SerializationPathStack.Pop(); } }
public static void WriteObject <T>(string path, Stream stream, T instance, AbstractSerializer serializer) { SerializationPathStack.Push(path); try { if (serializer is BinarySerializer) { WriteYuzuBinarySignature(stream); } serializer.ToStream(instance, stream); } finally { SerializationPathStack.Pop(); } }
private static string GetCurrentSerializationDirectory() { return(Path.GetDirectoryName(SerializationPathStack.Peek())); }
public static string GetCurrentSerializationPath() { return(SerializationPathStack.Peek()); }