private Maybe<Expression> SelfMethod(Type type, Expression instance, int errorPos, string id, Lazy<Expression[]> args)
{
MethodBase mb;
switch (GetAppropriateMethodCount(type, id, instance == null, args.Value, out mb))
{
case 0:
return Maybe.Nothing;
case 1:
var method = (MethodInfo) mb;
if (!IsPredefinedType(method.DeclaringType))
{
if (!method.DeclaringType.IsEnum)
throw ParseError(errorPos, Res.MethodsAreInaccessible(GetTypeName(method.DeclaringType)));
}
if (method.ReturnType == typeof(void))
throw ParseError(errorPos, Res.MethodIsVoid(id, GetTypeName(method.DeclaringType)));
return Expression.Call(instance, method, args.Value);
default:
return Maybe.Nothing;
}
}