private Delegate CreateConverter(TypeDescBasedTConverterKey key) { if (key.IsConvert) { return(GetTheStringFromTDelegateInt(key.SourceType, key.TargetType)); } else { return(GetTheTFromStringDelegateInt(key.SourceType, key.TargetType)); } }
public TFromStringDelegate GetTheTFromStringDelegate(Type sourceType, Type propertyType) { TypeDescBasedTConverterKey key = new TypeDescBasedTConverterKey(sourceType, propertyType, isConvert: false); #if DEBUG //bool inCache = _converters.ContainsKey(key); Delegate result = _converters.GetOrAdd(key); //System.Diagnostics.Debug.WriteLine( // string.Format("A TFromString delegate is being requested for type: {0} and was {1}", // sourceType.ToString(), inCache ? "found." : "not found.")); #else Delegate result = _converters.GetOrAdd(key); #endif if (result == null) { return(null); } return((TFromStringDelegate)result); }
public TypeDescBasedTConverterCache() { _converters = new LockingConcurrentDictionary <TypeDescBasedTConverterKey, Delegate>( CreateConverter, TypeDescBasedTConverterKey.GetEquComparer()); }