mirror of https://github.com/abpframework/abp.git
committed by
GitHub
6 changed files with 94 additions and 40 deletions
@ -0,0 +1,42 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Volo.Abp.BackgroundWorkers; |
||||
|
|
||||
|
public class BackgroundWorkerNameAttribute : Attribute, IBackgroundWorkerNameProvider |
||||
|
{ |
||||
|
public string Name { get; } |
||||
|
|
||||
|
public BackgroundWorkerNameAttribute(string name) |
||||
|
{ |
||||
|
Name = Check.NotNullOrWhiteSpace(name, nameof(name)); |
||||
|
} |
||||
|
|
||||
|
public static string GetName<TWorkerType>() |
||||
|
{ |
||||
|
return GetName(typeof(TWorkerType)); |
||||
|
} |
||||
|
|
||||
|
public static string GetName(Type workerType) |
||||
|
{ |
||||
|
Check.NotNull(workerType, nameof(workerType)); |
||||
|
|
||||
|
return GetNameOrNull(workerType) ?? workerType.FullName!; |
||||
|
} |
||||
|
|
||||
|
public static string? GetNameOrNull<TWorkerType>() |
||||
|
{ |
||||
|
return GetNameOrNull(typeof(TWorkerType)); |
||||
|
} |
||||
|
|
||||
|
public static string? GetNameOrNull(Type workerType) |
||||
|
{ |
||||
|
Check.NotNull(workerType, nameof(workerType)); |
||||
|
|
||||
|
return workerType |
||||
|
.GetCustomAttributes(true) |
||||
|
.OfType<IBackgroundWorkerNameProvider>() |
||||
|
.FirstOrDefault() |
||||
|
?.Name; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace Volo.Abp.BackgroundWorkers; |
||||
|
|
||||
|
public interface IBackgroundWorkerNameProvider |
||||
|
{ |
||||
|
string Name { get; } |
||||
|
} |
||||
Loading…
Reference in new issue