Exemple #1
0
        // Box value type
        public Value Box()
        {
            byte[] rawValue = this.CorGenericValue.GetRawValue();
            // The type must not be a primive type (always true in current design)
            ICorDebugReferenceValue corRefValue = Eval.NewObjectNoConstructor(this.Type).CorReferenceValue;

            // Make the reference to box permanent
            corRefValue = ((ICorDebugHeapValue2)corRefValue.Dereference()).CreateHandle(CorDebugHandleType.HANDLE_STRONG);
            // Create new value
            Value newValue = new Value(appDomain, corRefValue);

            // Copy the data inside the box
            newValue.CorGenericValue.SetRawValue(rawValue);
            return(newValue);
        }
Exemple #2
0
        /// <summary> Invoke the ToString() method </summary>
        public string InvokeToString(int maxLength = int.MaxValue)
        {
            if (this.Type.IsPrimitive)
            {
                return(AsString(maxLength));
            }
            if (this.Type.FullName == typeof(string).FullName)
            {
                return(AsString(maxLength));
            }
            if (this.Type.IsPointer)
            {
                return("0x" + this.PointerAddress.ToString("X"));
            }
            // if (!IsObject) // Can invoke on primitives
            DebugMethodInfo methodInfo = (DebugMethodInfo)this.AppDomain.ObjectType.GetMethod("ToString", new DebugType[] { });

            return(Eval.InvokeMethod(methodInfo, this, new Value[] { }).AsString(maxLength));
        }
Exemple #3
0
        /// <exception cref="GetValueException"><c>GetValueException</c>.</exception>
        private static void MethodInvokeStarter(Eval eval, DebugMethodInfo method, Value thisValue, Value[] args)
        {
            List <ICorDebugValue> corArgs = new List <ICorDebugValue>();

            args = args ?? new Value[0];
            if (args.Length != method.ParameterCount)
            {
                throw new GetValueException("Invalid parameter count");
            }
            if (!method.IsStatic)
            {
                if (thisValue == null)
                {
                    throw new GetValueException("'this' is null");
                }
                if (thisValue.IsNull)
                {
                    throw new GetValueException("Null reference");
                }
                // if (!(thisValue.IsObject)) // eg Can evaluate on array
                if (!method.DeclaringType.IsInstanceOfType(thisValue))
                {
                    throw new GetValueException(
                              "Can not evaluate because the object is not of proper type.  " +
                              "Expected: " + method.DeclaringType.FullName + "  Seen: " + thisValue.Type.FullName
                              );
                }
                corArgs.Add(thisValue.CorValue);
            }
            for (int i = 0; i < args.Length; i++)
            {
                Value     arg       = args[i];
                DebugType paramType = (DebugType)method.GetParameters()[i].ParameterType;
                if (!arg.Type.CanImplicitelyConvertTo(paramType))
                {
                    throw new GetValueException("Inncorrect parameter type");
                }
                // Implicitely convert to correct primitve type
                if (paramType.IsPrimitive && args[i].Type != paramType)
                {
                    object oldPrimVal = arg.PrimitiveValue;
                    object newPrimVal = Convert.ChangeType(oldPrimVal, paramType.PrimitiveType);
                    arg = CreateValue(method.AppDomain, newPrimVal);
                }
                // It is importatnt to pass the parameted in the correct form (boxed/unboxed)
                if (paramType.IsValueType)
                {
                    corArgs.Add(arg.CorGenericValue);
                }
                else
                {
                    if (args[i].Type.IsValueType)
                    {
                        corArgs.Add(arg.Box().CorValue);
                    }
                    else
                    {
                        corArgs.Add(arg.CorValue);
                    }
                }
            }

            ICorDebugType[] genericArgs = ((DebugType)method.DeclaringType).GenericArgumentsAsCorDebugType;
            eval.CorEval2.CallParameterizedFunction(
                method.CorFunction,
                (uint)genericArgs.Length, genericArgs,
                (uint)corArgs.Count, corArgs.ToArray()
                );
        }