本文整理汇总了C#中MemberMapper.Project方法的典型用法代码示例。如果您正苦于以下问题:C# MemberMapper.Project方法的具体用法?C# MemberMapper.Project怎么用?C# MemberMapper.Project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberMapper
的用法示例。
在下文中一共展示了MemberMapper.Project方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NestedPropertyWithCustomMappingWorks
public void NestedPropertyWithCustomMappingWorks()
{
var mapper = new MemberMapper();
mapper.CreateMap<Address, AddressDto>(src => new AddressDto
{
CountryName = src.Country.Name
});
var projection = mapper.Project<CustomerSingleAddress, CustomerSingleAddressDto>();
var method = projection.Compile();
var result = method(new CustomerSingleAddress
{
Address =
new Address
{
Country = new Country
{
Name = "X"
}
}
});
Assert.AreEqual("X", result.Address.CountryName);
}
示例2: AsProjectableFirstThrowsWhenLessThanOne
public void AsProjectableFirstThrowsWhenLessThanOne()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
};
var result = source.AsQueryable().AsProjectable().First(mapper.Project<SourceType, DestinationType>());
}
示例3: AsProjectableFirstOrDefaultReturnsDefaultWhenLessThanOne
public void AsProjectableFirstOrDefaultReturnsDefaultWhenLessThanOne()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
};
var result = source.AsQueryable().AsProjectable().FirstOrDefault(mapper.Project<SourceType, DestinationType>());
Assert.IsNull(result);
}
示例4: CustomMappingsWorkWithProjections
public void CustomMappingsWorkWithProjections()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType>(src => new DestinationType
{
FullName = src.FirstName + " " + src.LastName
});
var projection = mapper.Project<SourceType, DestinationType>().Compile();
var result = projection(new SourceType { FirstName = "First", LastName = "Last" });
Assert.AreEqual("First Last", result.FullName);
}
示例5: NestedProjectionWorks
public void NestedProjectionWorks()
{
var mapper = new MemberMapper();
var result = mapper.Project<ComplexSourceType, ComplexDestinationType>().Compile()(
new ComplexSourceType
{
ID = 1,
Foo = new NestedSourceType
{
Name = "Foo"
}
});
Assert.AreEqual(1, result.ID);
Assert.AreEqual("Foo", result.Foo.Name);
}
示例6: ProjectionOfArrayToICollectionWorks
public void ProjectionOfArrayToICollectionWorks()
{
var mapper = new MemberMapper();
var projection = mapper.Project<ArrayType, OtherICollectionType>().Compile();
var result = projection(new ArrayType
{
Foos = new NestedEnumerableSourceType[]
{
new NestedEnumerableSourceType
{
Name = "Test"
}
}
});
Assert.AreEqual("Test", result.Foos.Single().Name);
}
示例7: AsProjectableFirstWorks
public void AsProjectableFirstWorks()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
new SourceType
{
ID = 10
},
new SourceType
{
ID = 20
}
};
var result = source.AsQueryable().AsProjectable().First(mapper.Project<SourceType, DestinationType>());
Assert.AreEqual(10, result.ID);
}
示例8: NoCollectionMappingOptionIsRespected
public void NoCollectionMappingOptionIsRespected()
{
var mapper = new MemberMapper();
mapper.Options.Projection.MapCollectionMembers = false;
var projection = mapper.Project<IListType, OtherListType>().Compile();
var result = projection(new IListType
{
ID = 10,
Foos = new List<NestedEnumerableSourceType>
{
new NestedEnumerableSourceType
{
Name = "Test"
}
}
});
Assert.IsNull(result.Foos);
}
示例9: NonNullableToNullableWithProjectionsWorksAsExpected
public void NonNullableToNullableWithProjectionsWorksAsExpected()
{
var mapper = new MemberMapper();
var result = mapper.Project<EnumSourceType, EnumDestinationType>().Compile()(new EnumSourceType { Foo = FooEnum.B });
Assert.AreEqual(FooEnum.B, result.Foo);
}
示例10: ProjectionsAffectMaps
public void ProjectionsAffectMaps()
{
var mapper = new MemberMapper();
mapper.CreateProjection<SourceType, DestinationType>(src => new DestinationType
{
FullName = src.FirstName + " " + src.LastName
});
var projection = mapper.Project<SourceType, DestinationType>().Compile();
var source = new SourceType { FirstName = "First", LastName = "Last" };
var result = projection(source);
Assert.AreEqual("First Last", result.FullName);
result = mapper.Map<SourceType, DestinationType>(source);
Assert.AreEqual("First Last", result.FullName);
}
示例11: PagingOnProjectableWorks
public void PagingOnProjectableWorks()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
new SourceType
{
ID = 10
},
new SourceType
{
ID = 20
},
new SourceType
{
ID = 30
}
};
var result = source.AsQueryable().AsCollectionProjectable().Page(mapper.Project<SourceType, DestinationType>(), 0, 2);
Assert.AreEqual(2, result.Count);
Assert.AreEqual(10, result.First().ID);
Assert.AreEqual(20, result.Skip(1).First().ID);
}
示例12: AsProjectableToListWorks
public void AsProjectableToListWorks()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
new SourceType
{
ID = 10
},
new SourceType
{
ID = 20
}
};
var result = source.AsQueryable().AsProjectable().ToList(mapper.Project<SourceType, DestinationType>());
Assert.IsTrue(source.Select(s => s.ID).SequenceEqual(result.Select(s => s.ID)));
}
示例13: AsProjectableSingleThrowsWhenMoreThanOne
public void AsProjectableSingleThrowsWhenMoreThanOne()
{
var mapper = new MemberMapper();
var source = new List<SourceType>
{
new SourceType
{
ID = 10
},
new SourceType
{
ID = 20
}
};
var result = source.AsQueryable().AsProjectable().Single(mapper.Project<SourceType, DestinationType>());
Assert.AreEqual(1, result.ID);
}
示例14: SimpleProjectionWorks
public void SimpleProjectionWorks()
{
var mapper = new MemberMapper();
var result = mapper.Project<SourceType, DestinationType>().Compile()(new SourceType { ID = 1 });
Assert.AreEqual(1, result.ID);
}
示例15: ProjectionOfListToListWorks
public void ProjectionOfListToListWorks()
{
var mapper = new MemberMapper();
var projection = mapper.Project<ListType, OtherListType>().Compile();
var result = projection(new ListType
{
Foos = new List<NestedEnumerableSourceType>
{
new NestedEnumerableSourceType
{
Name = "Test"
}
}
});
Assert.AreEqual("Test", result.Foos.Single().Name);
}