Пример #1
0
        public void SetUp()
        {
            var executingAssemblyDefinition = CecilUtilsForTests.GetExecutingAssemblyDefinition();

            _finder  = new CecilDefinitionFinder(executingAssemblyDefinition);
            _subject = new MethodMap(_finder.FindType(GetType().FullName));
        }
        public void GenericMethodSignature()
        {
            var assembly = CecilUtilsForTests.GetExecutingAssemblyDefinition();

            Assert.AreEqual(
                string.Format("System.Void {0}::GenericMethod<T>(T&)", GetType().FullName),
                MethodSignatureProvider.SignatureFor(assembly.MainModule.Types[GetType().FullName].Methods.GetMethod("GenericMethod")[0]));
        }
Пример #3
0
        public void FindGenericMethod()
        {
            var assembly = CecilUtilsForTests.GetExecutingAssemblyDefinition();
            var finder   = new CecilDefinitionFinder(assembly);
            var found    = finder.FindMethod(string.Format("System.Void {0}::GenericMethod<T>(T&)", GetType().FullName));

            Assert.IsNotNull(found);
        }
        public void MethodInGenericType()
        {
            var assembly      = CecilUtilsForTests.GetExecutingAssemblyDefinition();
            var cecilTypeName = typeof(GenericType <>).FullName.Replace('+', '/');

            Assert.AreEqual(
                string.Format("System.Void {0}::Foo(T&)", cecilTypeName),
                MethodSignatureProvider.SignatureFor(assembly.MainModule.Types[cecilTypeName].Methods.GetMethod("Foo")[0]));
        }
Пример #5
0
        private void AssertMethodRoundtrip(Func <int> func)
        {
            var method   = func.Method;
            var assembly = CecilUtilsForTests.GetExecutingAssemblyDefinition();
            var finder   = new CecilDefinitionFinder(assembly);

            // cecil uses / to introduce nested types, the runtime uses +
            var declaringTypeCecilName = method.DeclaringType.CecilTypeName();
            var type = finder.FindType(declaringTypeCecilName);

            Assert.IsNotNull(type, "Type {0} not found!", declaringTypeCecilName);

            var actualDefinition = type.Methods.GetMethod(method.Name)[0];
            var signature        = SignatureFor(actualDefinition);

            Assert.AreSame(actualDefinition, finder.FindMethod(signature));
        }