本文整理汇总了C#中Mono.CSharp.CompilerSettings类的典型用法代码示例。如果您正苦于以下问题:C# CompilerSettings类的具体用法?C# CompilerSettings怎么用?C# CompilerSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerSettings类属于Mono.CSharp命名空间,在下文中一共展示了CompilerSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeEvaluator
private static void InitializeEvaluator()
{
_Interop.VarStorage["ReplVersion"] = typeof(Program).Assembly.GetName().Version;
var settings = new CompilerSettings() {
StdLib = true
};
var reportPrinter = new ConsoleReportPrinter();
var ctx = new CompilerContext(settings, reportPrinter);
evaluator = new Evaluator(ctx);
evaluator.ReferenceAssembly(typeof(_Interop).Assembly);
evaluator.Run(
@"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
");
evaluator.Run("var _v = _Interop.VarStorage;");
evaluator.Run("var _h = _Interop.History;");
evaluator.Run("_Interop.VoidMethod exit = _Interop.Exit;");
evaluator.Run("_Interop.ReturnStringListMethod globals = _Interop.GetGlobals");
}
示例2: CSharpCompiler
public CSharpCompiler()
{
CompilerSettings settings = new CompilerSettings ();
Report report = new Report (new NullReportPrinter ());
evaluator = new Evaluator (settings, report);
}
示例3: Run
public int Run()
{
// Enable unsafe code by default
var settings = new CompilerSettings () {
Unsafe = true
};
var startup_files = new string [0];
settings.SourceFiles.Clear ();
ReportPrinter printer= new ConsoleReportPrinter ();
var eval = new Evaluator (new CompilerContext (settings, printer));
eval.InteractiveBaseClass = typeof (InteractiveBaseShell);
eval.DescribeTypeExpressions = true;
eval.WaitOnTask = true;
CSharpShell shell;
#if !ON_DOTNET
if (attach.HasValue) {
shell = new ClientCSharpShell (eval, attach.Value);
} else if (agent != null) {
new CSharpAgent (eval, agent, agent_stderr).Run (startup_files);
return 0;
} else
#endif
{
shell = new CSharpShell (eval, console);
}
return shell.Run (startup_files);
}
示例4: Create
public static DynamicContext Create ()
{
if (dc != null)
return dc;
lock (compiler_initializer) {
if (dc != null)
return dc;
var reporter = new Compiler.Report (ErrorPrinter.Instance) {
WarningLevel = 0
};
var settings = new Compiler.CompilerSettings ();
var cc = new Compiler.CompilerContext (settings, reporter) {
IsRuntimeBinder = true
};
//IList<Compiler.PredefinedTypeSpec> core_types = null;
//// HACK: To avoid re-initializing static TypeManager types, like string_type
//if (!Compiler.RootContext.EvalMode) {
// core_types = Compiler.TypeManager.InitCoreTypes ();
//}
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer (cc);
module.HasTypesFullyDefined = true;
var temp = new Compiler.AssemblyDefinitionDynamic (module, "dynamic");
module.SetDeclaringAssembly (temp);
// Import all currently loaded assemblies
var domain = AppDomain.CurrentDomain;
temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
var importer = new Compiler.ReflectionImporter (module, cc.BuiltinTypes) {
IgnorePrivateMembers = false
};
foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
importer.ImportAssembly (a, module.GlobalRootNamespace);
}
cc.BuiltinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
dc = new DynamicContext (module, importer);
}
return dc;
}
示例5: Compiler
/// <summary>
/// Initializes a new instance of the <see cref="Dynamic.Compiler"/> class.
/// </summary>
/// <param name="project">Project.</param>
public Compiler(Project project)
{
Project = project;
Settings = new CompilerSettings()
{
OutputFile = "DynamicCodeTests-Scene.dll"
};
// Settings.AssemblyReferences.Remove("system.dll");
Trace.Log(TraceEventType.Information, "Project=\"{0}\"\nSettings:\n{1}", project.Name, Settings.ToString());
}
示例6: Setup
public void Setup()
{
var builder = new StringBuilder();
var writer = new StringWriter(builder);
var printer = new StreamReportPrinter(writer);
var settings = new CompilerSettings();
settings.AssemblyReferences.Add("DbTool.Testing");
var context = new CompilerContext(settings, printer);
_evaluator = new Evaluator(context);
}
示例7: Create
public static DynamicContext Create ()
{
if (dc != null)
return dc;
lock (compiler_initializer) {
if (dc != null)
return dc;
var settings = new Compiler.CompilerSettings () {
WarningLevel = 0
};
var cc = new Compiler.CompilerContext (settings, ErrorPrinter.Instance) {
IsRuntimeBinder = true
};
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer (cc);
module.HasTypesFullyDefined = true;
// Setup fake assembly, it's used mostly to simplify checks like friend-access
var temp = new Compiler.AssemblyDefinitionDynamic (module, "dynamic");
module.SetDeclaringAssembly (temp);
var importer = new Compiler.ReflectionImporter (module, cc.BuiltinTypes) {
IgnorePrivateMembers = false,
IgnoreCompilerGeneratedField = false
};
// Import all currently loaded assemblies
// TODO: Rewrite this to populate type cache on-demand, that should greatly
// reduce our start-up cost
var domain = AppDomain.CurrentDomain;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
importer.ImportAssembly (a, module.GlobalRootNamespace);
}
cc.BuiltinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
dc = new DynamicContext (module, importer);
}
return dc;
}
示例8: Evaluator
public Evaluator (CompilerSettings settings, Report report)
{
ctx = new CompilerContext (settings, report);
module = new ModuleContainer (ctx);
module.Evaluator = this;
// FIXME: Importer needs this assembly for internalsvisibleto
module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
importer = new ReflectionImporter (module, ctx.BuildinTypes);
InteractiveBaseClass = typeof (InteractiveBase);
fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
}
示例9: Main
static int Main (string [] args)
{
var cmd = new CommandLineParser (Console.Out);
cmd.UnknownOptionHandler += HandleExtraArguments;
// Enable unsafe code by default
var settings = new CompilerSettings () {
Unsafe = true
};
if (!cmd.ParseArguments (settings, args))
return 1;
var startup_files = new string [settings.SourceFiles.Count];
int i = 0;
foreach (var source in settings.SourceFiles)
startup_files [i++] = source.FullPathName;
settings.SourceFiles.Clear ();
TextWriter agent_stderr = null;
ReportPrinter printer;
if (agent != null) {
agent_stderr = new StringWriter ();
printer = new StreamReportPrinter (agent_stderr);
} else {
printer = new ConsoleReportPrinter ();
}
var eval = new Evaluator (new CompilerContext (settings, printer));
eval.InteractiveBaseClass = typeof (InteractiveBaseShell);
eval.DescribeTypeExpressions = true;
eval.WaitOnTask = true;
CSharpShell shell;
#if !ON_DOTNET
if (attach.HasValue) {
shell = new ClientCSharpShell (eval, attach.Value);
} else if (agent != null) {
new CSharpAgent (eval, agent, agent_stderr).Run (startup_files);
return 0;
} else
#endif
{
shell = new CSharpShell (eval);
}
return shell.Run (startup_files);
}
示例10: Init
public void Init()
{
var printer = new StreamReportPrinter(_stringWriter);
var settings = new CompilerSettings();
settings.AssemblyReferences.AddRange(InitialAssemblies);
var context = new CompilerContext(settings, printer);
_evaluator = new Evaluator(context)
{
InteractiveBaseClass = typeof (DbToolInteractive),
DescribeTypeExpressions = true,
};
ReferenceAssemblies(typeof(Database).Assembly, typeof(DynamicSqlQuery).Assembly);
Using(InitialUsings);
DbToolInteractive.Evaluator = _evaluator;
DbToolInteractive.Output = _stringWriter;
}
示例11: CreateContext
private CompilerContext CreateContext([NotNull] string source)
{
var settings = new CompilerSettings
{
Target = Target.Library,
TargetExt = ".dll",
LoadDefaultReferences = true,
ShowFullPaths = false,
StdLib = true,
};
var context = new CompilerContext(settings, new ConsoleReportPrinter(_logger));
context.SourceFiles.Add(new SourceFile("Source", source, 0));
_report = new Report(context, new ConsoleReportPrinter(_logger));
return context;
}
示例12: evaluateCode
// This method evaluates the given code and returns a CompilerOutput object
public static CompilerOutput evaluateCode(string code)
{
CompilerOutput compilerOutput = new CompilerOutput ();
/*
var compilerContext = new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter());
var evaluator = new Evaluator(compilerContext);
*/
var reportWriter = new StringWriter();
var settings = new CompilerSettings();
var printer = new ConsoleReportPrinter(reportWriter);
var compilerContext = new CompilerContext (settings, printer);
var reports = new Report(compilerContext, printer);
var evaluator = new Evaluator(compilerContext);
var myString = "";
originalConsoleOut_global = Console.Out; // preserve the original stream
using(var writer = new StringWriter())
{
Console.SetOut(writer);
evaluator.Run (code);
evaluator.Run ("MainClass m1 = new MainClass(); m1.Main();");
//bConsole.WriteLine ("after executing code");
if (reports.Errors > 0) {
Console.WriteLine ("reportWriter.ToString: \n" + reportWriter.ToString ());
compilerOutput.errors = reportWriter.ToString ();
}
writer.Flush(); // make sure everything is written out of consule
myString = writer.GetStringBuilder().ToString();
compilerOutput.consoleOut = myString;
}
Console.SetOut(originalConsoleOut_global); // restore Console.Out
return compilerOutput;
}
示例13: Initialize
///////////////////////////////////////////////////////////////////////
private void Initialize()
{
CompilerSettings sett = new CompilerSettings();
ReportPrinter prnt = new ConsoleReportPrinter();
// TODO programatically add references for all flynn assemblies
sett.AssemblyReferences.Add("Flynn.Core.dll");
sett.AssemblyReferences.Add("Flynn.X10.dll");
sett.AssemblyReferences.Add("Flynn.Cron.dll");
sett.AssemblyReferences.Add("Flynn.Utilities.dll");
CompilerContext ctx = new CompilerContext(sett, prnt);
_eval = new Evaluator(ctx);
_eval.Run(Resources.CSharpEngine_InitUsings);
_eval.Run(Resources.CSharpEngine_InitScript);
}
示例14: Evaluator
public Evaluator (CompilerSettings settings, Report report)
{
ctx = new CompilerContext (settings, report);
module = new ModuleContainer (ctx);
module.Evaluator = this;
source_file = new CompilationSourceFile ("{interactive}", "", 1);
source_file.NamespaceContainer = new NamespaceContainer (null, module, null, source_file);
ctx.SourceFiles.Add (source_file);
// FIXME: Importer needs this assembly for internalsvisibleto
module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
importer = new ReflectionImporter (module, ctx.BuiltinTypes);
InteractiveBaseClass = typeof (InteractiveBase);
fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
}
示例15: MonoCSharpExecutor
public MonoCSharpExecutor()
{
_reportBuilder = new StringBuilder();
var writer = new StringWriter(_reportBuilder);
var printer = new StreamReportPrinter(writer);
var settings = new CompilerSettings();
var context = new CompilerContext(settings, printer);
_evaluator = new Evaluator(context);
_evaluator.InteractiveBaseClass = typeof (InteractiveStuff);
_evaluator.ReferenceAssembly(typeof(HttpContext).Assembly);
_evaluator.ReferenceAssembly(typeof(VisualFarmRepo).Assembly);
_evaluator.ReferenceAssembly(typeof(BondegardFacade).Assembly);
_evaluator.ReferenceAssembly(typeof(IVFSConfig).Assembly);
Execute("using System;");
Execute("using System.Linq;");
Execute("using System.Web;");
Execute("using VisualFarmStudio.Core.Domain;");
Execute("using VisualFarmStudio.Core.Repository;");
Execute("using VisualFarmStudio.Lib.Model;");
Execute("using VisualFarmStudio.Lib.Containers;");
}