public void LoadFromJson(JObject source) { // This is where the automatic deserialization takes place. We just tell the Jobject that we want an object of the type RelfectionData and it will handle the rest var reflectionDataObject = source.Deserialize<ReflectionData>(); // This is just a simple method a created to read the data from reflectionDataObject back into this object reflectionDataObject.ToMonoBehavior(this); }
protected object ConvertToEntity <T>(string id, JObject documentFound, JObject metadata) { var entity = default(T); EnsureNotReadVetoed(metadata); var documentType = metadata.Value <string>("Raven-Clr-Type"); if (documentType != null) { var type = Type.GetType(documentType); if (type != null) { entity = (T)documentFound.Deserialize(type, Conventions); } } if (Equals(entity, default(T))) { entity = documentFound.Deserialize <T>(Conventions); #if !NET_3_5 var document = entity as JObject; if (document != null) { entity = (T)(object)(new DynamicJsonObject(document)); } #endif } var identityProperty = documentStore.Conventions.GetIdentityProperty(entity.GetType()); if (identityProperty != null && identityProperty.CanWrite) { identityProperty.SetValue(entity, id, null); } return(entity); }
private object ConvertToEntity <T>(string id, JObject documentFound, JObject metadata) { T entity = default(T); var documentType = metadata.Value <string>("Raven-Clr-Type"); if (documentType != null) { Type type = Type.GetType(documentType); if (type != null) { entity = (T)documentFound.Deserialize(type, Conventions.JsonContractResolver); } } if (Equals(entity, default(T))) { entity = documentFound.Deserialize <T>(Conventions.JsonContractResolver); } var identityProperty = documentStore.Conventions.GetIdentityProperty(entity.GetType()); if (identityProperty != null) { identityProperty.SetValue(entity, id, null); } return(entity); }
public void LoadFromJson(JObject source) { // This is where the automatic deserialization takes place. We just tell the Jobject that we want an object of the type RelfectionData and it will handle the rest var reflectionDataObject = source.Deserialize <ReflectionData>(); // This is just a simple method a created to read the data from reflectionDataObject back into this object reflectionDataObject.ToMonoBehavior(this); }
/// <summary> /// Converts the json document to an entity. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <param name="documentFound">The document found.</param> /// <param name="metadata">The metadata.</param> /// <returns></returns> protected object ConvertToEntity <T>(string id, JObject documentFound, JObject metadata) { if (typeof(T) == typeof(JObject)) { return((T)(object)documentFound); } var entity = default(T); EnsureNotReadVetoed(metadata); var documentType = Conventions.GetClrType(id, documentFound, metadata); if (documentType != null) { var type = Type.GetType(documentType); if (type != null) { entity = (T)documentFound.Deserialize(type, Conventions); } } if (Equals(entity, default(T))) { entity = documentFound.Deserialize <T>(Conventions); #if !NET_3_5 var document = entity as JObject; if (document != null) { entity = (T)(object)(new DynamicJsonObject(document)); } #endif } TrySetIdentity(entity, id); var documentToEntity = OnDocumentConverted; if (documentToEntity != null) { documentToEntity(entity, documentFound, metadata); } return(entity); }