我正在尝试创建一个只处理非系统调用的拦截方法。根据医生们,系统和非系统呼叫都被截获:
对于对一个谷物的所有方法调用,都会调用传出的谷物调用过滤器,这包括对OR良所做的系统方法的调用。
然而,我无法用任何公共方法或财产来区分。我是不是遗漏了什么?
发布于 2018-08-13 21:46:54
我可以想出两种解释一个系统调用可能是什么:
ISystemTarget的任何调用在这两种情况下,确定调用是否符合该条件的最简单方法是使用传递给调用筛选器的上下文的InterfaceMethod属性来检查该MethodInfo的DeclaringType。
例如:
siloBuilder.AddOutgoingGrainCallFilter(async context =>
{
var declaringType = context.InterfaceMethod?.DeclaringType;
// Check if the type being called belongs to one of the Orleans assemblies
// systemAssemblies here is a HashSet<Assembly> containing the Orleans assemblies
var isSystemAssembly = declaringType != null
&& systemAssemblies.Contains(declaringType.Assembly);
// Check if the type is an ISystemTarget
var systemTarget = declaringType != null
&& typeof(ISystemTarget).IsAssignableFrom(declaringType);
if (isSystemAssembly || systemTarget)
{
// This is a system call, so just continue invocation without any further action
await context.Invoke();
}
else
{
// This is an application call
// ... Inspect/modify the arguments here ...
await context.Invoke();
// ... inspect/modify return value here ...
}
})https://stackoverflow.com/questions/51829240
复制相似问题