コード例 #1
0
        public TDestination Map <TSource, TDestination>(TSource source) where TDestination : new()
        {
            Type sourseType = typeof(TSource);
            Type destType   = typeof(TDestination);

            MappingResultPair tempPair = new MappingResultPair()
            {
                TSource       = sourseType,
                TDestionation = destType
            };

            TDestination result = (TDestination)destType.GetConstructor(new Type[0]).Invoke(new Object[0]);

            if (mappingHash.ContainsKey(tempPair))
            {
                var lambda = mappingHash[tempPair];
                ((Action <TSource, TDestination>)lambda)(source, result);
            }
            else
            {
                Expression <Action <TSource, TDestination> > expression = BuildLambda <TSource, TDestination>();
                var lambda = expression.Compile();
                mappingHash[tempPair] = lambda;
                lambda(source, result);
            }

            return(result);
        }
コード例 #2
0
        public override bool Equals(object mapResultObject)
        {
            bool result            = false;
            MappingResultPair pair = mapResultObject as MappingResultPair;

            if ((pair.TSource.FullName == TSource.FullName) &&
                (pair.TDestionation.FullName == TDestionation.FullName))
            {
                result = true;
            }
            return(result);
        }