private static bool InterceptObjectPassThrough(object target, string funcName, object[] args, out object result)
{
if (target is Type)
{
if ((Type)target == typeof(System.Runtime.CompilerServices.RuntimeHelpers))
{
if (funcName == "Equals")
{
if (args == null || args.Length != 2)
throw ErrorFactory.CreateClrError("Equals() expect 2 arguments");
// Forwards to RuntimeHelpers.Equals() doesn't work under Mac OSX's Mono
result = args[0] == args[1];
return true;
}
if (funcName == "GetHashCode")
{
if (args == null || args.Length != 1)
throw ErrorFactory.CreateClrError("GetHashCode() expect 1 argument");
result = System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(args[0]);
return true;
}
}
else if ((Type)target == typeof(System.Threading.Monitor))
{
if (funcName == "Enter" || funcName == "Exit" ||
funcName == "Wait" || funcName == "Pulse" || funcName == "PulseAll")
{
if (args == null || args.Length != 1)
throw ErrorFactory.CreateClrError(string.Format("Monitor.{0}() expect 1 argument", funcName));
result = typeof(System.Threading.Monitor).CallMethod(funcName, args[0]);
return true;
}
if (funcName == "TryEnter")
{
if (args == null || (args.Length < 1 || args.Length > 2))
throw ErrorFactory.CreateClrError(string.Format("Monitor.{0}() expect 1 or 2 arguments", funcName));
if (args.Length == 1)
result = System.Threading.Monitor.TryEnter(args[0]);
else
result = System.Threading.Monitor.TryEnter(args[0],
(int)(decimal)InterpretationContext.Instance.Interpreter
.MarshallToClr(args[1]));
return true;
}
}
}
result = null;
return false;
}