當前位置: 首頁>>代碼示例>>C#>>正文


C# CSharp.CompilerContext類代碼示例

本文整理匯總了C#中Mono.CSharp.CompilerContext的典型用法代碼示例。如果您正苦於以下問題:C# CompilerContext類的具體用法?C# CompilerContext怎麽用?C# CompilerContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CompilerContext類屬於Mono.CSharp命名空間,在下文中一共展示了CompilerContext類的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");
        }
開發者ID:mkaput,項目名稱:csrepl,代碼行數:29,代碼來源:Program.cs

示例2: FeatureIsNotAvailable

		public void FeatureIsNotAvailable (CompilerContext compiler, Location loc, string feature)
		{
			string version;
			switch (compiler.Settings.Version) {
			case LanguageVersion.ISO_1:
				version = "1.0";
				break;
			case LanguageVersion.ISO_2:
				version = "2.0";
				break;
			case LanguageVersion.V_3:
				version = "3.0";
				break;
			case LanguageVersion.V_4:
				version = "4.0";
				break;
			case LanguageVersion.V_5:
				version = "5.0";
				break;
			default:
				throw new InternalErrorException ("Invalid feature version", compiler.Settings.Version);
			}

			Error (1644, loc,
				"Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
				      feature, version);
		}
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:27,代碼來源:report.cs

示例3: ScriptingEngine

        public ScriptingEngine()
        {
            tokenSource = new CancellationTokenSource();
            taskFactory = new TaskFactory(tokenSource.Token);

            context = new CompilerContext(new Mono.CSharp.CompilerSettings(), new ConsoleReportPrinter());
            evaluator = new Evaluator(context);
            evaluator.InteractiveBaseClass = typeof(ScriptingInteractiveBase);
            evaluator.DescribeTypeExpressions = true;

            ScriptingInteractiveBase.Evaluator = evaluator;
            var errorStream = new GuiStream(TextType.Error, OnConsoleOutput);
            var guiOutput = new StreamWriter(errorStream);
            guiOutput.AutoFlush = true;
            Console.SetError(guiOutput);
            ScriptingInteractiveBase.Output = guiOutput;

            var stdoutStream = new GuiStream(TextType.Output, OnConsoleOutput);
            guiOutput = new StreamWriter(stdoutStream);
            guiOutput.AutoFlush = true;
            Console.SetOut(guiOutput);
            ScriptingInteractiveBase.Error = guiOutput;

            codeCompletion = new CSharpCompletion(this);

            Evaluate("using System; using System.Linq; using System.Collections; using System.Collections.Generic;");

            //init the code completion so that the first character typed is not delayed
            //var readOnlyDocument = new ReadOnlyDocument(new StringTextSource(""), "init.csx");
            //codeCompletion.GetCompletions(readOnlyDocument, 0);
        }
開發者ID:CedarLogic,項目名稱:CShell,代碼行數:31,代碼來源:ScriptingEngine.cs

示例4: Main

        static void Main(string[] args)
        {
            var compilerContext = new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter());
            var evaluator = new Evaluator(compilerContext);

            // Make it reference our own assembly so it can use IFoo
            evaluator.ReferenceAssembly(typeof(IFoo).Assembly);

            // Feed it some code
            evaluator.Compile(
                @"
            public class Foo : MonoCompilerDemo.IFoo
            {
            public string Bar(string s) { return s.ToUpper(); }
            }");

            for (; ; )
            {
                string line = Console.ReadLine();
                if (line == null) break;

                object result;
                bool result_set;
                evaluator.Evaluate(line, out result, out result_set);
                if (result_set) Console.WriteLine(result);
            }
        }
開發者ID:davidebbo,項目名稱:MonoCompilerDemo,代碼行數:27,代碼來源:Program.cs

示例5: Shell

		public Shell(MainWindow container) : base()
		{
			this.container = container;
			WrapMode = WrapMode.Word;
			CreateTags ();

			Pango.FontDescription font_description = new Pango.FontDescription();
			font_description.Family = "Monospace";
			ModifyFont(font_description);
			
			TextIter end = Buffer.EndIter;
			Buffer.InsertWithTagsByName (ref end, "Mono C# Shell, type 'help;' for help\n\nEnter statements or expressions below.\n", "Comment");
			ShowPrompt (false);
			
			
			context = new CompilerContext (new CompilerSettings (), new ConsoleReportPrinter ());
			evaluator = new Evaluator (context);
			evaluator.DescribeTypeExpressions = true;
			
			evaluator.InteractiveBaseClass = typeof (InteractiveGraphicsBase);
			evaluator.Run ("LoadAssembly (\"System.Drawing\");");
			evaluator.Run ("using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Drawing;");

			if (!MainClass.Debug){
				GuiStream error_stream = new GuiStream ("Error", (x, y) => Output (x, y));
				StreamWriter gui_output = new StreamWriter (error_stream);
				gui_output.AutoFlush = true;
				Console.SetError (gui_output);

				GuiStream stdout_stream = new GuiStream ("Stdout", (x, y) => Output (x, y));
				gui_output = new StreamWriter (stdout_stream);
				gui_output.AutoFlush = true;
				Console.SetOut (gui_output);
			}
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:35,代碼來源:Shell.cs

示例6: Simple

		public void Simple ()
		{
			//string content = @"class A { }";
			string content = @"

class Foo
{
	void Bar ()
	{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
	}
}"
	;


			var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));

			var ctx = new CompilerContext (new CompilerSettings (), new AssertReportPrinter ());

			ModuleContainer module = new ModuleContainer (ctx);
			var file = new SourceFile ("test", "asdfas", 0);
			CSharpParser parser = new CSharpParser (
				new SeekableStreamReader (stream, Encoding.UTF8),
				new CompilationSourceFile (module, file),
				ctx.Report,
				new ParserSession ());

			RootContext.ToplevelTypes = module;
			Location.Initialize (new List<SourceFile> { file });
			parser.parse ();

			Assert.AreEqual (0, ctx.Report.Errors);

			module.Accept (new TestVisitor ());
		}
開發者ID:ItsVeryWindy,項目名稱:mono,代碼行數:35,代碼來源:ASTVisitorTest.cs

示例7: LookupTypeReflection

		public virtual Type LookupTypeReflection (CompilerContext ctx, string name, Location loc, bool must_be_unique)
		{
			Type found_type = null;

			foreach (Assembly a in referenced_assemblies) {
				Type t = GetTypeInAssembly (a, name);
				if (t == null)
					continue;

				if (!must_be_unique)
					return t;

				if (found_type == null) {
					found_type = t;
					continue;
				}

				// When type is forwarded
				if (t.Assembly == found_type.Assembly)
					continue;					

				ctx.Report.SymbolRelatedToPreviousError (found_type);
				ctx.Report.SymbolRelatedToPreviousError (t);
				if (loc.IsNull) {
					Error_AmbiguousPredefinedType (ctx, loc, name, found_type);
				} else {
					ctx.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name);
				}

				return found_type;
			}

			return found_type;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:34,代碼來源:namespace.cs

示例8: tokenize_file

		void tokenize_file (CompilationUnit file, CompilerContext ctx)
		{
			Stream input;

			try {
				input = File.OpenRead (file.Name);
			} catch {
				Report.Error (2001, "Source file `" + file.Name + "' could not be found");
				return;
			}

			using (input){
				SeekableStreamReader reader = new SeekableStreamReader (input, RootContext.Encoding);
				Tokenizer lexer = new Tokenizer (reader, file, ctx);
				int token, tokens = 0, errors = 0;

				while ((token = lexer.token ()) != Token.EOF){
					tokens++;
					if (token == Token.ERROR)
						errors++;
				}
				Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");
			}
			
			return;
		}
開發者ID:nekresh,項目名稱:mono,代碼行數:26,代碼來源:driver.cs

示例9: ModuleCompiled

        public ModuleCompiled(CompilerContext context, bool isUnsafe)
            : base(null)
        {
            this.is_unsafe = isUnsafe;
            this.context = context;

            types = new List<TypeContainer> ();
            anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
        }
開發者ID:speier,項目名稱:shake,代碼行數:9,代碼來源:roottypes.cs

示例10: ModuleContainer

		public ModuleContainer (CompilerContext context, bool isUnsafe)
			: base (null, null, MemberName.Null, null, Kind.Root)
		{
			this.is_unsafe = isUnsafe;
			this.context = context;

			types = new ArrayList ();
			anonymous_types = new Hashtable ();
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:9,代碼來源:roottypes.cs

示例11: InitDynamic

		//
		// Initializes the code generator variables for interactive use (repl)
		//
		static public void InitDynamic (CompilerContext ctx, string name)
		{
			current_domain = AppDomain.CurrentDomain;
			AssemblyName an = Assembly.GetAssemblyName (name, name);
			
			Assembly.Builder = current_domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
			RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
			RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (Basename (name), false);
			Assembly.Name = Assembly.Builder.GetName ();
		}
開發者ID:afaerber,項目名稱:mono,代碼行數:13,代碼來源:codegen.cs

示例12: Report

		public Report (CompilerContext context, ReportPrinter printer)
		{
			if (context == null)
				throw new ArgumentNullException ("settings");
			if (printer == null)
				throw new ArgumentNullException ("printer");

			this.settings = context.Settings;
			this.printer = printer;
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:10,代碼來源:report.cs

示例13: 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);
        }
開發者ID:pedershk,項目名稱:dotnetprograms,代碼行數:11,代碼來源:EvaluatorTest.cs

示例14: ModuleContainer

		public ModuleContainer (CompilerContext context)
			: base (null, null, MemberName.Null, null, 0)
		{
			this.context = context;

			caching_flags &= ~(Flags.Obsolete_Undetected | Flags.Excluded_Undetected);

			types = new List<TypeContainer> ();
			anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
			global_ns = new GlobalRootNamespace ();
			alias_ns = new Dictionary<string, RootNamespace> ();
		}
開發者ID:mpareja,項目名稱:mono,代碼行數:12,代碼來源:roottypes.cs

示例15: 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;
		}
開發者ID:ItsVeryWindy,項目名稱:mono,代碼行數:52,代碼來源:DynamicContext.cs


注:本文中的Mono.CSharp.CompilerContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。