Exemplo n.º 1
0
            public override void Initialize()
            {
                // CoreAssembly = Host.LoadAssembly(Host.CoreAssemblySymbolicIdentity);

                var     host   = new PeReader.DefaultHost();
                IModule module = OperatorUtils.CompileModuleFromCode(
                    @"public class GenException : Exception
{
    public GenException()
    {
    }

    public GenException(object o1)
    {
    }
    public GenException(object o1, object o2)
    {
    }
}", host);

                /*   GeneratedType = (NamespaceTypeDefinition)module.GetAllTypes().Single(t => t.Name.Value == "VisualMutatorGeneratedClass");
                 * var methodBody = TypeHelper.GetMethod(GeneratedType,
                 *     host.NameTable.GetNameFor("FailOnZero"), host.PlatformType.SystemInt32).Body;
                 * var generatedBody = (SourceMethodBody)methodBody;
                 * GeneratedBlock = generatedBody.Block;*/
                host.Dispose();
            }
Exemplo n.º 2
0
            public override void Initialize()
            {
                CoreAssembly = Host.LoadAssembly(Host.CoreAssemblySymbolicIdentity);

                var     host   = new PeReader.DefaultHost();
                IModule module = OperatorUtils.CompileModuleFromCode(
                    @"using System;
namespace VisualMutatorGeneratedNamespace
{
    public class VisualMutatorGeneratedClass
    {
        public static int FailOnZero(int x)
        {
            if(x == 0) throw new InvalidOperationException(""FailOnZero: x"");
            return x;
        }
    }
}", host);

                GeneratedType = (NamespaceTypeDefinition)module.GetAllTypes().Single(t => t.Name.Value == "VisualMutatorGeneratedClass");
                var methodBody = TypeHelper.GetMethod(GeneratedType,
                                                      host.NameTable.GetNameFor("FailOnZero"), host.PlatformType.SystemInt32).Body;
                var generatedBody = (SourceMethodBody)methodBody;

                GeneratedBlock = generatedBody.Block;
                host.Dispose();
            }