当前位置: 首页>>代码示例>>C#>>正文


C# ResolutionContext.CreateTypeContext方法代码示例

本文整理汇总了C#中ResolutionContext.CreateTypeContext方法的典型用法代码示例。如果您正苦于以下问题:C# ResolutionContext.CreateTypeContext方法的具体用法?C# ResolutionContext.CreateTypeContext怎么用?C# ResolutionContext.CreateTypeContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ResolutionContext的用法示例。


在下文中一共展示了ResolutionContext.CreateTypeContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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:mwpowellhtx,项目名称:MicroMapper,代码行数:32,代码来源:ConstructorMap.cs

示例2: Map

        public object Map(ResolutionContext context)
        {
            var typeMap = context.MapperContext.ConfigurationProvider.FindClosedGenericTypeMapFor(context);

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

            return context.MapperContext.Runner.Map(newContext);
        }
开发者ID:mwpowellhtx,项目名称:MicroMapper,代码行数:9,代码来源:OpenGenericMapper.cs

示例3: Map

 public object Map(ResolutionContext context)
 {
     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 context.Engine.Map(newContext);
 }
开发者ID:garora,项目名称:AutoMapper,代码行数:9,代码来源:StringDictionaryMapper.cs

示例4: 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

示例5: 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


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