-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
JsonHelpers.cs
28 lines (27 loc) · 909 Bytes
/
JsonHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// MIT License Copyright 2019 (c) David Melendez. All rights reserved. See License.txt in the project root for license information.
using ElCamino.AspNetCore.Identity.CosmosDB.Model;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace ElCamino.AspNetCore.Identity.CosmosDB.Helpers
{
public static class JsonHelpers
{
public static T CreateObject<T>(Document doc) where T : new()
{
var t = JsonConvert.DeserializeObject<T>(doc.ToString());
var r = t as IResource<string>;
if(r != null)
{
r.AltLink = doc.AltLink;
r.ETag = doc.ETag;
r.ResourceId = doc.ResourceId;
r.SelfLink = doc.SelfLink;
r.Timestamp = doc.Timestamp;
}
return t;
}
}
}