public CompilerContext (ReflectionMetaImporter metaImporter, Report report) { this.meta_importer = metaImporter; this.report = report; this.attributes = new PredefinedAttributes (); this.root = new GlobalRootNamespace (); }
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; }
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; }
public CompilerContext (ReflectionMetaImporter metaImporter, Report report) { this.meta_importer = metaImporter; this.attributes = new PredefinedAttributes (); this.report = report; }
public ImportedTypeDefinition (ReflectionMetaImporter metaImport, Type type) : base (type) { this.meta_import = metaImport; }
//ReflectionMetaImporter metaImporter; public ImportedModuleDefinition (Module module, ReflectionMetaImporter metaImporter) { this.module = module; //this.metaImporter = metaImporter; }
public static AttributesBag Read (MemberInfo mi, ReflectionMetaImporter typeImporter) { AttributesBag bag = null; List<string> conditionals = null; // It should not throw any loading exception IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (mi); foreach (var a in attrs) { var type = a.Constructor.DeclaringType; if (type == typeof (ObsoleteAttribute)) { if (bag == null) bag = new AttributesBag (); var args = a.ConstructorArguments; if (args.Count == 1) { bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value); } else if (args.Count == 2) { bag.Obsolete = new ObsoleteAttribute ((string) args[0].Value, (bool) args[1].Value); } else { bag.Obsolete = new ObsoleteAttribute (); } continue; } if (type == typeof (ConditionalAttribute)) { if (bag == null) bag = new AttributesBag (); if (conditionals == null) conditionals = new List<string> (2); conditionals.Add ((string) a.ConstructorArguments[0].Value); continue; } if (type == typeof (CLSCompliantAttribute)) { if (bag == null) bag = new AttributesBag (); bag.IsNotCLSCompliant = !(bool) a.ConstructorArguments[0].Value; continue; } // Type only attributes if (mi.MemberType == MemberTypes.TypeInfo || mi.MemberType == MemberTypes.NestedType) { if (type == typeof (DefaultMemberAttribute)) { if (bag == null) bag = new AttributesBag (); bag.DefaultIndexerName = (string) a.ConstructorArguments[0].Value; continue; } if (type == typeof (AttributeUsageAttribute)) { if (bag == null) bag = new AttributesBag (); bag.AttributeUsage = new AttributeUsageAttribute ((AttributeTargets) a.ConstructorArguments[0].Value); foreach (var named in a.NamedArguments) { if (named.MemberInfo.Name == "AllowMultiple") bag.AttributeUsage.AllowMultiple = (bool) named.TypedValue.Value; else if (named.MemberInfo.Name == "Inherited") bag.AttributeUsage.Inherited = (bool) named.TypedValue.Value; } continue; } // Interface only attribute if (typeImporter != null && type == typeof (CoClassAttribute)) { if (bag == null) bag = new AttributesBag (); bag.CoClass = typeImporter.ImportType ((Type) a.ConstructorArguments[0].Value); continue; } } } if (bag == null) return Default; if (conditionals != null) bag.Conditionals = conditionals.ToArray (); return bag; }