コード例 #1
0
        public void Handle(Instruction instruction, CilHandlerContext context)
        {
            var method = context.Resolver.Method((MethodReference)instruction.Operand, context.GenericScope);

            var parameters = method.GetParameters();
            var arguments  = new object[parameters.Length];

            for (var i = parameters.Length - 1; i >= 0; i--)
            {
                arguments[i] = TypeSupport.Convert(context.Stack.Pop(), parameters[i].ParameterType);
            }

            if (instruction.OpCode == OpCodes.Newobj)
            {
                var instance = context.Invoker.Invoke(method, null, arguments, context.Method);
                context.Stack.Push(instance);
                return;
            }

            var target = (object)null;

            if (!method.IsStatic)
            {
                target = TypeSupport.Convert(context.Stack.Pop(), method.DeclaringType);
            }

            var result = context.Invoker.Invoke(method, target, arguments, context.Method);

            if (!method.IsConstructor && ((MethodInfo)method).ReturnType != typeof(void))
            {
                context.Stack.Push(result);
            }
        }
コード例 #2
0
        private bool IsConditionTrue(Instruction instruction, CilHandlerContext context)
        {
            switch (instruction.OpCode.Code)
            {
            case Code.Br:
            case Code.Br_S:
                return(true);

            case Code.Brtrue:
            case Code.Brtrue_S:
                return(TypeSupport.Convert <bool>(context.Stack.Pop()));

            case Code.Brfalse:
            case Code.Brfalse_S:
                return(!TypeSupport.Convert <bool>(context.Stack.Pop()));

            case Code.Beq_S: return(IsBinaryConditionTrue(Primitives.Equal, context));

            case Code.Bne_Un_S: return(IsBinaryConditionTrue(Primitives.NotEqual, context));

            case Code.Blt_S: return(IsBinaryConditionTrue(Primitives.IsLessThan, context));

            case Code.Ble_S: return(IsBinaryConditionTrue(Primitives.IsLessThanOrEqual, context));

            default:
                throw new NotImplementedException();
            }
        }
コード例 #3
0
        public void Handle(Instruction instruction, CilHandlerContext context)
        {
            var index = TypeSupport.Convert <IntPtr>(context.Stack.Pop());
            var array = (Array)ObjectWrapper.UnwrapIfRequired(context.Stack.Pop());

            var value = array.GetValue(index.ToInt64());

            context.Stack.Push(value);
        }
コード例 #4
0
ファイル: StelemHandler.cs プロジェクト: ashmind/Cilin
        public void Handle(Instruction instruction, CilHandlerContext context)
        {
            var value = context.Stack.Pop();
            var index = TypeSupport.Convert <IntPtr>(context.Stack.Pop());
            var array = (Array)ObjectWrapper.UnwrapIfRequired(context.Stack.Pop());

            array.SetValue(
                TypeSupport.Convert(value, array.GetType().GetElementType()),
                index.ToInt64()
                );
        }
コード例 #5
0
ファイル: LdfldHandler.cs プロジェクト: ashmind/Cilin
        public void Handle(Instruction instruction, CilHandlerContext context)
        {
            var field = context.Resolver.Field((FieldReference)instruction.Operand, context.GenericScope);

            var target = (object)null;

            if (instruction.OpCode == OpCodes.Ldfld)
            {
                target = TypeSupport.Convert(context.Stack.Pop(), field.DeclaringType);
            }

            var value = field.GetValue(target);

            context.Stack.Push(value);
        }