Exemplo n.º 1
0
 private Delegate CreateConverter(TypeDescBasedTConverterKey key)
 {
     if (key.IsConvert)
     {
         return(GetTheStringFromTDelegateInt(key.SourceType, key.TargetType));
     }
     else
     {
         return(GetTheTFromStringDelegateInt(key.SourceType, key.TargetType));
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public TypeDescBasedTConverterCache()
 {
     _converters = new LockingConcurrentDictionary <TypeDescBasedTConverterKey, Delegate>(
         CreateConverter, TypeDescBasedTConverterKey.GetEquComparer());
 }