static private CreateExisting ( |
||
type | ||
id | int | |
defaultConstructorCache | ConstructorInfo>.IDictionary | |
return | IJsonEntity |
public object Fetch(Type type, int id) { if (!supportedTypes.Contains(type)) { throw new NotSupportedException("Type '" + type.Name + "' is not supported."); } IJsonEntity entity; Dictionary <int, IJsonEntity> typeEntities; if (!_existingEntities.TryGetValue(type, out typeEntities)) { _existingEntities[type] = typeEntities = new Dictionary <int, IJsonEntity>(); } else if (typeEntities.TryGetValue(id, out entity)) { return(entity); } Dictionary <string, object> entityData; var typeData = GetTypeData(type); if (!typeData.TryGetValue(id.ToString(CultureInfo.InvariantCulture), out entityData)) { return(null); } entity = JsonEntity.CreateExisting(type, id, _defaultConstructors); typeEntities[id] = entity; if (autoInitializeEntities) { InitializeInstance(type, entity, entityData); } return(entity); }
public IEnumerable FetchAll(Type type) { if (!supportedTypes.Contains(type)) { throw new NotSupportedException("Type '" + type.Name + "' is not supported."); } Dictionary <int, IJsonEntity> typeEntities; if (!_existingEntities.TryGetValue(type, out typeEntities)) { typeEntities = new Dictionary <int, IJsonEntity>(); _existingEntities[type] = typeEntities; } var typeData = GetTypeData(type); lock (typeData) { foreach (var key in typeData.Keys) { var id = int.Parse(key); var entity = JsonEntity.CreateExisting(type, id, _defaultConstructors); typeEntities[id] = entity; if (autoInitializeEntities) { InitializeInstance(type, entity, typeData[key]); } } } return(typeEntities.Values); }