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


C# IMappingOptions类代码示例

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


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

示例1: MapDestinationCtorToSource

        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
                                                IMappingOptions options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList<MemberInfo>();

                if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
                    return false;

                var resolvers = members.Select(mi => mi.ToMemberGetter());

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray());

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
开发者ID:EdsonF,项目名称:AutoMapper,代码行数:27,代码来源:TypeMapFactory.cs

示例2: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options,
            MemberList memberList)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType, options);
            var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();

                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:redwyre,项目名称:AutoMapper,代码行数:32,代码来源:TypeMapFactory.cs

示例3: FindTypeMember

        private static MemberInfo FindTypeMember(IEnumerable<MemberInfo> modelProperties, IEnumerable<MethodInfo> getMethods, string nameToSearch, IMappingOptions mappingOptions)
        {
            MemberInfo pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, nameToSearch));
            if (pi != null)
                return pi;

            MethodInfo mi = getMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch));
            if (mi != null)
                return mi;

            pi = modelProperties.FirstOrDefault(prop => NameMatches(mappingOptions.SourceMemberNameTransformer(prop.Name), nameToSearch));
            if (pi != null)
                return pi;

            mi = getMethods.FirstOrDefault(m => NameMatches(mappingOptions.SourceMemberNameTransformer(m.Name), nameToSearch));
            if (mi != null)
                return mi;

            pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, mappingOptions.DestinationMemberNameTransformer(nameToSearch)));
            if (pi != null)
                return pi;

            pi = getMethods.FirstOrDefault(m => NameMatches(m.Name, mappingOptions.DestinationMemberNameTransformer(nameToSearch)));
            if (pi != null)
                return pi;

            return null;
        }
开发者ID:firestrand,项目名称:AutoMapper,代码行数:28,代码来源:TypeMapFactory.cs

示例4: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
            #if !SILVERLIGHT
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
            #else
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
            #endif
                }
            }
            if (!destinationType.IsAbstract && destinationType.IsClass)
            {
                foreach (var destCtor in destTypeInfo.GetConstructors().OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:patuww,项目名称:Automapper,代码行数:34,代码来源:TypeMapFactory.cs

示例5: CreateNameSnippet

 private NameSnippet CreateNameSnippet(IEnumerable<string> matches, int i, IMappingOptions mappingOptions)
 {
     return new NameSnippet
             {
                 First = String.Join(mappingOptions.SourceMemberNamingConvention.SeparatorCharacter, matches.Take(i).ToArray()),
                 Second = String.Join(mappingOptions.SourceMemberNamingConvention.SeparatorCharacter, matches.Skip(i).ToArray())
             };
 }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:8,代码来源:TypeMapFactory.cs

示例6: MapDestinationPropertyToSource

        private bool MapDestinationPropertyToSource(LinkedList<MemberInfo> resolvers, TypeInfo sourceType,
                                                    string nameToSearch, IMappingOptions mappingOptions)
        {
            if (string.IsNullOrEmpty(nameToSearch))
                return true;

            var sourceProperties = sourceType.GetPublicReadAccessors();
            var sourceNoArgMethods = sourceType.GetPublicNoArgMethods();
			var sourceNoArgExtensionMethods = sourceType.GetPublicNoArgExtensionMethods();

			MemberInfo resolver = FindTypeMember(sourceProperties, sourceNoArgMethods, sourceNoArgExtensionMethods, nameToSearch, mappingOptions);

            bool foundMatch = resolver != null;

            if (foundMatch)
            {
                resolvers.AddLast(resolver);
            }
            else
            {
                string[] matches = mappingOptions.DestinationMemberNamingConvention.SplittingExpression
                    .Matches(nameToSearch)
                    .Cast<Match>()
                    .Select(m => m.Value)
                    .ToArray();

                for (int i = 1; (i <= matches.Length) && (!foundMatch); i++)
                {
                    NameSnippet snippet = CreateNameSnippet(matches, i, mappingOptions);

					var valueResolver = FindTypeMember(sourceProperties, sourceNoArgMethods, sourceNoArgExtensionMethods, snippet.First,
                                                       mappingOptions);

                    if (valueResolver != null)
                    {
                        resolvers.AddLast(valueResolver);

                        foundMatch = MapDestinationPropertyToSource(resolvers,
                                                                    GetTypeInfo(valueResolver.GetMemberType(), mappingOptions.SourceExtensionMethods),
                                                                    snippet.Second, mappingOptions);

                        if (!foundMatch)
                        {
                            resolvers.RemoveLast();
                        }
                    }
                }
            }

            return foundMatch;
        }
开发者ID:EdsonF,项目名称:AutoMapper,代码行数:51,代码来源:TypeMapFactory.cs

示例7: NameMatches

        private static bool NameMatches(string memberName, string nameToMatch, IMappingOptions mappingOptions)
        {
            var possibleSourceNames = PossibleNames(memberName, mappingOptions.Aliases, mappingOptions.Prefixes,
                                                          mappingOptions.Postfixes);
            var possibleDestNames = PossibleNames(nameToMatch, mappingOptions.Aliases, mappingOptions.DestinationPrefixes,
                                                          mappingOptions.DestinationPostfixes);

            var all =
                from sourceName in possibleSourceNames
                from destName in possibleDestNames
                select new {sourceName, destName};

            return all.Any(pair => String.Compare(pair.sourceName, pair.destName, StringComparison.OrdinalIgnoreCase) == 0);
        }
开发者ID:sliplow,项目名称:LisaChowArtwork,代码行数:14,代码来源:TypeMapFactory.cs

示例8: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter()).Cast<IValueResolver>();
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
                }
            }
            return typeMap;
        }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:20,代码来源:TypeMapFactory.cs

示例9: FindTypeMember

        private static MemberInfo FindTypeMember(IEnumerable<MemberInfo> modelProperties,
            IEnumerable<MethodInfo> getMethods,
            IEnumerable<MethodInfo> getExtensionMethods,
            string nameToSearch,
            IMappingOptions mappingOptions)
        {
            var pi = modelProperties.FirstOrDefault(prop => NameMatches(prop.Name, nameToSearch, mappingOptions));
            if (pi != null)
                return pi;

            var mi = getMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch, mappingOptions));
            if (mi != null)
                return mi;

            mi = getExtensionMethods.FirstOrDefault(m => NameMatches(m.Name, nameToSearch, mappingOptions));
            if (mi != null)
                return mi;

            return null;
        }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:20,代码来源:TypeMapFactory.cs

示例10: GetTypeInfo

 private TypeInfo GetTypeInfo(Type type, IMappingOptions mappingOptions)
 {
     return GetTypeInfo(type, mappingOptions.ShouldMapProperty, mappingOptions.ShouldMapField, mappingOptions.SourceExtensionMethods);
 }
开发者ID:redwyre,项目名称:AutoMapper,代码行数:4,代码来源:TypeMapFactory.cs

示例11: Establish_context

        protected override void Establish_context()
        {
            INamingConvention namingConvention = CreateStub<INamingConvention>();
            namingConvention.Stub(nc => nc.SeparatorCharacter).Return("__");

            _mappingOptions = CreateStub<IMappingOptions>();
            _mappingOptions.SourceMemberNamingConvention = namingConvention;
            _mappingOptions.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
            _mappingOptions.SourceMemberNameTransformer = s => s;
            _mappingOptions.DestinationMemberNameTransformer = s => s;

            _factory = new TypeMapFactory();
        }
开发者ID:joshuaflanagan,项目名称:AutoMapper,代码行数:13,代码来源:TypeMapFactorySpecs.cs

示例12: GetTypeInfo

        private TypeInfo GetTypeInfo(Type type, IEnumerable<MethodInfo> extensionMethodsToSearch, IMappingOptions mappingOptions)
        {
            TypeInfo typeInfo = _typeInfos.GetOrAdd(type, t => new TypeInfo(type, mappingOptions.BindingFlags, extensionMethodsToSearch));

            return typeInfo;
        }
开发者ID:tdbrian,项目名称:AutoMapper,代码行数:6,代码来源:TypeMapFactory.cs

示例13: CreateNameSnippet

 private NameSnippet CreateNameSnippet(IEnumerable<string> matches, int i, IMappingOptions mappingOptions)
 {
     return new NameSnippet
     {
         First =
             string.Join("", matches.Take(i).ToArray()),
         Second =
             string.Join("", matches.Skip(i).ToArray())
     };
 }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:10,代码来源:TypeMapFactory.cs

示例14: Establish_context

        protected override void Establish_context()
        {
            var namingConvention = new StubNamingConvention();

            namingConvention.SplittingExpression = new Regex(@"[\p{Ll}0-9]*(?=_?)");

            _mappingOptions = new StubMappingOptions();
            _mappingOptions.SourceMemberNamingConvention = new PascalCaseNamingConvention();
            _mappingOptions.DestinationMemberNamingConvention = namingConvention;

            _factory = new TypeMapFactory();
        }
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:12,代码来源:TypeMapFactorySpecs.cs


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