C# 截取方法调用时获取ContextBoundObject的类型
我正在拦截对ContextBoundObject的方法调用。有没有一种方法可以在消息接收器中获取我正在调用的对象的类型 说我有课C# 截取方法调用时获取ContextBoundObject的类型,c#,.net,C#,.net,我正在拦截对ContextBoundObject的方法调用。有没有一种方法可以在消息接收器中获取我正在调用的对象的类型 说我有课 [Intercept] [Synchronization] public class Test : ContextBoundObject { [Timeout(10010)] public void Method() { // Do something } } 在调用方法之前的消息接收器中是否有方法获取测试类
[Intercept]
[Synchronization]
public class Test : ContextBoundObject
{
[Timeout(10010)]
public void Method()
{
// Do something
}
}
在调用方法之前的消息接收器中
是否有方法获取测试
类型,以便我可以查询自定义属性超时
?乙二醇
public IMessage SyncProcessMessage(IMessage msg)
{
Type type = GetType(); // << Need to get hold of Test type here
object[] custom = type.GetMethod("Method").GetCustomAttributes(false);;
TimeoutAttribute ta = custom[0] as TimeoutAttribute;
int time = ta.Ticks;
IMessage returnedMessage = _nextSink.SyncProcessMessage(msg);
return returnedMessage;
}
public-IMessage-SyncProcessMessage(IMessage-msg)
{
Type Type=GetType();//经过一番努力,我找到了它
类型名称被传递到IMessage中属性字典中的SyncProcessMessage中
所以上面的代码变成了
public IMessage SyncProcessMessage(IMessage msg)
{
Type type = Type.GetType(msg.Properties["__TypeName"].ToString());
object[] custom = type.GetMethod("Method").GetCustomAttributes(false);
TimeoutAttribute ta = custom[0] as TimeoutAttribute;
int time = ta.Ticks;
IMessage returnedMessage = _nextSink.SyncProcessMessage(msg);
return returnedMessage;
}