void DeserializeResources(JObject jobj, Type resourceType, JsonSerializer serializer, RedwoodResourceRepository repo) { foreach (var resObj in jobj) { var resource = serializer.Deserialize(resObj.Value.CreateReader(), resourceType) as ResourceBase; repo.Register(resObj.Key, resource); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jobj = JObject.Load(reader); var repo = existingValue as RedwoodResourceRepository; if (repo == null) repo = new RedwoodResourceRepository(); foreach (var prop in jobj) { Type type; if (ResourceTypeNames.TryGetValue(prop.Key, out type)) { DeserializeResources((JObject)prop.Value, type, serializer, repo); } else throw new NotSupportedException(string.Format("resource collection name {0} is not supported", prop.Key)); } return repo; }
public RedwoodResourceRepository(RedwoodResourceRepository parent) : this() { this.Resources = new ConcurrentDictionary<string, ResourceBase>(); this.Parents.TryAdd("", parent); }