44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Svrnty.CQRS.Abstractions.Attributes;
|
|
|
|
namespace Svrnty.CQRS.Abstractions.Discovery;
|
|
|
|
public class QueryMeta : IQueryMeta
|
|
{
|
|
private readonly string _name;
|
|
|
|
public QueryMeta(Type queryType, Type serviceType, Type queryResultType)
|
|
{
|
|
QueryType = queryType;
|
|
ServiceType = serviceType;
|
|
QueryResultType = queryResultType;
|
|
|
|
// Cache reflection and computed value once in constructor
|
|
var nameAttribute = queryType.GetCustomAttribute<QueryNameAttribute>();
|
|
_name = nameAttribute?.Name ?? queryType.Name.Replace("Query", string.Empty);
|
|
}
|
|
|
|
public virtual string Name => _name;
|
|
|
|
public virtual Type QueryType { get; }
|
|
public virtual Type ServiceType { get; }
|
|
public virtual Type QueryResultType { get; }
|
|
public virtual string Category => "BasicQuery";
|
|
|
|
public string LowerCamelCaseName
|
|
{
|
|
get
|
|
{
|
|
// Use virtual Name property so derived classes can override
|
|
var name = Name;
|
|
if (string.IsNullOrEmpty(name))
|
|
return name;
|
|
|
|
var firstLetter = char.ToLowerInvariant(name[0]);
|
|
return $"{firstLetter}{name[1..]}";
|
|
}
|
|
}
|
|
}
|
|
|