static Assembly CompileCode(string cscode)
        {
            AssemblyComplier complier = new AssemblyComplier();

            //complier.Domain = DomainManagment.Random;
            complier.Add(cscode);
            return(complier.GetAssembly());
        }
Esempio n. 2
0
        public static void RunClassName1()
        {
            //ScriptComplier.Init();
            string text = @"using System;
using System.Collections;
using System.Linq;
using System.Text;
 
namespace HelloWorld
{
    public class TestIndex1
    {
        public string Name;
        public int Age{get;set;}
    }
    public class TestIndex2
    {
        public string Name;
        public int Age{get;set;}
    }

    public class TestIndex3
    {
        public string Name;
        public int Age{get;set;}
    }
}

namespace HelloWorld{
    public struct TestStruct1{}
    public struct TestStruct2{}
    public class TestIndex4
    {
        public string Name;
        public int Age{get;set;}
    }
}

";
            //根据脚本创建动态类
            AssemblyComplier oop = new AssemblyComplier();

            oop.Add(text);
            Type type = oop.GetType("TestIndex3");

            Assert.Equal("TestIndex3", type.Name);
        }
Esempio n. 3
0
        public static void RunClassName0()
        {
            //ScriptComplier.Init();
            string text = @"
namespace HelloWorld
{public class Test{public Test(){
            Name=""111"";
        }public string Name;
        public int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            AssemblyComplier oop = new AssemblyComplier();

            oop.Add(text);
            Type type = oop.GetType("Test");

            Assert.Equal("Test", type.Name);
        }
Esempio n. 4
0
        public ReWriter(string filePath, bool useDepsJson = true)
        {
            References = new List <string>();
            _typeCache = new ConcurrentDictionary <string, Type>();
            _cache     = new ConcurrentDictionary <string, string>();
            var domain = DomainManagment.Random;

            OldPath = filePath;

            _complier = new AssemblyComplier
            {
                Domain       = domain,
                EnumCRTarget = ComplierResultTarget.File,
                AssemblyName = Path.GetFileNameWithoutExtension(filePath)
            };


            _pluginDomain = DomainManagment.Random;
            _assembly     = _pluginDomain.LoadStream(filePath);
            CSharpDecompiler _decomplier;

            if (useDepsJson)
            {
                var module   = new PEFile(filePath);
                var resolver = new UniversalAssemblyResolver(filePath, false, module.Reader.DetectTargetFrameworkId());
                _decomplier = new CSharpDecompiler(filePath, resolver, _setting);
            }
            else
            {
                _decomplier = new CSharpDecompiler(filePath, _setting);
            }


            foreach (var item in _assembly.ExportedTypes)
            {
                var temp = item.GetDevelopName();
                _typeCache[temp] = item;
                _cache[temp]     = _decomplier.DecompileTypeAsString(new FullTypeName(item.FullName));
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            /*
             *   在此之前,你需要右键,选择工程文件,在你的.csproj里面
             *
             *   写上这样一句浪漫的话:
             *
             *      <PreserveCompilationContext>true</PreserveCompilationContext>
             */


            string text = @"namespace HelloWorld
{
    public class Test
    {
        public Test(){
            Name=""111"";
        }

        public string Name;
        public int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            AssemblyComplier oop = new AssemblyComplier("test");

            oop.Add(text);
            Type type = oop.GetType("Test");

            Console.WriteLine(type.Name);

            var action = NDomain.Random().Action("");
            var a      = action.Method;

            Console.WriteLine(action.Method.Module.Assembly);


            Console.ReadKey();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            /*
             *   在此之前,你需要右键,选择工程文件,在你的.csproj里面
             *
             *   写上这样一句浪漫的话:
             *
             *      <PreserveCompilationContext>true</PreserveCompilationContext>
             */


            string text = @"namespace HelloWorld
{
    public class Test
    {
        public Test(){
            Name=""111"";
        }

        public string Name;
        public int Age{get;set;}
    }
}";
            //根据脚本创建动态类
            AssemblyComplier oop = new AssemblyComplier("test");

            oop.Add(text);
            Type type = oop.GetType("Test");


            var func = "return arg;".Delegate <Func <string, string> >();

            Console.WriteLine(func("111"));

            Console.ReadKey();
        }
Esempio n. 7
0
 public static T Create(AssemblyComplier complier, Action <AssemblyComplier> option = default)
 {
     return(Create(complier.Domain, option));
 }
Esempio n. 8
0
 public ComplierTemplate()
 {
     Complier = new AssemblyComplier();
 }
Esempio n. 9
0
 public static void Create(AssemblyComplier complier, ComplierResultTarget target, ComplierResultError error)
 {
     complier.EnumCRTarget = target;
 }
Esempio n. 10
0
 public static void Create(AssemblyComplier complier, ComplierResultError error, ComplierResultTarget target)
 {
 }
Esempio n. 11
0
 public OopBuilder()
 {
     Complier = new AssemblyComplier();
 }
Esempio n. 12
0
 public OnceMethodBuilder(bool inCache = false)
 {
     _inCache = inCache;
     Complier = new AssemblyComplier();
 }
Esempio n. 13
0
 public OnceMethodBuilder()
 {
     Complier = new AssemblyComplier();
 }