public void TryAdd(Type type, ReflectionInfo fields) { cacheLock.EnterWriteLock(); try { harvestCache.Add(type, fields); } finally { cacheLock.ExitWriteLock(); } }
public void TryAdd(Type type, ReflectionInfo fields) { cacheLock.EnterWriteLock(); try { if (!harvestCache.ContainsKey(type)) { harvestCache.Add(type, fields); } } finally { cacheLock.ExitWriteLock(); } }
void IntrospectComplexType(object source, Field field, Type sourceType) { Reference optionReferenceInfo; seenBefore.TryGetValue(source, out optionReferenceInfo); tokens.Add(new Token(TokenType.FieldnameWithTypeAndReference, field, null, optionReferenceInfo, sourceType)); tokens.Add(Startscope); ReflectionInfo reflection = ReflectFields(sourceType); for (int i = 0; i < reflection.Fields.Length; i++) { Introspect(reflection.ValueProviders[i](source), reflection.Fields[i]); } tokens.Add(Endscope); }
ReflectionInfo ReflectFields(Type sourceType) { ReflectionInfo reflection; if ((reflection = harvestCache.TryGet(sourceType)) == null) { IFieldHarvester harvester; if (!configuration.TryGetFieldHarvester(sourceType, out harvester)) { throw new Exception( string.Format( "No fieldharvester is configured for handling type '{0}'. Try using 'ConfigurationHelper.GetStandardConfiguration()' to get started.", sourceType)); } List <SanitizedFieldInfo> fields = harvester.GetFields(sourceType); reflection = new ReflectionInfo(fields); harvestCache.TryAdd(sourceType, reflection); } return(reflection); }