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 void Replace(Method method)
        {
            this.instruction.Operand = 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)
            {
                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;
                (method.NewCode() as InstructionsSet).CastOrBoxValues(processor, parameters[0].typeReference, paramResult, parameters[0].typeDefinition);
                processor.InsertBefore(this.instruction, paramResult.Instructions);
            }
        }