I cannot access the custom attribute I wrote for the method within the invoke method.
Attribute class :
public class HttpTypeAttribute : Attribute
{
public string Type { get; set; }
public HttpTypeAttribute(string type)
{
Type = type;
}
}
Web function:
[HttpType("POST")]
public ResponseDTO Run(RequestDTO requestDTO)
{
var result = ProxyManager<TestInterface>.CreateProxy(url).Run(requestDTO);
return result;
}
Invoke method:
public class ProxyManager<T> : DispatchProxy where T : class
{
public string APIAddress { get; set; }
public static T CreateProxy(string APIAddress)
{
var proxy = Create<T, ProxyManager<T>>() as ProxyManager<T>;
proxy.APIAddress = APIAddress;
return proxy as T;
}
protected override object Invoke(MethodInfo targetMethod, object[] args)
{
//attr is null . I can't access custom attribute
HttpTypeAttribute attr = (HttpTypeAttribute)targetMethod.GetCustomAttributes(typeof(HttpTypeAttribute), true).FirstOrDefault(); // attr is null
string url = APIAddress;
url += targetMethod.DeclaringType.Name + "/" + targetMethod.Name;
var returnStr = HttpRequest.HttpPost(url, args);
return JsonSerializer.Deserialize(returnStr, targetMethod.ReturnType);
}
}
Is there any way to do this? I would be glad if you help.