public static EvaluationResult MonoObjectToString(Thread thread, TargetStructObject obj,
EvaluationFlags flags, int timeout,
out string result)
{
result = null;
if (!obj.Type.Language.IsManaged)
return EvaluationResult.MethodNotFound;
again:
TargetStructType ctype = obj.Type;
if ((ctype.Name == "System.Object") || (ctype.Name == "System.ValueType"))
return EvaluationResult.MethodNotFound;
TargetClass klass = ctype.GetClass (thread);
if (klass == null)
return EvaluationResult.NotInitialized;
TargetMethodInfo[] methods = klass.GetMethods (thread);
if (methods == null)
return EvaluationResult.MethodNotFound;
foreach (TargetMethodInfo minfo in methods) {
if (minfo.Name != "ToString")
continue;
TargetFunctionType ftype = minfo.Type;
if (ftype.ParameterTypes.Length != 0)
continue;
if (ftype.ReturnType != ftype.Language.StringType)
continue;
RuntimeInvokeResult rti;
try {
RuntimeInvokeFlags rti_flags = RuntimeInvokeFlags.VirtualMethod;
if ((flags & EvaluationFlags.NestedBreakStates) != 0)
rti_flags |= RuntimeInvokeFlags.NestedBreakStates;
rti = thread.RuntimeInvoke (
ftype, obj, new TargetObject [0], rti_flags);
if (!rti.CompletedEvent.WaitOne (timeout, false)) {
rti.Abort ();
return EvaluationResult.Timeout;
}
if ((rti.TargetException != null) &&
(rti.TargetException.Type == TargetError.ClassNotInitialized)) {
result = null;
return EvaluationResult.NotInitialized;
}
if (rti.Result is Exception) {
result = ((Exception) rti.Result).Message;
return EvaluationResult.UnknownError;
}
if (rti.ExceptionMessage != null) {
result = rti.ExceptionMessage;
return EvaluationResult.Exception;
} else if (rti.ReturnObject == null) {
rti.Abort ();
return EvaluationResult.UnknownError;
}
} catch (TargetException ex) {
result = ex.ToString ();
return EvaluationResult.UnknownError;
}
TargetObject retval = (TargetObject) rti.ReturnObject;
result = (string) ((TargetFundamentalObject) retval).GetObject (thread);
return EvaluationResult.Ok;
}
if (obj.Type.HasParent) {
obj = obj.GetParentObject (thread) as TargetClassObject;
if (obj != null)
goto again;
}
return EvaluationResult.MethodNotFound;
}