InferenceResult IInferableInvokable.GetInferredType(Type delegateType, Type parameterType) {
if (!delegateType.IsSubclassOf(typeof(Delegate))) {
throw new InvalidOperationException();
}
MethodInfo invoke = delegateType.GetMethod("Invoke");
ParameterInfo[] pis = invoke.GetParameters();
if (pis.Length == Value.NormalArgumentCount) {
// our signatures are compatible
return new InferenceResult(
typeof(object),
Restrictions.Merge(
BindingRestrictions.GetTypeRestriction(
Expression,
typeof(PythonFunction)
).Merge(
BindingRestrictions.GetExpressionRestriction(
Expression.Equal(
Expression.Call(
typeof(PythonOps).GetMethod("FunctionGetCompatibility"),
Expression.Convert(Expression, typeof(PythonFunction))
),
Expression.Constant(Value.FunctionCompatibility)
)
)
)
)
);
}
return null;
}