本文整理汇总了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();
}
示例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
}
示例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]);
}
示例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();
}
示例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();
}
示例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();
}
示例7: ExampleIgnoring
public void ExampleIgnoring()
{
var config = new MapperConfiguration(cfg =>
cfg.CreateMap<Source, Destination>().ForMember(m => m.SomeValuefff, opt => opt.Ignore())
);
config.AssertConfigurationIsValid();
}
示例8: Configure
public void Configure(IEnumerable<IAutoMapperTypeConfigurator> autoMapperTypeConfigurators)
{
var mapperConfiguration = new MapperConfiguration(cfg =>
{
autoMapperTypeConfigurators.ToList().ForEach(x => x.Configure(cfg));
});
mapperConfiguration.AssertConfigurationIsValid();
}
示例9: Configure
public static IMapper Configure()
{
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<Album, HomeIndexAlbumViewModel>();
});
config.AssertConfigurationIsValid();
return config.CreateMapper();
}
示例10: OpportunityRepository
public OpportunityRepository()
{
config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Opportunity, OpportunityDocument>();
cfg.CreateMap<OpportunityDocument, Opportunity>();
});
config.AssertConfigurationIsValid();
mapper = config.CreateMapper();
}
示例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);
}
示例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();
}
示例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();
}
示例14: InitialAutomapper
private static void InitialAutomapper()
{
if(mapper == null)
{
lock(mapperSyncRoot)
{
MapperConfiguration configuration = new MapperConfiguration(MapperConfigure);
configuration.AssertConfigurationIsValid();
mapper = configuration.CreateMapper();
}
}
}
示例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();
}