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


C# MapperConfiguration.AssertConfigurationIsValid方法代码示例

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


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

示例1: AutoMapper_DomainToDataMappingTest

 public void AutoMapper_DomainToDataMappingTest()
 {
     var config = new MapperConfiguration(cfg => {
         DomainToDataMapping.CreateMaps(cfg);
     });
     config.AssertConfigurationIsValid();
 }
开发者ID:hakelimopu,项目名称:wandermaze,代码行数:7,代码来源:AutoMapperTests.cs

示例2: Get

        // <summary>取得所有客戶資料(分頁)</summary>
        /// <returns></returns>
        public IQueryable<CustomerViewModel> Get(int CurrPage, int PageSize, out int TotalRow)
        {
            // 取得所有筆數
            TotalRow = db.Get().ToList().Count();

            // 使用Linq篩選分頁
            var DbResult = db.Get().ToList().Skip((CurrPage - 1) * PageSize).Take(PageSize).ToList();

            #region AutoMapper V4.2 以前的寫法
            // Mapping到ViewModel
            
            //
            //Mapper.CreateMap<Customers, CustomerViewModel>();
            //return Mapper.Map<List<Customers>, List<CustomerViewModel>>(DbResult).AsQueryable();
            #endregion

            #region 新版AutoMapper 寫法
            //AutoMapper V >= 4.2 的寫法
            var config = new MapperConfiguration(cfg => cfg.CreateMap<Customers, CustomerViewModel>());
            config.AssertConfigurationIsValid();//驗證應對

            var mapper = config.CreateMapper();
            return mapper.Map<List<Customers>, List<CustomerViewModel>>(DbResult).AsQueryable();
            #endregion
        }
开发者ID:chao1017,项目名称:MVC5_Labs,代码行数:27,代码来源:CustomerService.cs

示例3: Should_map_the_existing_array_elements_over

            public void Should_map_the_existing_array_elements_over()
            {
                var sourceList = new List<SourceObject>();
                var destList = new List<DestObject>();

                var config = new MapperConfiguration(cfg => cfg.CreateMap<SourceObject, DestObject>().PreserveReferences());
                config.AssertConfigurationIsValid();

                var source1 = new SourceObject
                {
                    Id = 1,
                };
                sourceList.Add(source1);

                var source2 = new SourceObject
                {
                    Id = 2,
                };
                sourceList.Add(source2);

                source1.AddChild(source2); // This causes the problem

                config.CreateMapper().Map(sourceList, destList);

                destList.Count.ShouldEqual(2);
                destList[0].Children.Count.ShouldEqual(1);
                destList[0].Children[0].ShouldBeSameAs(destList[1]);
            }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:28,代码来源:DuplicateValuesBug.cs

示例4: ConfigureMapper

        private void ConfigureMapper()
        {
            //var config = Mapper.Configuration;
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<Record, JWSModels.Record>().ForMember(target => target.TierLevel, opts => opts.Ignore()).ForMember(target => target.TierLevelId, opts => opts.Ignore()).ForMember(target => target.TierName, opts => opts.Ignore()).ForMember(target => target.UserLevel, opts => opts.Ignore()).ForMember(target => target.IndexCode, opts => opts.Ignore()).ForMember(target => target.NumberPayPeriods, opts => opts.Ignore()).ForMember(target => target.PayRatePerPayPeriod, opts => opts.Ignore()).ForMember(target => target.AnnualHours, opts => opts.Ignore()).ForMember(target => target.AnnualPayRate, opts => opts.Ignore()).ForMember(target => target.AddressLine1, opts => opts.ResolveUsing(c => c.Address1)).ForMember(target => target.AddressLine2, opts => opts.ResolveUsing(c => c.Address2)).ForMember(target => target.City, opts => opts.ResolveUsing(c => c.City)).ForMember(target => target.DateOfBirth, opts => opts.ResolveUsing(c => c.DateOfBirth)).ForMember(target => target.DaysWorkedPerWeek, opts => opts.Ignore()).ForMember(target => target.EmployeeId, opts => opts.Ignore()).ForMember(target => target.FirstName, opts => opts.ResolveUsing(c => c.FirstName)).ForMember(target => target.Gender, opts => opts.ResolveUsing(c => c.Gender)).ForMember(target => target.HireDate, opts => opts.ResolveUsing(c => c.HireDate)).ForMember(target => target.JobClassCode, opts => opts.Ignore()).ForMember(target => target.JobDescription, opts => opts.Ignore()).ForMember(target => target.LastName, opts => opts.ResolveUsing(c => c.LastName)).ForMember(target => target.OccupationCode, opts => opts.Ignore()).ForMember(target => target.PayRate, opts => opts.Ignore()).ForMember(target => target.HoursWorkedPerDay, opts => opts.Ignore()).ForMember(target => target.PayRateType, opts => opts.Ignore()).ForMember(target => target.PhoneNumber, opts => opts.Ignore()).ForMember(target => target.SocialSecurityNumber, opts => opts.ResolveUsing(c => c.SocialSecurityNumber)).ForMember(target => target.State, opts => opts.ResolveUsing(c => c.State)).ForMember(target => target.UnionCode, opts => opts.Ignore()).ForMember(target => target.NameSuffix, opts => opts.Ignore()).ForMember(target => target.ZipCode, opts => opts.ResolveUsing(c => c.ZipCode)).AfterMap((src, target) =>
                {
                    TierMapping tierMapping; //= new TierMapping(this, target);

                    if (!src.DepartmentName.IsEmpty())
                    {
                        tierMapping = new TierMapping(this, target, src.DepartmentName);
                        tierMapping.MapOrgLevel(Tiers4, 4, src.DepartmentName.ToUpper(), src.DepartmentName.ToUpper(), MissingOrganizationMappingEncountered, MultipleOrganizationMappingEncountered);
                    }

                    if (!src.DivisionName.IsEmpty())
                    {
                        tierMapping = new TierMapping(this, target, src.DivisionName);
                        tierMapping.MapOrgLevel(Tiers3, 3, src.DivisionName.ToUpper(), src.DivisionName.ToUpper(), MissingOrganizationMappingEncountered, MultipleOrganizationMappingEncountered);
                    }
                });
            });
            config.AssertConfigurationIsValid();
            mapper = config.CreateMapper();
        }
开发者ID:briandarley,项目名称:ClientImport,代码行数:25,代码来源:ModelBuilder.cs

示例5: Initialize

        public static void Initialize()
        {
            MapperConfig = new MapperConfiguration(mapper =>
            {
                mapper.CreateMap<ParentTouristSite, FullTouristSiteResponseModel>()
                    .ForMember(
                        m => m.Type,
                        opts => opts.MapFrom(p => (int)p.Type)); ;

                mapper.CreateMap<TouristSite, TouristSiteResponseModel>()
                    .ForMember(
                        m => m.Rating,
                        opts => opts.MapFrom(t => t.Ratings.Count > 0 ? t.Ratings.Sum(r => r.Value) / t.Ratings.Count : 0))
                    .ForMember(
                        m => m.Status,
                        opts => opts.MapFrom(t => (int)t.Status));

                mapper.CreateMap<TouristSite, SimpleTouristSiteResponseModel>();

                mapper.CreateMap<ParentTouristSite, SimpleParentTouristSiteResponseModel>();

                mapper.CreateMap<User, ScoreboardResponseModel>().ForMember(
                        m => m.Rating,
                        opts => opts.MapFrom(u => u.CalculatedRating));

                mapper.CreateMap<User, FullUserResponseModel>();

                mapper.CreateMap<Badge, BadgeResponseModel>().ForMember(
                        m => m.Title,
                        opts => opts.MapFrom(b => Enum.GetName(typeof(BadgeTitle), b.Title)));
            });

            MapperConfig.AssertConfigurationIsValid();
        }
开发者ID:TsvetanMilanov,项目名称:BG-Tourist-Guide-Server,代码行数:34,代码来源:AutoMapperConfig.cs

示例6: Example

        public void Example()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<ContainsASrc, ContainsADest>();

                cfg.CreateMap<ASrc, ADest>()
                    .Include<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<CSrc, CDest>();
            });

            var expectedCSrc = new CSrc() {StringA = "A", StringB = "B", StringC = "C"};
            var expectedBSrc = new BSrc() {StringA = "A", StringB = "B"};

            var expectedContCSrc = new ContainsASrc() {A = expectedCSrc};
            var expectedContBSrc = new ContainsASrc() {A = expectedBSrc};

            var mapper = config.CreateMapper();
            var actualContCDest = mapper.Map<ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = mapper.Map<ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            config.AssertConfigurationIsValid();
            actualContBDest.ShouldNotBeNull();
            actualContCDest.ShouldNotBeNull();
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:30,代码来源:DeepInheritanceIssue.cs

示例7: ExampleIgnoring

            public void ExampleIgnoring()
            {
                var config = new MapperConfiguration(cfg =>
                    cfg.CreateMap<Source, Destination>().ForMember(m => m.SomeValuefff, opt => opt.Ignore())
                    );

                config.AssertConfigurationIsValid();
            }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:8,代码来源:ConfigurationValidation.cs

示例8: Configure

 public void Configure(IEnumerable<IAutoMapperTypeConfigurator> autoMapperTypeConfigurators)
 {
     var mapperConfiguration = new MapperConfiguration(cfg =>
     {
         autoMapperTypeConfigurators.ToList().ForEach(x => x.Configure(cfg));
     });
     mapperConfiguration.AssertConfigurationIsValid();
 }
开发者ID:Ladex,项目名称:webapi,代码行数:8,代码来源:AutoMapperConfigurator.cs

示例9: Configure

        public static IMapper Configure()
        {
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap<Album, HomeIndexAlbumViewModel>();
            });

            config.AssertConfigurationIsValid();

            return config.CreateMapper();
        }
开发者ID:SiCannon,项目名称:Aspnet5ProofOfConcept,代码行数:10,代码来源:AutoMapperConfig.cs

示例10: OpportunityRepository

 public OpportunityRepository()
 {
     config = new MapperConfiguration(cfg =>
     {
         cfg.CreateMap<Opportunity, OpportunityDocument>();
         cfg.CreateMap<OpportunityDocument, Opportunity>();
     });
     config.AssertConfigurationIsValid();
     mapper = config.CreateMapper();
 }
开发者ID:skalinkin,项目名称:PersonalAssistant,代码行数:10,代码来源:OpportunityRepository.cs

示例11: Should_map_enum_to_nullable

        public void Should_map_enum_to_nullable()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap<DummySource, DummyDestination>());
            config.AssertConfigurationIsValid();
            DummySource src = new DummySource() { Dummy = DummyTypes.Bar };

            var destination = config.CreateMapper().Map<DummySource, DummyDestination>(src);

            destination.Dummy.ShouldEqual((int)DummyTypes.Bar);
        }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:10,代码来源:CannotConvertEnumToNullable.cs

示例12: included_mapping_should_inherit_base_mappings_should_not_throw

 public void included_mapping_should_inherit_base_mappings_should_not_throw()
 {
     var config = new MapperConfiguration(cfg =>
     {
         cfg.CreateMap<ModelObject, DtoObject>()
             .ForMember(d => d.BaseString, m => m.MapFrom(s => s.DifferentBaseString))
             .Include<ModelSubObject, DtoSubObject>();
         cfg.CreateMap<ModelSubObject, DtoSubObject>();
     });
     config.AssertConfigurationIsValid();
 }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:11,代码来源:IncludedBaseMappingShouldInheritBaseMappings.cs

示例13: GlobalIgnore_ignores_properties_with_names_matching_but_different_types

        public void GlobalIgnore_ignores_properties_with_names_matching_but_different_types()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddGlobalIgnore("ShouldBeMapped");
                cfg.CreateMap<Source, DestinationWrongType>();
            });

            config.CreateMapper().Map<Source, DestinationWrongType>(new Source { ShouldBeMapped = "true" });
            config.AssertConfigurationIsValid();
        }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:11,代码来源:IgnoreAllTests.cs

示例14: InitialAutomapper

 private static void InitialAutomapper()
 {
     if(mapper == null)
     {
         lock(mapperSyncRoot)
         {
             MapperConfiguration configuration = new MapperConfiguration(MapperConfigure);
             configuration.AssertConfigurationIsValid();
             mapper = configuration.CreateMapper();
         }
     }
 }
开发者ID:harrison314,项目名称:MapperPerformace,代码行数:12,代码来源:AutoMapperAdapter.cs

示例15: more_specific_map_should_override_base_ignore_passes_validation

 public void more_specific_map_should_override_base_ignore_passes_validation()
 {
     var config = new MapperConfiguration(cfg =>
     {
         cfg.CreateMap<ModelObject, DtoObject>()
             .ForMember(d => d.BaseString, m => m.Ignore())
             .Include<ModelSubObject, DtoSubObject>();
         cfg.CreateMap<ModelSubObject, DtoSubObject>()
             .ForMember(d => d.BaseString, m => m.MapFrom(s => s.DifferentBaseString));
     });
     config.AssertConfigurationIsValid();
 }
开发者ID:garora,项目名称:AutoMapper,代码行数:12,代码来源:IncludedBaseMappingShouldInheritBaseMappings.cs


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