• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IMappingEngineRunner类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IMappingEngineRunner的典型用法代码示例。如果您正苦于以下问题:C# IMappingEngineRunner类的具体用法?C# IMappingEngineRunner怎么用?C# IMappingEngineRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IMappingEngineRunner类属于命名空间,在下文中一共展示了IMappingEngineRunner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var sourceElementType = TypeHelper.GetElementType(context.SourceValue.GetType());
            var destinationElementType = TypeHelper.GetElementType(context.DestinationValue.GetType());
            var equivilencyExpression = GetEquivilentExpression(context);

            var sourceEnumerable = context.SourceValue as IEnumerable;
            var destEnumerable = (IEnumerable)context.DestinationValue;

            var destItems = destEnumerable.Cast<object>().ToList();
            var sourceItems = sourceEnumerable.Cast<object>().ToList();
            var compareSourceToDestination = sourceItems.ToDictionary(s => s, s => destItems.FirstOrDefault(d => equivilencyExpression.IsEquivlent(s, d)));

            var actualDestType = destEnumerable.GetType();

            var addMethod = actualDestType.GetMethod("Add");
            foreach (var keypair in compareSourceToDestination)
            {
                if (keypair.Value == null)
                    addMethod.Invoke(destEnumerable, new[] { Mapper.Map(keypair.Key, sourceElementType, destinationElementType) });
                else
                    Mapper.Map(keypair.Key, keypair.Value, sourceElementType, destinationElementType);
            }

            var removeMethod = actualDestType.GetMethod("Remove");
            foreach (var removedItem in destItems.Except(compareSourceToDestination.Values))
                removeMethod.Invoke(destEnumerable, new[] { removedItem });

            return destEnumerable;
        }
开发者ID:yao-yi,项目名称:Automapper.Collection,代码行数:30,代码来源:EquivlentExpressionAddRemoveCollectionMapper.cs


示例2: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var sourceDelegateType = context.SourceType.GetGenericArguments()[0];
            var destDelegateType = context.DestinationType.GetGenericArguments()[0];
            var expression = (LambdaExpression) context.SourceValue;

            if (sourceDelegateType.GetGenericTypeDefinition() != destDelegateType.GetGenericTypeDefinition())
                throw new AutoMapperMappingException("Source and destination expressions must be of the same type.");

            var parameters = expression.Parameters.ToArray();
            var body = expression.Body;

            for (int i = 0; i < expression.Parameters.Count; i++)
            {
                var sourceParamType = sourceDelegateType.GetGenericArguments()[i];
                var destParamType = destDelegateType.GetGenericArguments()[i];

                if (sourceParamType == destParamType)
                    continue;

                var typeMap = mapper.ConfigurationProvider.ResolveTypeMap(destParamType, sourceParamType);

                if (typeMap == null)
                    throw new AutoMapperMappingException(
                        $"Could not find type map from destination type {destParamType} to source type {sourceParamType}. Use CreateMap to create a map from the source to destination types.");

                var oldParam = expression.Parameters[i];
                var newParam = Expression.Parameter(typeMap.SourceType, oldParam.Name);
                parameters[i] = newParam;
                var visitor = new MappingVisitor(typeMap, oldParam, newParam);
                body = visitor.Visit(body);
            }
            return Expression.Lambda(body, parameters);
        }
开发者ID:AnatolyKulakov,项目名称:AutoMapper,代码行数:34,代码来源:ExpressionMapper.cs


示例3: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (IsDataReader(context))
            {
                var dataReader = (IDataReader)context.SourceValue;

                var destinationElementType = TypeHelper.GetElementType(context.DestinationType);
                var buildFrom = CreateBuilder(destinationElementType, dataReader);

                var results = ObjectCreator.CreateList(destinationElementType);
                while (dataReader.Read())
                {
                    results.Add(buildFrom(dataReader));
                }

                return results;
            }

            if (IsDataRecord(context))
            {
                var dataRecord = context.SourceValue as IDataRecord;
                var buildFrom = CreateBuilder(context.DestinationType, dataRecord);

                var result = buildFrom(dataRecord);
                MapPropertyValues(context, mapper, result);

                return result;
            }

            return null;
        }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:31,代码来源:DataReaderMapper.cs


示例4: ResolveValue

        public object ResolveValue(ResolutionContext context, IMappingEngineRunner mappingEngine)
        {
            var ctorArgs = new List<object>();

            foreach (var map in CtorParams)
            {
                var result = map.ResolveValue(context);

                var sourceType = result.Type;
                var destinationType = map.Parameter.ParameterType;

                var typeMap = mappingEngine.ConfigurationProvider.ResolveTypeMap(result, destinationType);

                Type targetSourceType = typeMap != null ? typeMap.SourceType : sourceType;

                var newContext = context.CreateTypeContext(typeMap, result.Value, null, targetSourceType,
                    destinationType);

                if (typeMap == null && map.Parameter.IsOptional)
                {
                    object value = map.Parameter.DefaultValue;
                    ctorArgs.Add(value);
                }
                else
                {
                    var value = mappingEngine.Map(newContext);
                    ctorArgs.Add(value);
                }
            }

            return _runtimeCtor.Value(ctorArgs.ToArray());
        }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:32,代码来源:ConstructorMap.cs


示例5: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            bool toEnum = false;
            Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType);
            Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType);

            if (EnumToStringMapping(context, ref toEnum))
            {
                if (context.SourceValue == null)
                {
                    return mapper.CreateObject(context);
                }

                if (toEnum)
                {
                    var stringValue = context.SourceValue.ToString();
                    if (string.IsNullOrEmpty(stringValue))
                    {
                        return mapper.CreateObject(context);
                    }

                    return Enum.Parse(enumDestinationType, stringValue, true);
                }
                return Enum.GetName(enumSourceType, context.SourceValue);
            }
            if (EnumToEnumMapping(context))
            {
                if (context.SourceValue == null)
                {
                    return mapper.CreateObject(context);
                }

                if (!Enum.IsDefined(enumSourceType, context.SourceValue))
                {
                    return Enum.ToObject(enumDestinationType, context.SourceValue);
                }

            #if !SILVERLIGHT && !__ANDROID__
                if (!Enum.GetNames(enumDestinationType).Contains(context.SourceValue.ToString()))
                {
                    Type underlyingSourceType = Enum.GetUnderlyingType(enumSourceType);
                    var underlyingSourceValue = Convert.ChangeType(context.SourceValue, underlyingSourceType);

                    return Enum.ToObject(context.DestinationType, underlyingSourceValue);
                }
            #endif

                return Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true);
            }
            if (EnumToUnderlyingTypeMapping(context, ref toEnum))
            {
                if (toEnum)
                {
                    return Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true);
                }
                return Convert.ChangeType(context.SourceValue, context.DestinationType, null);
            }
            return null;
        }
开发者ID:rkania,项目名称:AutoMapper,代码行数:59,代码来源:EnumMapper.cs


示例6: Map

		public object Map(ResolutionContext context, IMappingEngineRunner mapper)
		{
			if (context.SourceValue == null)
			{
				return mapper.FormatValue(context.CreateValueContext(null));
			}
			return mapper.FormatValue(context);
		}
开发者ID:sclcwwl,项目名称:Gimela,代码行数:8,代码来源:StringMapper.cs


示例7: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var mapperToUse = _mappers.First(objectMapper => objectMapper.IsMatch(context, mapper));
            object mappedObject = mapperToUse.Map(context, mapper);

            context.TypeMap.AfterMap(context.SourceValue, mappedObject);
            return mappedObject;
        }
开发者ID:paulbatum,项目名称:automapper,代码行数:8,代码来源:TypeMapMapper.cs


示例8: Map

		public object Map(ResolutionContext context, IMappingEngineRunner mapper)
		{
			if (context.SourceValue == null)
			{
				return mapper.CreateObject(context);
			}
			Func<object> converter = GetConverter(context);
			return converter != null ? converter() : null;
		}
开发者ID:dennyli,项目名称:HandySolution,代码行数:9,代码来源:TypeConverterMapper.cs


示例9: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (context.SourceValue == null && !mapper.ShouldMapSourceCollectionAsNull(context))
            {
                return mapper.CreateObject(context);
            }

            return context.SourceValue;
        }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:9,代码来源:AssignableArrayMapper.cs


示例10: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (context.SourceValue == null)
            {
                return mapper.CreateObject(context);
            }

            return context.SourceValue;
        }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:9,代码来源:AssignableMapper.cs


示例11: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var typeMap = mapper.ConfigurationProvider.FindClosedGenericTypeMapFor(context);

            var newContext = context.CreateTypeContext(typeMap, context.SourceValue, context.DestinationValue, context.SourceType,
                context.DestinationType);

            return mapper.Map(newContext);
        }
开发者ID:gonzalogilrepositorio,项目名称:Proyecto-ComIT,代码行数:9,代码来源:OpenGenericMapper.cs


示例12: Map

 public object Map(ResolutionContext context, IMappingEngineRunner mapper)
 {
     var source = context.SourceValue;
     var sourceType = source.GetType();
     var sourceTypeDetails = new TypeDetails(sourceType, _ => true, _ => true);
     var membersDictionary = sourceTypeDetails.PublicReadAccessors.ToDictionary(p => p.Name, p => p.GetMemberValue(source));
     var newContext = context.CreateTypeContext(null, membersDictionary, context.DestinationValue, membersDictionary.GetType(), context.DestinationType);
     return mapper.Map(newContext);
 }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:9,代码来源:StringDictionaryMapper.cs


示例13: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (context.SourceValue == null)
            {
                return mapper.CreateObject(context);
            }

            TypeConverter typeConverter = GetTypeConverter(context);
            return typeConverter.ConvertTo(context.SourceValue, context.DestinationType);
        }
开发者ID:paulbatum,项目名称:automapper,代码行数:10,代码来源:TypeConverterMapper.cs


示例14: Map

            public object Map(ResolutionContext context, IMappingEngineRunner mapper)
            {
                var newSource = context.TypeMap.Substitution(context.SourceValue);
                var typeMap = mapper.ConfigurationProvider.ResolveTypeMap(newSource.GetType(), context.DestinationType);

                var substitutionContext = context.CreateTypeContext(typeMap, newSource, context.DestinationValue,
                    newSource.GetType(), context.DestinationType);

                return mapper.Map(substitutionContext);
            }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:10,代码来源:TypeMapObjectMapperRegistry.cs


示例15: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (mapper == null) throw new ArgumentNullException("mapper");

            if (context.SourceValue == null)
            {
                return mapper.FormatValue(context.CreateValueContext(null));
            }
            return mapper.FormatValue(context);
        }
开发者ID:firestrand,项目名称:AutoMapper,代码行数:11,代码来源:StringMapper.cs


示例16: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            context.TypeMap.Seal();

            var mapperToUse = _mappers.First(objectMapper => objectMapper.IsMatch(context, mapper));

            // check whether the context passes conditions before attempting to map the value (depth check)
            var mappedObject = !context.TypeMap.ShouldAssignValue(context) ? null : mapperToUse.Map(context, mapper);

            return mappedObject;
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:11,代码来源:TypeMapMapper.cs


示例17: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var enumDestType = TypeHelper.GetEnumerationType(context.DestinationType);

            if (context.SourceValue == null)
            {
                return mapper.CreateObject(context);
            }

            return Enum.Parse(enumDestType, context.SourceValue.ToString(), true);
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:11,代码来源:FlagsEnumMapper.cs


示例18: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            var contextTypePair = new TypePair(context.SourceType, context.DestinationType);
            Func<TypePair, IObjectMapper> missFunc = tp => context.Engine.ConfigurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(context));
            var typeMap = mapper.ConfigurationProvider.CreateTypeMap(context.SourceType, context.DestinationType, _profileName);

            context = context.CreateTypeContext(typeMap, context.SourceValue, context.DestinationValue, context.SourceType, context.DestinationType);

            var map = (context.Engine as MappingEngine)._objectMapperCache.GetOrAdd(contextTypePair, missFunc);
            return map.Map(context, mapper);
        }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:11,代码来源:CreateMapBasedOnCriteriaMapper.cs


示例19: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (!IsMatch(context) || context.SourceValue == null)
                return null;
            
            var nvc = new NameValueCollection();
            var source = context.SourceValue as NameValueCollection;
            foreach (var s in source.AllKeys)
                nvc.Add(s, source[s]);

            return nvc;
        }
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:12,代码来源:NameValueCollectionMapper.cs


示例20: Map

        public object Map(ResolutionContext context, IMappingEngineRunner mapper)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (mapper == null) throw new ArgumentNullException("mapper");

            if (context.SourceValue == null && !mapper.ShouldMapSourceValueAsNull(context))
            {
                return mapper.CreateObject(context);
            }

            return context.SourceValue;
        }
开发者ID:firestrand,项目名称:AutoMapper,代码行数:12,代码来源:AssignableMapper.cs



注:本文中的IMappingEngineRunner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IMappingOptions类代码示例发布时间:2022-05-24
下一篇:
C# IMappingEngine类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap