Пример #1
0
        private static void Map(object source, Type sourceType, object destination, Type destinationType, bool assumeDestinationExplicitly)
        {
            DictionaryKey <Type, Type, bool> key = new DictionaryKey <Type, Type, bool>(sourceType, destinationType, assumeDestinationExplicitly);

            Lazy <Action <object, object> > mappingAction;

            if (!cachedActions.TryGetValue(key, out mappingAction))
            {
                mappingAction = CacheMappingAction(key);
            }

            mappingAction.Value(source, destination);
        }
Пример #2
0
        private static Type AssumeDestinationActualType(Type initialDestinationType, Type sourceActualType)
        {
            DictionaryKey <Type, Type> key = new DictionaryKey <Type, Type>(initialDestinationType, sourceActualType);

            Lazy <Type> actualType;

            if (!assumeDestinationActualTypesCache.TryGetValue(key, out actualType))
            {
                actualType = CacheDestinationActualType(key);
            }

            return(actualType.Value);
        }
Пример #3
0
        private static object MapTo(object source, Type sourceType, Type destinationType, bool assumeDestinationExplicitly)
        {
            DictionaryKey <Type, Type, bool> key = new DictionaryKey <Type, Type, bool>(sourceType, destinationType, assumeDestinationExplicitly);

            Lazy <Func <object, object> > mappingFunction;

            if (!cachedFunctions.TryGetValue(key, out mappingFunction))
            {
                mappingFunction = CacheMappingFunction(key);
            }

            return(mappingFunction.Value(source));
        }
Пример #4
0
 private static Lazy <Action <object, object> > CacheMappingAction(DictionaryKey <Type, Type, bool> key)
 {
     return(cachedActions.GetOrAdd(
                key,
                new Lazy <Action <object, object> >(() => GetMappingAction(key.Item1, key.Item2, key.Item3), true)));
 }
Пример #5
0
 public bool Equals(DictionaryKey <T1, T2> other)
 {
     return(DictionaryKey.Equals(this, other));
 }
Пример #6
0
 public override bool Equals(object obj)
 {
     return(DictionaryKey.Equals(this, obj));
 }
Пример #7
0
 public override int GetHashCode()
 {
     return(DictionaryKey.GetHashCode(this));
 }
Пример #8
0
 private static Lazy <Type> CacheDestinationActualType(DictionaryKey <Type, Type> key)
 {
     return(assumeDestinationActualTypesCache.GetOrAdd(
                key,
                new Lazy <Type>(() => GetDestinationActualType(key.Item1, key.Item2), true)));
 }