Skip to content

Commit fc34548

Browse files
committed
Support custom event name
1 parent b772c5a commit fc34548

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Wodsoft.ComBoost
6+
{
7+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
8+
public class DomainDistributedEventNameAttribute : Attribute
9+
{
10+
public DomainDistributedEventNameAttribute(string name)
11+
{
12+
Name = name ?? throw new ArgumentNullException(nameof(name));
13+
}
14+
15+
public string Name { get; }
16+
}
17+
}

src/Wodsoft.ComBoost.Distributed/DomainDistributedEventProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Text;
67
using System.Threading.Tasks;
78

@@ -31,6 +32,9 @@ protected virtual string GetTypeName<T>()
3132
private static ConcurrentDictionary<Type, string> _TypeNames = new ConcurrentDictionary<Type, string>();
3233
public static string GetTypeName(Type type)
3334
{
35+
var nameAttribute = type.GetCustomAttribute<DomainDistributedEventNameAttribute>();
36+
if (nameAttribute != null)
37+
return nameAttribute.Name;
3438
var name = type.Namespace + "." + type.Name;
3539
if (type.IsGenericType)
3640
{

0 commit comments

Comments
 (0)