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

C# AutoMapper.ResolutionContext类代码示例

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

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



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

示例1: AutoMapperMappingException

 public AutoMapperMappingException(ResolutionContext context, Exception inner, PropertyMap propertyMap)
     : base(null, inner)
 {
     Context = context;
     Types = context.Types;
     PropertyMap = propertyMap;
 }
开发者ID:sh-sabooni,项目名称:AutoMapper,代码行数:7,代码来源:AutoMapperMappingException.cs


示例2: ResolveValue

        public object ResolveValue(ResolutionContext context)
        {
            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 = context.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 = context.Engine.Map(newContext);
                    ctorArgs.Add(value);
                }
            }

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


示例3: CreateObject

        public object CreateObject(ResolutionContext context)
        {
            var typeMap = context.TypeMap;
            var destinationType = context.DestinationType;

            if (typeMap != null)
                if (typeMap.DestinationCtor != null)
                    return typeMap.DestinationCtor(context);
                else if (typeMap.ConstructDestinationUsingServiceLocator)
                    return context.Options.ServiceCtor(destinationType);
                else if (typeMap.ConstructorMap != null && typeMap.ConstructorMap.CtorParams.All(p => p.CanResolve))
                    return typeMap.ConstructorMap.ResolveValue(context);

            if (context.DestinationValue != null)
                return context.DestinationValue;

            if (destinationType.IsInterface())
#if PORTABLE
                throw new PlatformNotSupportedException("Mapping to interfaces through proxies not supported.");
#else
                destinationType = new ProxyGenerator().GetProxyType(destinationType);
#endif

                return !ConfigurationProvider.AllowNullDestinationValues
                ? ObjectCreator.CreateNonNullValue(destinationType)
                : ObjectCreator.CreateObject(destinationType);
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:27,代码来源:MappingEngine.cs


示例4: FormatValue

        public string FormatValue(ResolutionContext context)
        {
            var timespan = (TimeSpan) context.SourceValue;
            var list = new List<string>(3);

            int days = timespan.Days;
            int hours = timespan.Hours;
            int minutes = timespan.Minutes;

            if (days > 1)
                list.Add(string.Format("{0} days", days));
            else if (days == 1)
                list.Add(string.Format("{0} day", days));

            if (hours > 1)
                list.Add(string.Format("{0} hours", hours));
            else if (hours == 1)
                list.Add(string.Format("{0} hour", hours));

            if (minutes > 1)
                list.Add(string.Format("{0} minutes", minutes));
            else if (minutes == 1)
                list.Add(string.Format("{0} minute", minutes));

            return string.Join(", ", list.ToArray());
        }
开发者ID:snahider,项目名称:Presentations,代码行数:26,代码来源:TimeSpanFormatter.cs


示例5: CheckPropertyMapSkipList

        private static bool CheckPropertyMapSkipList(ResolutionContext context, Type formatterType)
        {
            if (context.PropertyMap == null)
                return true;

            return !context.PropertyMap.FormattersToSkipContains(formatterType);
        }
开发者ID:joshuaflanagan,项目名称:AutoMapper,代码行数:7,代码来源:ValueFormatter.cs


示例6: ResolutionResult

 private ResolutionResult(object value, ResolutionContext context, Type memberType)
 {
     Value = value;
     Context = context;
     Type = ResolveType(value, memberType);
     MemberType = memberType;
 }
开发者ID:DeanMilojevic,项目名称:AutoMapper,代码行数:7,代码来源:ResolutionResult.cs


示例7: ResolutionResult

 private ResolutionResult(object value, ResolutionContext context, Type memberType)
 {
     _value = value;
     _context = context;
     _type = ResolveType(value, memberType);
     _memberType = memberType;
 }
开发者ID:nates1973,项目名称:AutoMapper,代码行数:7,代码来源:ResolutionResult.cs


示例8: DryRunTypeMap

 private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, ResolutionContext context)
 {
     var typeMap = context.TypeMap;
     if (typeMap != null)
     {
         typeMapsChecked.Add(typeMap);
         CheckPropertyMaps(typeMapsChecked, context);
     }
     else
     {
         var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(context.Types));
         if (mapperToUse == null && context.SourceType.IsNullableType())
         {
             var nullableTypes = new TypePair(Nullable.GetUnderlyingType(context.SourceType),
                 context.DestinationType);
             mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
         }
         if (mapperToUse == null)
         {
             throw new AutoMapperConfigurationException(context);
         }
         if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
         {
             CheckElementMaps(typeMapsChecked, context);
         }
     }
 }
开发者ID:jbogard,项目名称:AutoMapper,代码行数:27,代码来源:ConfigurationValidator.cs


示例9: DryRunTypeMap

 private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, TypePair types, TypeMap typeMap, ResolutionContext context)
 {
     if (typeMap != null)
     {
         typeMapsChecked.Add(typeMap);
         if(typeMap.CustomMapper != null || typeMap.TypeConverterType != null)
         {
             return;
         }
         CheckPropertyMaps(typeMapsChecked, typeMap, context);
     }
     else
     {
         var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(types));
         if (mapperToUse == null && types.SourceType.IsNullableType())
         {
             var nullableTypes = new TypePair(Nullable.GetUnderlyingType(types.SourceType),
                 types.DestinationType);
             mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
         }
         if (mapperToUse == null)
         {
             throw new AutoMapperConfigurationException(types);
         }
         if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
         {
             CheckElementMaps(typeMapsChecked, types, context);
         }
     }
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:30,代码来源:ConfigurationValidator.cs


示例10: MapAbstractModel

 protected object MapAbstractModel(ResolutionContext context)
 {
     var assemblyQualifiedName = context.DestinationType.AssemblyQualifiedName;
     var baseFullName = context.DestinationType.FullName;
     var childtype = ((AbstractForm)context.SourceValue).BindingType;
     var destinationType = Type.GetType(assemblyQualifiedName.Replace(baseFullName, baseFullName + childtype));
     return Mapper.Map(context.SourceValue, context.SourceType, destinationType);
 }
开发者ID:jmptrader,项目名称:Switch-Transaccional,代码行数:8,代码来源:AbstractConverter.cs


示例11: ResolveValue

        /// <summary>
        /// Resolves the value.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public object ResolveValue(ResolutionContext context)
        {
            var ctorArgs = CtorParams
                        .Select(p => p.ResolveValue(context))
                        .Select(result => result.Value)
                        .ToArray();

            return _runtimeCtor(ctorArgs);
        }
开发者ID:patuww,项目名称:Automapper,代码行数:14,代码来源:ConstructorMap.cs


示例12: ReturnsTrueWhenBothSourceAndDestinationTypesAreNameValueCollection

            public void ReturnsTrueWhenBothSourceAndDestinationTypesAreNameValueCollection()
            {
                var rc = new ResolutionContext(null, null, null, typeof(NameValueCollection), typeof(NameValueCollection), null);
                var nvcm = new NameValueCollectionMapper();

                var result = nvcm.IsMatch(rc);

                result.ShouldBeTrue();
            }
开发者ID:ngadvmaster,项目名称:AutoMapper,代码行数:9,代码来源:NameValueCollectionMapperTests.cs


示例13: ReturnsIsFalseWhenSourceTypeIsNotNameValueCollection

            public void ReturnsIsFalseWhenSourceTypeIsNotNameValueCollection()
            {
                var rc = new ResolutionContext(null, null, null, typeof(Object), typeof(NameValueCollection), null);
                var nvcm = new NameValueCollectionMapper();

                var result = nvcm.IsMatch(rc);

                result.ShouldBeFalse();
            }
开发者ID:ngadvmaster,项目名称:AutoMapper,代码行数:9,代码来源:NameValueCollectionMapperTests.cs


示例14: IsMatch

        /// <summary>
        /// Determines whether the specified context is match.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if the specified context is match; otherwise, <c>false</c>.</returns>
        public bool IsMatch( ResolutionContext context )
        {
            if (Mapper.GetAllTypeMaps().Count(m => m.SourceType == context.SourceType && m.DestinationType == context.DestinationType) == 0)
            {
                return true;
            }

            return false;
        }
开发者ID:divyang4481,项目名称:REM,代码行数:14,代码来源:DefaulObjectMapper.cs


示例15: ResolutionResult

        private ResolutionResult(object value, ResolutionContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            _value = value;
            _context = context;
            _type = ResolveType(value, typeof(object));
            _memberType = _type;
        }
开发者ID:firestrand,项目名称:AutoMapper,代码行数:9,代码来源:ResolutionResult.cs


示例16: ReturnsNullIfSourceValueIsNull

            public void ReturnsNullIfSourceValueIsNull()
            {
                var rc = new ResolutionContext(null, null, new NameValueCollection(), typeof(NameValueCollection), typeof(NameValueCollection), null, Mapper.Engine);
                var nvcm = new NameValueCollectionMapper();

                var result = nvcm.Map(rc, null);

                result.ShouldBeNull();
            }
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:9,代码来源:NameValueCollectionMapperTests.cs


示例17: ReturnsIsFalseWhenDestinationTypeIsNotNameValueCollection

            public void ReturnsIsFalseWhenDestinationTypeIsNotNameValueCollection()
            {
                var rc = new ResolutionContext(null, null, null, typeof(NameValueCollection), typeof(Object), null);
                var nvcm = new NameValueCollectionMapper();

                var result = nvcm.IsMatch(rc);

                Assert.IsFalse(result);
            }
开发者ID:nates1973,项目名称:AutoMapper,代码行数:9,代码来源:NameValueCollectionMapperTests.cs


示例18: FormatValue

 public string FormatValue(ResolutionContext context)
 {
     if (context.SourceValue is decimal)
     {
         var money = (decimal)context.SourceValue;
         return money.FormatMoney();
     }
     return context.SourceValue.ToString();
 }
开发者ID:wangscript,项目名称:personal-hosting,代码行数:9,代码来源:MoneyFormatter.cs


示例19: FormatValue

 public string FormatValue(ResolutionContext context)
 {
     var sourceType = context.SourceType;
     if(sourceType != typeof(DateTime) && sourceType != typeof(DateTime?)) {
         throw new ArgumentException(sourceType.GetType().FullName + " is not a System.DateTime.", "context");
     }
     var dateTime = context.SourceValue as DateTime?;
     return dateTime.HasValue ? dateTime.Value.ToLongDateString() : "";
 }
开发者ID:JamesKovacs,项目名称:prairiedevcon2010-jquerydojo,代码行数:9,代码来源:DateFormatter.cs


示例20: FormatValue

 public string FormatValue(ResolutionContext context)
 {
     var items = context.DestinationValue as IList<SearchingFor>;
     if (items != null) {
         var list = new List<string>(items.Count);
         list.AddRange(items.Select(item => item.Search.ToString(CultureInfo.InvariantCulture)));
         return string.Join("", list);
     }
     return "";
 }
开发者ID:ramazanaktolu,项目名称:MS.Katusha,代码行数:10,代码来源:SearchingForFormatter.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# AutoMapper.TypeMap类代码示例发布时间:2022-05-24
下一篇:
C# AuroraDotNetEngine.ScriptData类代码示例发布时间: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