Пример #1
0
        public TDestination Map <TSource, TDestination>(TSource source) where TDestination : new()
        {
            Type sourceType = typeof(TSource);
            Type destType   = typeof(TDestination);
            SourceDestinationTypesPair key = new SourceDestinationTypesPair()
            {
                SourceType      = sourceType,
                DestinationType = destType
            };
            TDestination result = (TDestination)destType.GetConstructor(new Type[0]).Invoke(new object[0]);

            if (expressions.ContainsKey(key))
            {
                var lambda = expressions[key];
                ((Action <TSource, TDestination>)lambda)(source, result);
            }
            else
            {
                Expression <Action <TSource, TDestination> > expr =
                    BuildNewMapLambda <TSource, TDestination>();
                var lambda = expr.Compile();
                expressions[key] = lambda;
                lambda(source, result);
            }
            return(result);
        }
        public override bool Equals(object obj)
        {
            SourceDestinationTypesPair pair = obj as SourceDestinationTypesPair;

            if ((pair.DestinationType.FullName == DestinationType.FullName) &&
                (pair.SourceType.FullName == SourceType.FullName))
            {
                return(true);
            }
            return(false);
        }