Merge pull request #1156 from felfert/master
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / DynamicContext.cs
index f42783e4cd769f2d166e5eef0a8b1c3508dfdfd1..9c466c5ed9c9875b31f69f0f0ec9654075f3ac37 100644 (file)
@@ -78,12 +78,6 @@ namespace Microsoft.CSharp.RuntimeBinder
                                        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
@@ -93,17 +87,19 @@ namespace Microsoft.CSharp.RuntimeBinder
                                //
                                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);
 
-                               // 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
                                };
 
+                               // 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);
                                }
@@ -150,8 +146,14 @@ namespace Microsoft.CSharp.RuntimeBinder
                        Type value_type = (info.Flags & CSharpArgumentInfoFlags.UseCompileTimeType) != 0 ? value.Expression.Type : value.LimitType;
                        var type = ImportType (value_type);
 
-                       if ((info.Flags & CSharpArgumentInfoFlags.Constant) != 0)
-                               return Compiler.Constant.CreateConstantFromValue (type, value.Value, Compiler.Location.Null);
+                       if ((info.Flags & CSharpArgumentInfoFlags.Constant) != 0) {
+                               var c = Compiler.Constant.CreateConstantFromValue (type, value.Value, Compiler.Location.Null);
+                               //
+                               // It can be null for misused Constant flag
+                               //
+                               if (c != null)
+                                       return c;
+                       }
 
                        return new Compiler.RuntimeValueExpression (value, type);
                }