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


C# MapperConfiguration类代码示例

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


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

示例1: Get

        /// <summary>
        /// 取得所有客戶資料
        /// </summary>
        /// <returns></returns>
        public List<CustomerViewModel> Get()
        {
            #region 很累的寫法(一個一個丟)
            //List<CustomerViewModel> model = new List<CustomerViewModel>();
            //var DbResult = db.Get().AsQueryable();
            //
            //foreach (var item in DbResult)
            //{
            //    //將Customers的清單資料一個一個丟到CustomerViewModel
            //    CustomerViewModel _model = new CustomerViewModel();
            //    _model.CustomerID = item.CustomerID;
            //    _model.ContactName = item.ContactName;
            //    model.Add(_model);
            //}
            //
            //return model.AsQueryable();
            #endregion

            #region 改用AutoMapper
            var DbResult = db.Get().ToList();
            //AntoMapper before V4.2
            //Mapper.CreateMap<Customers, CustomerViewModel>();
            //
            //return Mapper.Map<List<Customers>, List<CustomerViewModel>>(DbResult);

            var config = new MapperConfiguration(cfg => cfg.CreateMap<Customers, CustomerViewModel>());
            config.AssertConfigurationIsValid();//驗證應對

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

示例2: NullChildItemTest

 public NullChildItemTest()
 {
     _config = new MapperConfiguration(cfg => {
         cfg.CreateMap<Parent, ParentDto>();
         cfg.AllowNullCollections = true;
     });
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:7,代码来源:NullableItemsTests.cs

示例3: Example

 public void Example()
 {
     var config = new MapperConfiguration(cfg =>
     {
         cfg.ConstructServicesUsing(ObjectFactory.GetInstance);
     });
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:7,代码来源:Initialization.cs

示例4: Should_map_source_properties

 public void Should_map_source_properties()
 {
     var config = new MapperConfiguration(cfg => { });
     dynamic destination = config.CreateMapper().Map<DynamicDictionary>(new Source());
     ((int)destination.Count).ShouldEqual(1);
     Assert.Equal(24, destination.Value);
 }
开发者ID:AutoMapper,项目名称:AutoMapper,代码行数:7,代码来源:DynamicMapperTests.cs

示例5: RegisterProfiles

        public static IMapper RegisterProfiles()
        {
            var config = new MapperConfiguration(
                cfg =>
                {
                    //Model para Dto
                    cfg.CreateMap<TarefaCadastroModel, TarefaDto>()
                        .ForMember(dto => dto.Usuario.Id,model => model.MapFrom(m => m.IdUsuario));

                    cfg.CreateMap<TarefaEdicaoModel, TarefaDto>()
                        .ForMember(dto => dto.Usuario.Id, model => model.MapFrom(m => m.IdUsuario));

                    cfg.CreateMap<TarefaExcluirModel, TarefaDto>()
                        .ForMember(dto => dto.Usuario.Id, model => model.MapFrom(m => m.IdUsuario));

                    cfg.CreateMap<TarefaEdicaoModel, TarefaDto>()
                        .ForMember(dto => dto.Usuario.Id, model => model.MapFrom(m => m.IdUsuario));

                    cfg.CreateMap<AutenticacaoModel, UsuarioDto>();

                    //Dto para Model
                    /*
                    cfg.CreateMap<Usuario, UsuarioDto>();
                    cfg.CreateMap<UsuarioDto, Usuario>();
                     */
                }
            );

            var mapper = config.CreateMapper();

            return mapper;
        }
开发者ID:gabrielsimas,项目名称:SistemasExemplo,代码行数:32,代码来源:AutoMapperConfig.cs

示例6: InMemoryIdentityManagerService

 public InMemoryIdentityManagerService(ICollection<InMemoryScope> scopes, ICollection<InMemoryClient> clients)
 {
     this._clients = clients;
     this._scopes = scopes;
     Config = new MapperConfiguration(cfg => {
         cfg.CreateMap<InMemoryClientClaim, ClientClaimValue>();
         cfg.CreateMap<ClientClaimValue, InMemoryClientClaim>();
         cfg.CreateMap<InMemoryClientSecret, ClientSecretValue>();
         cfg.CreateMap<ClientSecretValue, InMemoryClientSecret>();
         cfg.CreateMap<InMemoryClientIdPRestriction, ClientIdPRestrictionValue>();
         cfg.CreateMap<ClientIdPRestrictionValue, InMemoryClientIdPRestriction>();
         cfg.CreateMap<InMemoryClientPostLogoutRedirectUri, ClientPostLogoutRedirectUriValue>();
         cfg.CreateMap<ClientPostLogoutRedirectUriValue, InMemoryClientPostLogoutRedirectUri>();
         cfg.CreateMap<InMemoryClientRedirectUri, ClientRedirectUriValue>();
         cfg.CreateMap<ClientRedirectUriValue, InMemoryClientRedirectUri>();
         cfg.CreateMap<InMemoryClientCorsOrigin, ClientCorsOriginValue>();
         cfg.CreateMap<ClientCorsOriginValue, InMemoryClientCorsOrigin>();
         cfg.CreateMap<InMemoryClientCustomGrantType, ClientCustomGrantTypeValue>();
         cfg.CreateMap<ClientCustomGrantTypeValue, InMemoryClientCustomGrantType>();
         cfg.CreateMap<InMemoryClientScope, ClientScopeValue>();
         cfg.CreateMap<ClientScopeValue, InMemoryClientScope>();
         cfg.CreateMap<InMemoryScopeClaim, ScopeClaimValue>();
         cfg.CreateMap<ScopeClaimValue, InMemoryScopeClaim>();
         cfg.CreateMap<InMemoryScope, Scope>();
         cfg.CreateMap<Scope, InMemoryScope>();
     });
     Mapper = Config.CreateMapper();
 }
开发者ID:MAliM1988,项目名称:IdentityServer3.Admin,代码行数:28,代码来源:InMemoryIdentityManagerService.cs

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

示例8: Configure

        public static void Configure()
        {
            Config = new MapperConfiguration(cfg =>{});

            var profileConfig = (IConfiguration) Config;
            AutoMapperConfiguration.Configure(profileConfig);
        }
开发者ID:joncoello,项目名称:CSExample,代码行数:7,代码来源:AutoMapperConfig.cs

示例9: Example

            public void Example()
            {

                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap<Entity, EntityViewModel>()
                        .ForMember(m => m.SubEntityNames, o => o.MapFrom(f => f.SubEntities.Select(e => e.Name)));
                });

                var expression = config.ExpressionBuilder.CreateMapExpression<Entity, EntityViewModel>();

                var entity = new Entity
                {
                    EntityID = 1,
                    SubEntities =
                                     {
                                         new SubEntity {Name = "First", Description = "First Description"},
                                         new SubEntity {Name = "Second", Description = "First Description"},
                                     },
                    Title = "Entities"
                };

                var viewModel = expression.Compile()(entity);

                Assert.Equal(viewModel.EntityID, entity.EntityID);
                Assert.Contains("First", viewModel.SubEntityNames.ToArray());
                Assert.Contains("Second", viewModel.SubEntityNames.ToArray());


            }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:30,代码来源:NestedAndArraysTests.cs

示例10: GetCurrentPosition

 public IEnumerable<CurrentPosition> GetCurrentPosition()
 {
     var config = new MapperConfiguration(cfg => cfg.CreateMap<Position, CurrentPosition>());
     var mapper = config.CreateMapper();
     var result = new List<CurrentPosition>();
     var positions = _positionRepository.Get();
     foreach (var position in positions)
     {
         var current = mapper.Map<CurrentPosition>(position);
         if (current.CurrencyCode == "AUD")
         {
             current.CurrentPrice = _screenScrapper.GetYahooPrice($"{current.Key}.AX").Result;
         }
         else
         {
             current.CurrentPrice = _screenScrapper.GetYahooPrice(current.Key).Result / _screenScrapper.GetYahooPrice($"AUD{current.CurrencyCode}=X").Result;
         }
         //make the calculation
         current.TotalNow = current.Quantity * current.CurrentPrice;
         current.TotalWhenBought = current.Quantity * current.PriceWhenBought;
         current.DaysSinceBought = (int)(DateTime.Now - current.DateWhenBought).TotalDays;
         current.DifferenceMoney = current.TotalNow - current.TotalWhenBought;
         current.DifferencePercentage = (current.DifferenceMoney / current.TotalWhenBought) * 100;
         result.Add(current);
     }
     return result;
 }
开发者ID:ozcarzarate,项目名称:Asx,代码行数:27,代码来源:PositionService.cs

示例11: Should_map_properties_with_different_names

        public void Should_map_properties_with_different_names()
        {
            var config = new MapperConfiguration(c =>
            {
                c.ReplaceMemberName("Ä", "A");
                c.ReplaceMemberName("í", "i");
                c.ReplaceMemberName("Airlina", "Airline");
                c.CreateMap<Source, Destination>();
            });

            var source = new Source()
            {
                Value = 5,
                Ävíator = 3,
                SubAirlinaFlight = 4
            };

            //Mapper.AddMemberConvention().AddName<ReplaceName>(_ => _.AddReplace("A", "Ä").AddReplace("i", "í").AddReplace("Airline", "Airlina")).SetMemberInfo<FieldPropertyMemberInfo>();
            var mapper = config.CreateMapper();
            var destination = mapper.Map<Source, Destination>(source);

            Assert.AreEqual(source.Value, destination.Value);
            Assert.AreEqual(source.Ävíator, destination.Aviator);
            Assert.AreEqual(source.SubAirlinaFlight, destination.SubAirlineFlight);
        }
开发者ID:ouyh18,项目名称:LtePlatform,代码行数:25,代码来源:MemberNameReplacers.cs

示例12: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddCaching();
            services.AddSession();

            // Configuration
            services.Configure<EncryptionConfig>(Configuration.GetSection("Encryption"));
            services.Configure<EmailConfig>(Configuration.GetSection("Email"));
            services.Configure<RedisConfig>(Configuration.GetSection("Redis"));

            // Dependency Injection
            services.AddSingleton<IRedisService, RedisService>();
            services.AddSingleton<IEncryptionService, BasicEncryption>();
            services.AddSingleton<ISchedulerService, SchedulerService>();
            services.AddSingleton<IEmailService, EmailService>();
            services.AddTransient<IMojangService, MojangService>();
            services.AddTransient<IUserService, UserService>();
            services.AddTransient<IUsernameService, UsernameService>();

            // Automapper
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperProfile());
            });
            services.AddSingleton(sp => config.CreateMapper());
        }
开发者ID:AMerkuri,项目名称:MCNotifier,代码行数:29,代码来源:Startup.cs

示例13: Application_Start

		protected void Application_Start()
		{
			Dependency.Initialize(new LiveDependencyProvider());
			Dependency.Container.RegisterTypesIncludingInternals(
				typeof(CNCLib.ServiceProxy.Logic.MachineService).Assembly,
				typeof(CNCLib.Repository.MachineRepository).Assembly,
				typeof(CNCLib.Logic.Client.DynItemController).Assembly,
				typeof(CNCLib.Logic.MachineController).Assembly);
			Dependency.Container.RegisterType<IUnitOfWork, UnitOfWork<Repository.Context.CNCLibContext>>();

			Dependency.Container.RegisterType<IRest< CNCLib.Logic.Contracts.DTO.Machine>, MachineRest>();
			Dependency.Container.RegisterType<IRest<CNCLib.Logic.Contracts.DTO.LoadOptions>, LoadInfoRest>();
			Dependency.Container.RegisterType<IRest<CNCLib.Logic.Contracts.DTO.Item>, ItemRest>();

			var config = new MapperConfiguration(cfg =>
			{
				cfg.AddProfile<LogicAutoMapperProfile>();
			});

			var mapper = config.CreateMapper();

			Dependency.Container.RegisterInstance<IMapper>(mapper);

			AreaRegistration.RegisterAllAreas();
			GlobalConfiguration.Configure(WebApiConfig.Register);
			FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
			RouteConfig.RegisterRoutes(RouteTable.Routes);
			BundleConfig.RegisterBundles(BundleTable.Bundles);
		}
开发者ID:aiten,项目名称:CNCLib,代码行数:29,代码来源:Global.asax.cs

示例14: EntitiesMap

        static EntitiesMap()
        {
            Config = new MapperConfiguration(cfg => {
                cfg.CreateMap<IdentityScope, IdentityServer3.Core.Models.Scope>(MemberList.Destination)
                                .ForMember(x => x.Claims, opts => opts.MapFrom(src => src.ScopeClaims.Select(x => x)))
                                .ForMember(x => x.ScopeSecrets, opts => opts.MapFrom(src => src.ScopeSecrets.Select(x => x)));
                cfg.CreateMap<IdentityServer3.EntityFramework.Entities.ScopeClaim, IdentityServer3.Core.Models.ScopeClaim>(MemberList.Destination);
                cfg.CreateMap<IdentityServer3.EntityFramework.Entities.ScopeSecret, IdentityServer3.Core.Models.Secret>(MemberList.Destination)
                    .ForMember(dest => dest.Type, opt => opt.Condition(srs => srs.Value != null));

                cfg.CreateMap<IdentityServer3.EntityFramework.Entities.ClientSecret, IdentityServer3.Core.Models.Secret>(MemberList.Destination)
                     .ForMember(dest => dest.Type, opt => opt.Condition(srs => srs.Value != null));
                cfg.CreateMap<IdentityClient, IdentityServer3.Core.Models.Client>(MemberList.Destination)
                    .ForMember(x => x.UpdateAccessTokenClaimsOnRefresh, opt => opt.MapFrom(src => src.UpdateAccessTokenOnRefresh))
                    .ForMember(x => x.AllowAccessToAllCustomGrantTypes, opt => opt.MapFrom(src => src.AllowAccessToAllGrantTypes))
                    .ForMember(x => x.AllowedCustomGrantTypes, opt => opt.MapFrom(src => src.AllowedCustomGrantTypes.Select(x => x.GrantType)))
                    .ForMember(x => x.RedirectUris, opt => opt.MapFrom(src => src.RedirectUris.Select(x => x.Uri)))
                    .ForMember(x => x.PostLogoutRedirectUris, opt => opt.MapFrom(src => src.PostLogoutRedirectUris.Select(x => x.Uri)))
                    .ForMember(x => x.IdentityProviderRestrictions, opt => opt.MapFrom(src => src.IdentityProviderRestrictions.Select(x => x.Provider)))
                    .ForMember(x => x.AllowedScopes, opt => opt.MapFrom(src => src.AllowedScopes.Select(x => x.Scope)))
                    .ForMember(x => x.AllowedCorsOrigins, opt => opt.MapFrom(src => src.AllowedCorsOrigins.Select(x => x.Origin)))
                    .ForMember(x => x.Claims, opt => opt.MapFrom(src => src.Claims.Select(x => new Claim(x.Type, x.Value))));
            });
            
        }
开发者ID:IdentityServer,项目名称:IdentityServer3.Admin.EntityFramework,代码行数:25,代码来源:EntitiesMap.cs

示例15: Install

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            // register value resolvers
            container.Register(Types.FromAssembly(Assembly.GetExecutingAssembly()).BasedOn(typeof(IValueResolver<,,>)));

            // register profiles
            container.Register(Types.FromThisAssembly().BasedOn<Profile>().WithServiceBase().Configure(c => c.Named(c.Implementation.FullName)).LifestyleTransient());

            var profiles = container.ResolveAll<Profile>();

            var config = new MapperConfiguration(cfg =>
            {
                foreach (var profile in profiles)
                {
                    cfg.AddProfile(profile);
                }
            });

            container.Register(Component.For<MapperConfiguration>()
                .UsingFactoryMethod(() => config));

            container.Register(
                Component.For<IMapper>().UsingFactoryMethod(ctx => ctx.Resolve<MapperConfiguration>().CreateMapper(ctx.Resolve)));

            var mapper = container.Resolve<IMapper>();
            mapper.ConfigurationProvider.AssertConfigurationIsValid();
        }
开发者ID:CoditEU,项目名称:lunchorder,代码行数:27,代码来源:AutoMapperInstaller.cs


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