Files
BeWoPlaner/Service/ServiceUtils/ServiceHelper.cs
2025-02-21 16:09:11 +01:00

44 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IdentityModel.Claims;
using System.Linq;
using System.Reflection;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using BS.Shared.Attributes;
using BS.Shared.Extensions;
using NHibernate.Hql.Ast.ANTLR.Tree;
namespace BeWo.Service.ServiceUtils
{
public static class ServiceHelper
{
public static T GetCustomAttribute<T>(this Message pMessage) where T : Attribute
{
// Finde Action
var lTemp = pMessage.Headers.Action?.Split("/");
if (lTemp is null)
lTemp = pMessage.Headers.To.Segments.ToList();
if (lTemp is null)
throw new ArgumentException("Kann Action nicht finden");
// Extrahiere MethodeName + ServiceInterface
string lMethodName = lTemp[lTemp.Count - 1].Trim('/');
string lServiceInterface = lTemp[lTemp.Count - 2].Trim('/');
// Hole entsprechende Methode
var name = $"BeWo.Service.ServiceContracts.I{lServiceInterface}";
var t = Type.GetType(name);
var methodInfo = t.GetMethod(lMethodName);
// Hole Custome Attribute
var attribute = methodInfo.GetCustomAttribute<T>();
return attribute;
}
}
}