74
else if ((obj is StructMirror) && cx.Options.AllowTargetInvoke) {
75
StructMirror ob = (StructMirror) obj;
76
MethodMirror method = OverloadResolve (cx, "ToString", ob.Type, new TypeMirror[0], true, false, false);
77
if (method != null && method.DeclaringType.FullName != "System.ValueType") {
78
StringMirror res = (StringMirror) cx.RuntimeInvoke (method, obj, new Value[0]);
73
82
return GetDisplayTypeName (GetValueTypeName (ctx, obj));
77
public override object Cast (EvaluationContext ctx, object obj, object targetType)
85
public override object TryConvert (EvaluationContext ctx, object obj, object targetType)
81
87
object res = TryCast (ctx, obj, targetType);
85
throw new EvaluatorException ("Can't cast an object of type '{0}' to type '{1}'", GetValueTypeName (ctx, obj), GetTypeName (ctx, targetType));
92
object otype = GetValueType (ctx, obj);
94
if (targetType is TypeMirror)
95
targetType = Type.GetType (((TypeMirror)targetType).FullName, false);
96
Type tt = targetType as Type;
99
if (obj is PrimitiveValue)
100
obj = ((PrimitiveValue)obj).Value;
101
res = System.Convert.ChangeType (obj, tt);
102
return CreateValue (ctx, res);
88
110
public override object TryCast (EvaluationContext ctx, object obj, object targetType)
93
115
if (otype is TypeMirror) {
94
116
if ((targetType is TypeMirror) && ((TypeMirror)targetType).IsAssignableFrom ((TypeMirror)otype))
118
// Try casting the primitive type of the enum
119
EnumMirror em = obj as EnumMirror;
121
return TryCast (ctx, CreateValue (ctx, em.Value), targetType);
96
122
} else if (otype is Type) {
97
if (targetType is TypeMirror)
123
if (targetType is TypeMirror) {
124
TypeMirror tm = (TypeMirror) targetType;
126
// TODO: convert to enum
98
128
targetType = Type.GetType (((TypeMirror)targetType).FullName, false);
99
if ((targetType is Type) && ((Type)targetType).IsAssignableFrom ((Type)otype))
130
Type tt = targetType as Type;
132
if (tt.IsAssignableFrom ((Type)otype))
134
if (obj is PrimitiveValue)
135
obj = ((PrimitiveValue)obj).Value;
136
if (tt != typeof(string) && !(obj is string)) {
138
object res = System.Convert.ChangeType (obj, tt);
139
return CreateValue (ctx, res);
363
406
SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
365
TypeMirror[] types = new TypeMirror [argTypes.Length];
366
for (int n=0; n<argTypes.Length; n++)
367
types [n] = (TypeMirror) argTypes [n];
409
if (argTypes == null)
410
types = new TypeMirror [0];
412
types = new TypeMirror [argTypes.Length];
413
for (int n=0; n<argTypes.Length; n++) {
414
if (argTypes [n] is TypeMirror)
415
types [n] = (TypeMirror) argTypes [n];
417
types [n] = (TypeMirror) GetType (ctx, ((Type)argTypes[n]).FullName);
369
421
MethodMirror met = OverloadResolve (ctx, methodName, (TypeMirror) targetType, types, (flags & BindingFlags.Instance) != 0, (flags & BindingFlags.Static) != 0, false);
370
422
return met != null;
424
476
DebuggerTypeProxyAttribute at = BuildAttribute<DebuggerTypeProxyAttribute> (attr);
425
477
td.ProxyType = at.ProxyTypeName;
426
478
if (!string.IsNullOrEmpty (td.ProxyType))
427
ForceLoadType (ctx, t, td.ProxyType);
479
ForceLoadType (ctx, td.ProxyType);
430
482
foreach (FieldInfoMirror fi in t.GetFields ()) {
461
513
return default(T);
464
void ForceLoadType (SoftEvaluationContext ctx, TypeMirror helperType, string typeName)
516
public override object ForceLoadType (EvaluationContext gctx, string typeName)
518
// Shortcut to avoid a target invoke in case the type is already loaded
519
object t = GetType (gctx, typeName);
523
SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
466
524
if (!ctx.Options.AllowTargetInvoke)
468
TypeMirror tm = helperType.GetTypeObject ().Type;
469
TypeMirror[] ats = new TypeMirror[] { ctx.Session.GetType ("System.String") };
526
TypeMirror tm = (TypeMirror) ctx.Thread.Type.GetTypeObject ().Type;
527
TypeMirror stype = ctx.Session.GetType ("System.String");
529
// If the string type is not loaded, we need to get it in another way
530
StringMirror ss = ctx.Thread.Domain.CreateString ("");
533
TypeMirror[] ats = new TypeMirror[] { stype };
470
534
MethodMirror met = OverloadResolve (ctx, "GetType", tm, ats, false, true, true);
471
tm.InvokeMethod (ctx.Thread, met, new Value[] {(Value) CreateValue (ctx, typeName)});
472
ctx.Session.StackVersion++;
536
tm.InvokeMethod (ctx.Thread, met, new Value[] {(Value) CreateValue (ctx, typeName)});
540
ctx.Session.StackVersion++;
542
return GetType (ctx, typeName);
475
546
T BuildAttribute<T> (CustomAttributeDataMirror attr)
649
720
return ((StringMirror)obj).Value;
650
721
else if (obj is EnumMirror) {
651
722
EnumMirror eob = (EnumMirror) obj;
652
return new LiteralExp (eob.StringValue);
723
return new EvaluationResult (eob.Type.FullName + "." + eob.StringValue, eob.StringValue);
654
725
else if (obj is PrimitiveValue)
655
726
return ((PrimitiveValue)obj).Value;
708
779
} catch (Exception ex) {
709
780
ctx.Session.StackVersion++;
710
MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread", ex);
781
MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread on " + GetInfo (), ex);
735
806
} catch (InvocationException ex) {
737
808
} catch (Exception ex) {
738
MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread", ex);
809
MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread on " + GetInfo (), ex);
741
812
ctx.Session.StackVersion++;
819
TypeMirror type = null;
820
if (obj is ObjectMirror)
821
type = ((ObjectMirror)obj).Type;
822
else if (obj is TypeMirror)
823
type = (TypeMirror)obj;
824
else if (obj is StructMirror)
825
type = ((StructMirror)obj).Type;
826
return string.Format ("method {0} on object {1}",
827
function == null? "[null]" : function.FullName,
828
type == null? "[null]" : type.FullName);
829
} catch (Exception ex) {
830
MonoDevelop.Core.LoggingService.LogError ("Error getting info for SDB MethodCall", ex);
745
835
public override bool WaitForCompleted (int timeout)