private bool IsAssignmentToConcreteType(StackAnalysisResult stackAnalysis)
        {
            TypeReference assignmentTargetType;

            if (InstrumentationUtil.IsCallInstruction(stackAnalysis.Consumer))
            {
                assignmentTargetType = stackAnalysis.AssignedParameter().ParameterType;
            }
            else
            {
                FieldReference assignmentTarget = stackAnalysis.Consumer.Operand as FieldReference;
                if (assignmentTarget != null)
                {
                    assignmentTargetType = assignmentTarget.FieldType;
                }
                else
                {
                    VariableReference variableDefinition = stackAnalysis.Consumer.Operand as VariableReference;
                    if (variableDefinition != null)
                    {
                        assignmentTargetType = variableDefinition.VariableType;
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
            return(HasReplacement(assignmentTargetType.GetElementType().FullName));
        }
Example #2
0
        private static void PatchBaseConstructorInvocationOrder(MethodDefinition method)
        {
            Instruction ctorInvocation = (Instruction)Iterators.Next(InstrumentationUtil.Where(method.Body, IsBaseConstructorInvocation).GetEnumerator());
            Instruction loadThis       = GetLoadThisReferenceFor(method.Body, ctorInvocation);

            MoveInstructions(loadThis, ctorInvocation, method.Body.Instructions[0], method.Body.GetILProcessor());
        }
Example #3
0
 private static IEnumerable <Instruction> BaseConstructorInvocationOrFieldAccesses(MethodDefinition ctor)
 {
     return(InstrumentationUtil.Where(
                ctor.Body,
                delegate(Instruction instruction)
     {
         return IsFieldAccess(instruction) || IsBaseConstructorInvocation(instruction);
     }));
 }
        private IEnumerable <Instruction> CastsToSupportedCollections(MethodBody body)
        {
            return(InstrumentationUtil.Where(body, delegate(Instruction candidate)
            {
                if (candidate.OpCode != OpCodes.Castclass)
                {
                    return false;
                }
                GenericInstanceType target = candidate.Operand as GenericInstanceType;

                return target != null && HasReplacement(target.Resolve().FullName);
            }));
        }
        private static IEnumerable <Instruction> TAEnabledCollectionInstantiations(MethodBody methodBody)
        {
            return(InstrumentationUtil.Where(methodBody, delegate(Instruction candidate)
            {
                if (candidate.OpCode != OpCodes.Newobj)
                {
                    return false;
                }
                MethodReference ctor = (MethodReference)candidate.Operand;
                TypeDefinition declaringType = ctor.DeclaringType.Resolve();

                return declaringType.HasGenericParameters && _collectionReplacements.ContainsKey(declaringType.FullName);
            }));
        }
Example #6
0
 private IEnumerable <Instruction> FieldAccesses(MethodBody body)
 {
     return(InstrumentationUtil.Where(body, IsActivatableFieldAccess));
 }
Example #7
0
 private static bool IsBaseConstructorInvocation(Instruction instruction)
 {
     return(InstrumentationUtil.IsCallInstruction(instruction) && HasConstructorOperand(instruction));
 }