static Assembly CompileCode(string cscode) { AssemblyComplier complier = new AssemblyComplier(); //complier.Domain = DomainManagment.Random; complier.Add(cscode); return(complier.GetAssembly()); }
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); }
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); }
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)); } }
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(); }
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(); }
public static T Create(AssemblyComplier complier, Action <AssemblyComplier> option = default) { return(Create(complier.Domain, option)); }
public ComplierTemplate() { Complier = new AssemblyComplier(); }
public static void Create(AssemblyComplier complier, ComplierResultTarget target, ComplierResultError error) { complier.EnumCRTarget = target; }
public static void Create(AssemblyComplier complier, ComplierResultError error, ComplierResultTarget target) { }
public OopBuilder() { Complier = new AssemblyComplier(); }
public OnceMethodBuilder(bool inCache = false) { _inCache = inCache; Complier = new AssemblyComplier(); }
public OnceMethodBuilder() { Complier = new AssemblyComplier(); }