Esempio n. 1
0
        private static FieldInfo GetBackingField(MethodInfo method, ILPattern pattern) {
            MatchContext result = ILPattern.Match(method, pattern);
            if (!result.success)
                throw new NotSupportedException();

            return result.field;
        }
Esempio n. 2
0
        public void TestSequenceIsBackwardsMatch()
        {
            ILPattern sequence = ILPattern.Sequence(OpCodes.Stsfld, OpCodes.Ldsfld);

            Instruction lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence1);

            Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction));

            sequence = ILPattern.Sequence(OpCodes.Ldsfld, OpCodes.Stsfld);
            Assert.IsTrue(!sequence.IsBackwardsMatch(lastInstruction));
        }
Esempio n. 3
0
        public void TestSequenceBackwardsMatch()
        {
            ILPattern sequence = ILPattern.Sequence(OpCodes.Stsfld, OpCodes.Ldsfld);

            MethodDefinition method          = CreateTestMethod(TestSequence1);
            Instruction      lastInstruction = LastInstruction(method);

            ILPattern.MatchContext context = sequence.BackwardsMatch(lastInstruction);
            Assert.IsTrue(context.Success);
            Assert.AreSame(method.Body.Instructions[0], context.Instruction);
        }
 private static ILPattern CreateStaticFieldPattern()
 {
     // ldsfld (br_s)? stsfld newobj ldftn ldnull (brtrue_s | brtrue) ldsfld
     return(ILPattern.Sequence(
                ILPattern.Instruction(OpCodes.Ldsfld),
                ILPattern.Optional(OpCodes.Br_S),
                ILPattern.Instruction(OpCodes.Stsfld),
                ILPattern.Instruction(OpCodes.Newobj),
                ILPattern.Instruction(OpCodes.Ldftn),
                ILPattern.Instruction(OpCodes.Ldnull),
                ILPattern.Alternation(OpCodes.Brtrue, OpCodes.Brtrue_S),
                ILPattern.Instruction(OpCodes.Ldsfld)));
 }
Esempio n. 5
0
        public void TestComplexSequenceIsBackwardsMatch()
        {
            ILPattern sequence = ILPattern.Sequence(
                ILPattern.Optional(OpCodes.Ret),
                ILPattern.Instruction(OpCodes.Stsfld),
                ILPattern.Alternation(OpCodes.Ldfld, OpCodes.Ldsfld));

            Instruction lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence1);

            Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction));

            lastInstruction = CreateTestMethodAndReturnLastInstruction(TestSequence2);
            Assert.IsTrue(sequence.IsBackwardsMatch(lastInstruction));
        }
Esempio n. 6
0
 private static MatchContext MatchGetter(MethodInfo method)
 {
     return(ILPattern.Match(method, GetterPattern));
 }
Esempio n. 7
0
 public EitherPattern(ILPattern a, ILPattern b)
 {
     this.a = a;
     this.b = b;
 }