Esempio n. 1
0
        public void Should_Copy_Method(string methodName)
        {
            var module = ModuleDefinition.ReadModule(Assembly.GetExecutingAssembly().Location);

            var methodDefinition = module.Types
                                   .Single(type => type.Name == nameof(ILCopierTests))
                                   .Methods.First(method => method.Name == methodName);

            var dynMethod = ILCopier.CopyToDynamicMethod(methodDefinition);
            var copied    = (Func <bool>)dynMethod.CreateDelegate(typeof(Func <bool>));

            copied();
        }
        public void ShouldCopyILCode([NotNull] string sampleName)
        {
            if (sampleName == null)
            {
                throw new ArgumentNullException(nameof(sampleName));
            }

            var method = Sample.GetMethod(sampleName);

            var dynamicMethod = ILCopier.CopyToDynamicMethod(method);
            var action        = (Func <bool>)dynamicMethod.CreateDelegate(typeof(Func <bool>));

            try
            {
                action();
            }
            catch (ExpectedException)
            {
            }
        }