Ejemplo n.º 1
0
            public override bool Call(bool isCallvirt, DmdMethodBase method, ILValue[] arguments, out ILValue returnValue)
            {
                var ad   = method.AppDomain;
                var type = method.ReflectedType;

                if (type.FullName == "dnSpy.Debugger.DotNet.Interpreter.Tests.MyClass")
                {
                    switch (method.Name)
                    {
                    case "InstanceMethod1":
                        returnValue = new ConstantInt32ILValue(ad, 123);
                        return(true);

                    case "InstanceMethod2":
                        returnValue = arguments[0].Clone();
                        return(true);

                    case "InstanceMethod3":
                        returnValue = arguments[1].Clone();
                        return(true);

                    case "InstanceMethod4":
                        returnValue = arguments[2].Clone();
                        return(true);
                    }
                }

                returnValue = null;
                return(false);
            }
Ejemplo n.º 2
0
            public override bool Call(bool isCallvirt, DmdMethodBase method, ILValue[] arguments, out ILValue returnValue)
            {
                var ad   = method.AppDomain;
                var type = method.ReflectedType;

                if (type == ad.GetWellKnownType(DmdWellKnownType.System_RuntimeTypeHandle))
                {
                    if (method.Name == "get_Value")
                    {
                        returnValue = ad.Runtime.PointerSize == 4 ?
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 0) :
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 0);
                        return(true);
                    }
                }
                else if (type == ad.GetWellKnownType(DmdWellKnownType.System_RuntimeFieldHandle))
                {
                    if (method.Name == "get_Value")
                    {
                        returnValue = ad.Runtime.PointerSize == 4 ?
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 1) :
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 1);
                        return(true);
                    }
                }
                else if (type == ad.GetWellKnownType(DmdWellKnownType.System_RuntimeMethodHandle))
                {
                    if (method.Name == "get_Value")
                    {
                        returnValue = ad.Runtime.PointerSize == 4 ?
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 2) :
                                      ConstantNativeIntILValue.Create32(ad, DUMMY_PTR_BASE + 2);
                        return(true);
                    }
                }
                else if (type.FullName == "dnSpy.Debugger.DotNet.Interpreter.Tests.MyStruct")
                {
                    switch (method.Name)
                    {
                    case "InstanceMethod1":
                        returnValue = new ConstantInt32ILValue(ad, 123);
                        return(true);

                    case "InstanceMethod2":
                        returnValue = arguments[0].Clone();
                        return(true);

                    case "InstanceMethod3":
                        returnValue = arguments[1].Clone();
                        return(true);

                    case "InstanceMethod4":
                        returnValue = arguments[2].Clone();
                        return(true);
                    }
                }

                returnValue = null;
                return(false);
            }
Ejemplo n.º 3
0
        static void InitializeValue(ref ILValue value, DmdType valueType)
        {
            if (value != null)
            {
                return;
            }

            if (!valueType.IsValueType)
            {
                value = new NullObjectRefILValue();
                return;
            }

            switch (DmdType.GetTypeCode(valueType))
            {
            case TypeCode.Boolean:          value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Char:                     value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.SByte:            value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Byte:                     value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Int16:            value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.UInt16:           value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Int32:            value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.UInt32:           value = new ConstantInt32ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Int64:            value = new ConstantInt64ILValue(valueType.AppDomain, 0); return;

            case TypeCode.UInt64:           value = new ConstantInt64ILValue(valueType.AppDomain, 0); return;

            case TypeCode.Single:           value = new ConstantFloatILValue(valueType.AppDomain, 0); return;

            case TypeCode.Double:           value = new ConstantFloatILValue(valueType.AppDomain, 0); return;
            }
            if (valueType == valueType.AppDomain.System_IntPtr || valueType == valueType.AppDomain.System_UIntPtr)
            {
                value = valueType.AppDomain.Runtime.PointerSize == 4 ? ConstantNativeIntILValue.Create32(valueType.AppDomain, 0) : ConstantNativeIntILValue.Create64(valueType.AppDomain, 0);
                return;
            }

            throw new InvalidOperationException();
        }