Ejemplo n.º 1
0
        public void Replace(Method method, bool autoCast = true)
        {
            this.instruction.Operand = Builder.Current.Import(method.methodReference);

            // If we know this method has only one param (Because easy to do), we should try to check
            // the type and and try a cast if needed
            var parameters = method.Parameters;

            if (parameters.Length == 1 && autoCast)
            {
                var previousType = this.GetPreviousInstructionObjectType();

                if (parameters[0].typeReference.FullName.GetHashCode() == previousType.typeReference.FullName.GetHashCode() && parameters[0].typeReference.FullName == previousType.typeReference.FullName)
                {
                    return;
                }

                var paramResult = new ParamResult();
                var processor   = this.HostMethod.GetILProcessor();
                paramResult.Type = previousType.typeReference;
                var coder = method.NewCoder();
                InstructionBlock.CastOrBoxValues(coder.instructions, parameters[0]);
                processor.InsertBefore(this.instruction, paramResult.Instructions);
            }
        }
Ejemplo n.º 2
0
        public BooleanExpressionCoder As(BuilderType type)
        {
            if (this.instructions.associatedMethod.IsStatic)
            {
                throw new NotSupportedException("This is not supported in static methods.");
            }

            this.instructions.Emit(OpCodes.Ldarg_0);
            InstructionBlock.CastOrBoxValues(this, type);
            return(new BooleanExpressionCoder(this, this.jumpTargets));
        }
Ejemplo n.º 3
0
        public BooleanExpressionCoder Or <T>(T[] collection, Func <BooleanExpressionCoder, T, int, object> code)
        {
            if (collection == null || collection.Length == 0)
            {
                return(this);
            }

            code(this, collection[0], 0);
            InstructionBlock.CastOrBoxValues(this.instructions, BuilderTypes.Boolean);

            for (int i = 1; i < collection.Length; i++)
            {
                code(this, collection[i], i);
                InstructionBlock.CastOrBoxValues(this.instructions, BuilderTypes.Boolean);
                this.instructions.Emit(OpCodes.Or);
            }

            return(this);
        }
Ejemplo n.º 4
0
 public BooleanExpressionFieldCoder As(BuilderType type)
 {
     InstructionBlock.CastOrBoxValues(this, type);
     return(new BooleanExpressionFieldCoder(this, type));
 }