52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Reflection;
|
|||
|
using OpenHarbor.CQRS.Abstractions.Attributes;
|
|||
|
|
|||
|
namespace OpenHarbor.CQRS.Abstractions.Discovery;
|
|||
|
|
|||
|
public sealed class CommandMeta : ICommandMeta
|
|||
|
{
|
|||
|
public CommandMeta(Type commandType, Type serviceType, Type commandResultType)
|
|||
|
{
|
|||
|
CommandType = commandType;
|
|||
|
ServiceType = serviceType;
|
|||
|
CommandResultType = commandResultType;
|
|||
|
}
|
|||
|
|
|||
|
public CommandMeta(Type commandType, Type serviceType)
|
|||
|
{
|
|||
|
CommandType = commandType;
|
|||
|
ServiceType = serviceType;
|
|||
|
}
|
|||
|
|
|||
|
private CommandNameAttribute NameAttribute => CommandType.GetCustomAttribute<CommandNameAttribute>();
|
|||
|
|
|||
|
public string Name
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var name = NameAttribute?.Name ?? CommandType.Name.Replace("Command", string.Empty);
|
|||
|
return name;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Type CommandType { get; }
|
|||
|
public Type ServiceType { get; }
|
|||
|
public Type CommandResultType { get; }
|
|||
|
|
|||
|
public string LowerCamelCaseName
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(Name))
|
|||
|
return Name;
|
|||
|
|
|||
|
var name = Name;
|
|||
|
var firstLetter = Char.ToLowerInvariant(name[0]);
|
|||
|
var ret = $"{firstLetter}{name.Substring(1)}";
|
|||
|
return ret;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|