コード例 #1
0
ファイル: CSharpBinder.cs プロジェクト: stabbylambda/mono
		public static DynamicContext Create ()
		{
			if (dc != null)
				return dc;

			lock (compiler_initializer) {
				if (dc != null)
					return dc;

				var importer = new Compiler.ReflectionMetaImporter () {
					IgnorePrivateMembers = false
				};

				var core_types = Compiler.TypeManager.InitCoreTypes ();
				importer.Initialize ();

				// I don't think dynamically loaded assemblies can be used as dynamic
				// expression without static type to be loaded first
				// AppDomain.CurrentDomain.AssemblyLoad += (sender, e) => { throw new NotImplementedException (); };

				// Import all currently loaded assemblies
				var ns = Compiler.GlobalRootNamespace.Instance;
				foreach (System.Reflection.Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
					ns.AddAssemblyReference (a);
					importer.ImportAssembly (a, ns);
				}

				var reporter = new Compiler.Report (ErrorPrinter.Instance) {
					WarningLevel = 0
				};

				var cc = new Compiler.CompilerContext (importer, reporter) {
					IsRuntimeBinder = true
				};

				Compiler.TypeManager.InitCoreTypes (cc, core_types);
				Compiler.TypeManager.InitOptionalCoreTypes (cc);

				dc = new DynamicContext (cc);
			}

			return dc;
		}
コード例 #2
0
ファイル: CSharpBinder.cs プロジェクト: davidwaters/mono
		public static DynamicContext Create ()
		{
			if (dc != null)
				return dc;

			lock (compiler_initializer) {
				if (dc != null)
					return dc;

				var importer = new Compiler.ReflectionMetaImporter () {
					IgnorePrivateMembers = false
				};

				var reporter = new Compiler.Report (ErrorPrinter.Instance) {
					WarningLevel = 0
				};

				var cc = new Compiler.CompilerContext (importer, 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 ();
				}

				importer.Initialize ();

				//
				// 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
				//
				Compiler.RootContext.ToplevelTypes = new Compiler.ModuleContainer (cc);
				var temp = Compiler.RootContext.ToplevelTypes.MakeExecutable ("dynamic");

				// Import all currently loaded assemblies
				var domain = AppDomain.CurrentDomain;

				temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
				foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
					importer.ImportAssembly (a, Compiler.RootContext.ToplevelTypes.GlobalRootNamespace);
				}

				if (!Compiler.RootContext.EvalMode) {
					Compiler.TypeManager.InitCoreTypes (Compiler.RootContext.ToplevelTypes, core_types);
					Compiler.TypeManager.InitOptionalCoreTypes (cc);
				}

				dc = new DynamicContext (cc);
			}

			return dc;
		}