mirror of https://github.com/abpframework/abp.git
5 changed files with 71 additions and 12 deletions
@ -0,0 +1,24 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class GenericEventNameAttribute : Attribute, IEventNameProvider |
|||
{ |
|||
public string GetName(Type eventType) |
|||
{ |
|||
if (!eventType.IsGenericType) |
|||
{ |
|||
throw new AbpException($"Given type is not generic: {eventType.AssemblyQualifiedName}"); |
|||
} |
|||
|
|||
var genericArguments = eventType.GetGenericArguments(); |
|||
if (genericArguments.Length > 1) |
|||
{ |
|||
throw new AbpException($"Given type has more than one generic argument: {eventType.AssemblyQualifiedName}"); |
|||
} |
|||
|
|||
return EventNameAttribute.GetNameOrDefault(genericArguments[0]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public interface IEventNameProvider |
|||
{ |
|||
string GetName(Type eventType); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.EventBus |
|||
{ |
|||
public class GenericEventNameAttribute_Tests |
|||
{ |
|||
[Fact] |
|||
public void Should_Properly_Get_EventName() |
|||
{ |
|||
new GenericEventNameAttribute() |
|||
.GetName(typeof(MyGenericType<MyInnerType>)) |
|||
.ShouldBe(typeof(MyInnerType).FullName); |
|||
} |
|||
|
|||
public class MyInnerType |
|||
{ |
|||
|
|||
} |
|||
|
|||
public class MyGenericType<T> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue