Exemple #1
0
 /// <summary>
 /// Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 public bool Equals(ConvertibleTypeKey other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.ToInstanceType == ToInstanceType && other.FromElementType == FromElementType);
 }
        public static object TranslateToConvertibleGenericICollectionCache(object from, Type toInstanceOfType, Type fromElementType)
        {
            ConvertibleTypeKey      key = new ConvertibleTypeKey(toInstanceOfType, fromElementType);
            ConvertInstanceDelegate instanceDelegate1;

            if (TranslateListWithElements.TranslateConvertibleICollectionCache.TryGetValue(key, out instanceDelegate1))
            {
                return(instanceDelegate1(from, toInstanceOfType));
            }
            Type genericTypeArgument = toInstanceOfType.FirstGenericType().GenericTypeArguments()[0];
            ConvertInstanceDelegate instanceDelegate2 = (ConvertInstanceDelegate)typeof(TranslateListWithConvertibleElements <,>).MakeGenericType(fromElementType, genericTypeArgument).GetStaticMethod("LateBoundTranslateToGenericICollection").MakeDelegate(typeof(ConvertInstanceDelegate), true);
            Dictionary <ConvertibleTypeKey, ConvertInstanceDelegate> icollectionCache;
            Dictionary <ConvertibleTypeKey, ConvertInstanceDelegate> dictionary;

            do
            {
                icollectionCache = TranslateListWithElements.TranslateConvertibleICollectionCache;
                dictionary       = new Dictionary <ConvertibleTypeKey, ConvertInstanceDelegate>((IDictionary <ConvertibleTypeKey, ConvertInstanceDelegate>)TranslateListWithElements.TranslateConvertibleICollectionCache);
                dictionary[key]  = instanceDelegate2;
            }while (Interlocked.CompareExchange <Dictionary <ConvertibleTypeKey, ConvertInstanceDelegate> >(ref TranslateListWithElements.TranslateConvertibleICollectionCache, dictionary, icollectionCache) != icollectionCache);
            return(instanceDelegate2(from, toInstanceOfType));
        }