Fix GetUsing to output the using name instead of -> using Mono.CSharp.NamespaceExpres...
authorKenneth Pouncey <kjpou@pt.lu>
Fri, 7 Nov 2014 15:41:05 +0000 (16:41 +0100)
committerKenneth Pouncey <kjpou@pt.lu>
Fri, 7 Nov 2014 15:41:05 +0000 (16:41 +0100)
+ Fix NRE when source_file or source_file.Usings is null. This will now return back an empty string or empty List
+ **Note** that we are returning the ToString() value of NamespaceExpression which is the full resolved namespace of "System.Drawing" instead of "Drawing".
+ Add ToString override for NamespaceExpression to return the full resolved name of the namespace.

mcs/mcs/ecore.cs
mcs/mcs/eval.cs

index 3143908b63accad973ddba473d1f532987e364e5..a91f3dc6b82046d86e67a5a250e17e6f26312a16 100644 (file)
@@ -3208,6 +3208,11 @@ namespace Mono.CSharp {
                {
                        return ns.LookupTypeOrNamespace (ctx, name, arity, mode, loc);
                }
+
+               public override string ToString()
+               {
+                       return Namespace.Name;
+               }
     }
 
        /// <summary>
index 059ffb82d1db25721330f26f96b1ba6fd321ab9e..384d8dd3199235c67a59791c455ba5a1a42ed34c 100644 (file)
@@ -863,13 +863,19 @@ namespace Mono.CSharp
 
                public string GetUsing ()
                {
+                       if (source_file == null || source_file.Usings == null)
+                               return string.Empty;
+
                        StringBuilder sb = new StringBuilder ();
                        // TODO:
                        //foreach (object x in ns.using_alias_list)
                        //    sb.AppendFormat ("using {0};\n", x);
 
                        foreach (var ue in source_file.Usings) {
-                               sb.AppendFormat ("using {0};", ue.ToString ());
+                               if (ue.Alias != null || ue.ResolvedExpression == null)
+                                       continue;
+
+                               sb.AppendFormat("using {0};", ue.ToString());
                                sb.Append (Environment.NewLine);
                        }
 
@@ -880,7 +886,11 @@ namespace Mono.CSharp
                {
                        var res = new List<string> ();
 
-                       foreach (var ue in source_file.Usings) {
+                       if (source_file == null || source_file.Usings == null)
+                               return res;
+
+                       foreach (var ue in source_file.Usings)
+                       {
                                if (ue.Alias != null || ue.ResolvedExpression == null)
                                        continue;