public override object TargetObjectToObject(EvaluationContext gctx, object obj) { if (obj is StringMirror) { return(((StringMirror)obj).Value); } else if (obj is PrimitiveValue) { return(((PrimitiveValue)obj).Value); } else if ((obj is StructMirror) && ((StructMirror)obj).Type.IsPrimitive) { // Boxed primitive StructMirror sm = (StructMirror)obj; if (sm.Type.FullName == "System.IntPtr") { return(new IntPtr((long)((PrimitiveValue)sm.Fields[0]).Value)); } if (sm.Fields.Length > 0 && (sm.Fields[0] is PrimitiveValue)) { return(((PrimitiveValue)sm.Fields[0]).Value); } } return(base.TargetObjectToObject(gctx, obj)); }
public override string CallToString(EvaluationContext ctx, object obj) { SoftEvaluationContext cx = (SoftEvaluationContext)ctx; if (obj is StringMirror) { return(((StringMirror)obj).Value); } else if (obj is EnumMirror) { EnumMirror eob = (EnumMirror)obj; return(eob.StringValue); } else if (obj is PrimitiveValue) { return(((PrimitiveValue)obj).Value.ToString()); } else if ((obj is StructMirror) && ((StructMirror)obj).Type.IsPrimitive) { // Boxed primitive StructMirror sm = (StructMirror)obj; if (sm.Fields.Length > 0 && (sm.Fields[0] is PrimitiveValue)) { return(((PrimitiveValue)sm.Fields[0]).Value.ToString()); } } else if (obj == null) { return(string.Empty); } else if ((obj is ObjectMirror) && cx.Options.AllowTargetInvoke) { ObjectMirror ob = (ObjectMirror)obj; MethodMirror method = OverloadResolve(cx, "ToString", ob.Type, new TypeMirror[0], true, false, false); if (method != null && method.DeclaringType.FullName != "System.Object") { StringMirror res = cx.RuntimeInvoke(method, obj, new Value[0]) as StringMirror; return(res != null ? res.Value : string.Empty); } } else if ((obj is StructMirror) && cx.Options.AllowTargetInvoke) { StructMirror ob = (StructMirror)obj; MethodMirror method = OverloadResolve(cx, "ToString", ob.Type, new TypeMirror[0], true, false, false); if (method != null && method.DeclaringType.FullName != "System.ValueType") { StringMirror res = cx.RuntimeInvoke(method, obj, new Value[0]) as StringMirror; return(res != null ? res.Value : string.Empty); } } return(GetDisplayTypeName(GetValueTypeName(ctx, obj))); }
public ValueTypeFieldValueLocation(DmdType type, ValueLocation containingLocation, StructMirror structMirror, FieldInfoMirror field) { Type = type ?? throw new ArgumentNullException(nameof(type)); this.containingLocation = containingLocation ?? throw new ArgumentNullException(nameof(containingLocation)); this.field = field ?? throw new ArgumentNullException(nameof(field)); structType = structMirror.Type; Debug.Assert(!field.IsStatic); Debug.Assert(field.DeclaringType == structType); Debug.Assert(containingLocation.Load() is StructMirror); valueIndex = GetValueIndex(field); if ((uint)valueIndex >= (uint)structMirror.Fields.Length) { throw new InvalidOperationException(); } }
public MonoProperty(StackFrame frame, Mirror currentMirror, StructMirror parentStructMirror) : this(frame, currentMirror) { _parentStructMirror = parentStructMirror; }