private void Unbox(ref CorValue value) { CorBoxValue boxVal = value.CastToBoxValue(); if (boxVal != null) { value = boxVal.GetObject(); } }
static CorValue Unbox(EvaluationContext ctx, CorBoxValue boxVal) { CorObjectValue bval = boxVal.GetObject(); Type ptype = Type.GetType(ctx.Adapter.GetTypeName(ctx, bval.ExactType)); if (ptype != null && ptype.IsPrimitive) { ptype = bval.ExactType.GetTypeInfo(((CorEvaluationContext)ctx).Session); foreach (FieldInfo field in ptype.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (field.Name == "m_value") { CorValue val = bval.GetFieldValue(bval.ExactType.Class, field.MetadataToken); val = GetRealObject(ctx, val); return(val); } } } return(GetRealObject(ctx, bval)); }
public static CorValue GetRealObject(EvaluationContext ctx, CorValue obj) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; if (obj == null) { return(null); } try { if (obj is CorStringValue) { return(obj); } if (obj is CorGenericValue) { return(obj); } if (obj is CorGenericValue) { return(obj); } if (obj is CorArrayValue) { return(obj); } CorArrayValue arrayVal = obj.CastToArrayValue(); if (arrayVal != null) { return(arrayVal); } CorReferenceValue refVal = obj.CastToReferenceValue(); if (refVal != null) { if (refVal.IsNull) { return(refVal); } else { cctx.Session.WaitUntilStopped(); return(GetRealObject(cctx, refVal.Dereference())); } } cctx.Session.WaitUntilStopped(); CorBoxValue boxVal = obj.CastToBoxValue(); if (boxVal != null) { return(Unbox(ctx, boxVal)); } if (obj.ExactType.Type == CorElementType.ELEMENT_TYPE_STRING) { return(obj.CastToStringValue()); } if (CorMetadataImport.CoreTypes.ContainsKey(obj.Type)) { CorGenericValue genVal = obj.CastToGenericValue(); if (genVal != null) { return(genVal); } } if (!(obj is CorObjectValue)) { return(obj.CastToObjectValue()); } } catch { // Ignore throw; } return(obj); }