Пример #1
0
        internal static Document Serialize <T>(TypedDocument <T> typedDoc)
        {
            // TODO: This serializer stuff for document references should be in standard typed doc serializer
            var settings = new JsonSerializerSettings();

            var documentReferenceConverter = new DocumentReferenceConverter();

            settings.Converters.Add(documentReferenceConverter);

            var jsonSerializer = JsonSerializer.CreateDefault(settings);

            var jdoc = new Document
            {
                Meta    = typedDoc.Meta,
                Content = JObject.FromObject(typedDoc.Content, jsonSerializer),
            };

            jdoc.References = new List <DocumentReferencePosition>(documentReferenceConverter.References);

            return(jdoc);
        }
Пример #2
0
        public static Task <TypedDocument <T> > StoreObject <T>(this IProvider provider, TypedDocument <T> typedDoc)
        {
            var doc = Serialize <T>(typedDoc);
            Func <Task <Document>, TypedDocument <T> > continuation = task => Deserialize <T>(task.Result);

            return(provider.StoreDocument(doc).ContinueWith <TypedDocument <T> >(continuation));
        }