Merge pull request #1616 from abpframework/maliming/AutomapperPrefix

fix #1615 Add a prefix to AutoMap*Attribute.
pull/1710/head
Halil İbrahim Kalkan 6 years ago committed by GitHub
commit 7b4037052c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -146,7 +146,7 @@ public interface IBookAppService : IApplicationService
`BookDto` is a simple [DTO](Data-Transfer-Objects.md) class defined as below: `BookDto` is a simple [DTO](Data-Transfer-Objects.md) class defined as below:
````csharp ````csharp
[AutoMapFrom(typeof(Book))] //Defines the mapping [AbpAutoMapFrom(typeof(Book))] //Defines the mapping
public class BookDto public class BookDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
@ -159,7 +159,7 @@ public class BookDto
} }
```` ````
* `BookDto` defines `[AutoMapFrom(typeof(Book))]` attribute to create the object mapping from `Book` to `BookDto`. * `BookDto` defines `[AbpAutoMapFrom(typeof(Book))]` attribute to create the object mapping from `Book` to `BookDto`.
Then you can implement the `GetAsync` method as shown below: Then you can implement the `GetAsync` method as shown below:
@ -248,7 +248,7 @@ public interface IAsyncCrudAppService<
DTO classes used in this example are `BookDto` and `CreateUpdateBookDto`: DTO classes used in this example are `BookDto` and `CreateUpdateBookDto`:
````csharp ````csharp
[AutoMapFrom(typeof(Book))] [AbpAutoMapFrom(typeof(Book))]
public class BookDto : AuditedEntityDto<Guid> public class BookDto : AuditedEntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
@ -258,7 +258,7 @@ public class BookDto : AuditedEntityDto<Guid>
public float Price { get; set; } public float Price { get; set; }
} }
[AutoMapTo(typeof(Book))] [AbpAutoMapTo(typeof(Book))]
public class CreateUpdateBookDto public class CreateUpdateBookDto
{ {
[Required] [Required]

@ -146,7 +146,7 @@ public interface IBookAppService : IApplicationService
`BookDto`是一个简单的[DTO](Data-Transfer-Objects.md)类, 定义如下: `BookDto`是一个简单的[DTO](Data-Transfer-Objects.md)类, 定义如下:
````csharp ````csharp
[AutoMapFrom(typeof(Book))] //Defines the mapping [AbpAutoMapFrom(typeof(Book))] //Defines the mapping
public class BookDto public class BookDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
@ -159,7 +159,7 @@ public class BookDto
} }
```` ````
* `BookDto`定义了`[AutoMapFrom(typeof(Book))]`属性来从创建对象映射Book到BookDto. * `BookDto`定义了`[AbpAutoMapFrom(typeof(Book))]`属性来从创建对象映射Book到BookDto.
然后你可以实现`GetAsync`方法. 如下所示: 然后你可以实现`GetAsync`方法. 如下所示:
@ -247,7 +247,7 @@ public interface IAsyncCrudAppService<
示例中使用的DTO类是`BookDto`和`CreateUpdateBookDto`: 示例中使用的DTO类是`BookDto`和`CreateUpdateBookDto`:
````csharp ````csharp
[AutoMapFrom(typeof(Book))] [AbpAutoMapFrom(typeof(Book))]
public class BookDto : AuditedEntityDto<Guid> public class BookDto : AuditedEntityDto<Guid>
{ {
public string Name { get; set; } public string Name { get; set; }
@ -257,7 +257,7 @@ public class BookDto : AuditedEntityDto<Guid>
public float Price { get; set; } public float Price { get; set; }
} }
[AutoMapTo(typeof(Book))] [AbpAutoMapTo(typeof(Book))]
public class CreateUpdateBookDto public class CreateUpdateBookDto
{ {
[Required] [Required]

@ -4,9 +4,9 @@ using AutoMapper;
namespace Volo.Abp.AutoMapper namespace Volo.Abp.AutoMapper
{ {
public class AutoMapAttribute : AutoMapAttributeBase public class AbpAutoMapAttribute : AbpAutoMapAttributeBase
{ {
public AutoMapAttribute(params Type[] targetTypes) public AbpAutoMapAttribute(params Type[] targetTypes)
: base(targetTypes) : base(targetTypes)
{ {

@ -3,11 +3,11 @@ using AutoMapper;
namespace Volo.Abp.AutoMapper namespace Volo.Abp.AutoMapper
{ {
public abstract class AutoMapAttributeBase : Attribute public abstract class AbpAutoMapAttributeBase : Attribute
{ {
public Type[] TargetTypes { get; } public Type[] TargetTypes { get; }
protected AutoMapAttributeBase(params Type[] targetTypes) protected AbpAutoMapAttributeBase(params Type[] targetTypes)
{ {
TargetTypes = targetTypes; TargetTypes = targetTypes;
} }

@ -4,17 +4,17 @@ using AutoMapper;
namespace Volo.Abp.AutoMapper namespace Volo.Abp.AutoMapper
{ {
public class AutoMapFromAttribute : AutoMapAttributeBase public class AbpAutoMapFromAttribute : AbpAutoMapAttributeBase
{ {
public MemberList MemberList { get; set; } = MemberList.Destination; public MemberList MemberList { get; set; } = MemberList.Destination;
public AutoMapFromAttribute(params Type[] targetTypes) public AbpAutoMapFromAttribute(params Type[] targetTypes)
: base(targetTypes) : base(targetTypes)
{ {
} }
public AutoMapFromAttribute(MemberList memberList, params Type[] targetTypes) public AbpAutoMapFromAttribute(MemberList memberList, params Type[] targetTypes)
: this(targetTypes) : this(targetTypes)
{ {
MemberList = memberList; MemberList = memberList;

@ -4,17 +4,17 @@ using AutoMapper;
namespace Volo.Abp.AutoMapper namespace Volo.Abp.AutoMapper
{ {
public class AutoMapToAttribute : AutoMapAttributeBase public class AbpAutoMapToAttribute : AbpAutoMapAttributeBase
{ {
public MemberList MemberList { get; set; } = MemberList.Source; public MemberList MemberList { get; set; } = MemberList.Source;
public AutoMapToAttribute(params Type[] targetTypes) public AbpAutoMapToAttribute(params Type[] targetTypes)
: base(targetTypes) : base(targetTypes)
{ {
} }
public AutoMapToAttribute(MemberList memberList, params Type[] targetTypes) public AbpAutoMapToAttribute(MemberList memberList, params Type[] targetTypes)
: this(targetTypes) : this(targetTypes)
{ {
MemberList = memberList; MemberList = memberList;

@ -70,9 +70,9 @@ namespace Volo.Abp.AutoMapper
var types = typeFinder.Types.Where(type => var types = typeFinder.Types.Where(type =>
{ {
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
return typeInfo.IsDefined(typeof(AutoMapAttribute)) || return typeInfo.IsDefined(typeof(AbpAutoMapAttribute)) ||
typeInfo.IsDefined(typeof(AutoMapFromAttribute)) || typeInfo.IsDefined(typeof(AbpAutoMapFromAttribute)) ||
typeInfo.IsDefined(typeof(AutoMapToAttribute)); typeInfo.IsDefined(typeof(AbpAutoMapToAttribute));
} }
).ToArray(); ).ToArray();

@ -8,7 +8,7 @@ namespace Volo.Abp.AutoMapper
{ {
public static void CreateAutoAttributeMaps(this IMapperConfigurationExpression configuration, Type type) public static void CreateAutoAttributeMaps(this IMapperConfigurationExpression configuration, Type type)
{ {
foreach (var autoMapAttribute in type.GetTypeInfo().GetCustomAttributes<AutoMapAttributeBase>()) foreach (var autoMapAttribute in type.GetTypeInfo().GetCustomAttributes<AbpAutoMapAttributeBase>())
{ {
autoMapAttribute.CreateMap(configuration, type); autoMapAttribute.CreateMap(configuration, type);
} }

@ -38,7 +38,7 @@ namespace Volo.Abp.AutoMapper
} }
[AutoMapFrom(typeof(MyBaseClass))] [AbpAutoMapFrom(typeof(MyBaseClass))]
public class MyTargetClassToMap public class MyTargetClassToMap
{ {
public string Value { get; set; } public string Value { get; set; }
@ -63,13 +63,13 @@ namespace Volo.Abp.AutoMapper
private class EntityProxy : DerivedEntity { } private class EntityProxy : DerivedEntity { }
[AutoMapFrom(typeof(Entity))] [AbpAutoMapFrom(typeof(Entity))]
private class EntityDto private class EntityDto
{ {
public string Value { get; set; } public string Value { get; set; }
} }
[AutoMapFrom(typeof(DerivedEntity))] [AbpAutoMapFrom(typeof(DerivedEntity))]
private class DerivedEntityDto : EntityDto { } private class DerivedEntityDto : EntityDto { }
} }
} }

@ -128,7 +128,7 @@ namespace Volo.Abp.AutoMapper
obj2.NullableValue.ShouldBe(42); obj2.NullableValue.ShouldBe(42);
} }
[AutoMap(typeof(MyClass2), typeof(MyClass3))] [AbpAutoMap(typeof(MyClass2), typeof(MyClass3))]
private class MyClass1 private class MyClass1
{ {
public string TestProp { get; set; } public string TestProp { get; set; }
@ -136,7 +136,7 @@ namespace Volo.Abp.AutoMapper
public long? NullableValue { get; set; } public long? NullableValue { get; set; }
} }
[AutoMapTo(typeof(MyClass3))] [AbpAutoMapTo(typeof(MyClass3))]
private class MyClass2 private class MyClass2
{ {
public string TestProp { get; set; } public string TestProp { get; set; }

@ -2,7 +2,7 @@
namespace Volo.Abp.AutoMapper.SampleClasses namespace Volo.Abp.AutoMapper.SampleClasses
{ {
[AutoMap(typeof(MyEntity))] [AbpAutoMap(typeof(MyEntity))]
public class MyEntityDto public class MyEntityDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }

@ -6,7 +6,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.TestApp.Domain namespace Volo.Abp.TestApp.Domain
{ {
[AutoMapTo(typeof(PersonEto))] [AbpAutoMapTo(typeof(PersonEto))]
public class Person : FullAuditedAggregateRoot<Guid>, IMultiTenant public class Person : FullAuditedAggregateRoot<Guid>, IMultiTenant
{ {
public virtual Guid? TenantId { get; set; } public virtual Guid? TenantId { get; set; }

Loading…
Cancel
Save