private ICompositeStorage TrySerializeInternal(object input, ISerializerContext context) { Ensure.NotNull(input, "input"); Ensure.NotNull(context, "context"); ICompositeModel model = input as ICompositeModel; if (model == null) { return(null); } ICompositeStorage storage = storageFactory.Create(); if (!typeNameMapper.TryGet(model.GetType(), out string typeName)) { return(null); } storage.Add(Name.TypeName, typeName); ICompositeStorage childStorage = storage.Add(Name.Payload); model.Save(childStorage); return(storage); }
public bool TrySerialize(object input, ISerializerContext context) { Ensure.NotNull(input, "input"); Ensure.NotNull(context, "context"); ICompositeModel model = input as ICompositeModel; if (model == null) { return(false); } ICompositeStorage storage = storageFactory.Create(); model.Save(storage); storage.Store(context.Output); return(true); }
public async Task <bool> TrySerializeAsync(object input, ISerializerContext context) { Ensure.NotNull(input, "input"); Ensure.NotNull(context, "context"); ICompositeModel model = input as ICompositeModel; if (model == null) { return(false); } ICompositeStorage storage = storageFactory.Create(); model.Save(storage); await storage.StoreAsync(context.Output).ConfigureAwait(false); return(true); }