private static void AssertLineInformation(string methodName, string expected)
        {
            AssemblyDefinition assembly = Db4oToolTestServices.AssemblyFromResource(ResourceName, typeof(DebugInformationTestSuite), DebugInformationTestVariables.TestWithDebugSymbolsAvailable(), SourceHandler);

            MethodDefinition method      = ReflectionServices.FindMethod(assembly, ResourceName, methodName);
            Instruction      instruction = ReflectionServices.FindInstruction(method, OpCodes.Callvirt);

            string actual = DebugInformation.InstructionInformationFor(instruction, method.Body.Instructions);

            string fixedExpectation = FixExpectation(expected);

            Assert.IsTrue(actual.Contains(fixedExpectation), string.Format("Expected: {0}, Actual: {1}", fixedExpectation, actual));
        }
示例#2
0
        private void InstrumentConcreteCollectionCasts(MethodDefinition methodDefinition)
        {
            foreach (var cast in CastsToSupportedCollections(methodDefinition.Body))
            {
                var result = StackAnalyzer.IsConsumedBy(MethodCallOnSupportedCollections, cast,
                                                        methodDefinition.DeclaringType.Module);
                if (!result.Match)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Error: [{0}] Invalid use of cast result: '{1}'.\r\nCasts to {2} are only allowed for property access/method calls.",
                                  methodDefinition,
                                  DebugInformation.InstructionInformationFor(result.Consumer,
                                                                             methodDefinition.Body.Instructions), cast.Operand));
                }

                var castTarget = (TypeReference)cast.Operand;
                ReplaceCastAndCalleeDeclaringType(cast, result.Consumer,
                                                  _collectionReplacements[castTarget.Resolve().FullName]);
            }
        }