[svn] r7769: nemerle/trunk/ncc/codedom: NemerleCodeGenerator.n NemerleCodeProvider.n NemerleMemberAttribut...

pbludov svnadmin at nemerle.org
Fri Aug 24 13:43:50 CEST 2007


Log:
Hide AssemblyAndFamily member access from WinForms designer.

Author: pbludov
Date: Fri Aug 24 13:43:47 2007
New Revision: 7769

Added:
   nemerle/trunk/ncc/codedom/NemerleMemberAttributeConverter.n
Modified:
   nemerle/trunk/ncc/codedom/NemerleCodeGenerator.n
   nemerle/trunk/ncc/codedom/NemerleCodeProvider.n

Modified: nemerle/trunk/ncc/codedom/NemerleCodeGenerator.n
==============================================================================
--- nemerle/trunk/ncc/codedom/NemerleCodeGenerator.n	(original)
+++ nemerle/trunk/ncc/codedom/NemerleCodeGenerator.n	Fri Aug 24 13:43:47 2007
@@ -103,12 +103,13 @@
 
     protected new Indent : int
     {
-      get { if (base.Output != null) base.Indent else output.Indent }
-      set {
-        when (base.Output != null)
-          base.Indent = value;
-        when (output != null)
-          output.Indent = value;
+      get { if (output != null) output.Indent else base.Indent }
+      set
+      {
+        if (output != null)
+          output.Indent = value
+        else
+          base.Indent = value
       }
     }
 
@@ -156,8 +157,6 @@
   
       when (createType.BaseType == "System.Object" || createType.BaseType == "object")
         output.Write(" :> array[object]");
-
-      output.WriteLine ();
     }
     
     protected override GenerateBaseReferenceExpression (_ : CodeBaseReferenceExpression) : void
@@ -1130,7 +1129,7 @@
         | MemberAttributes.Family => 
           output.Write("protected ");
 
-        | MemberAttributes.Assembly => 
+        | MemberAttributes.Assembly | MemberAttributes.FamilyAndAssembly => 
           output.Write("internal ");
 
         | MemberAttributes.FamilyOrAssembly => 

Modified: nemerle/trunk/ncc/codedom/NemerleCodeProvider.n
==============================================================================
--- nemerle/trunk/ncc/codedom/NemerleCodeProvider.n	(original)
+++ nemerle/trunk/ncc/codedom/NemerleCodeProvider.n	Fri Aug 24 13:43:47 2007
@@ -33,9 +33,12 @@
       NemerleCodeGenerator();
     }
 
-    public override GetConverter (_Type : Type) : TypeConverter
+    public override GetConverter (ty : Type) : TypeConverter
     {
-      throw NotImplementedException ();
+      if (typeof (System.CodeDom.MemberAttributes).Equals(ty))
+        NemerleMemberAttributeConverter.Default;
+      else
+        base.GetConverter (ty);
     }
   }
 }

Added: nemerle/trunk/ncc/codedom/NemerleMemberAttributeConverter.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/codedom/NemerleMemberAttributeConverter.n	Fri Aug 24 13:43:47 2007
@@ -0,0 +1,86 @@
+//
+// Permission is hereby granted,  free of charge,  to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"),  to deal in the Software without restriction,  including
+// without limitation the rights to use,  copy,  modify,  merge,  publish, 
+// distribute,  sublicense,  and/or sell copies of the Software,  and to
+// permit persons to whom the Software is furnished to do so,  subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS",  WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED,  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM,  DAMAGES OR OTHER LIABILITY,  WHETHER IN AN ACTION
+// OF CONTRACT,  TORT OR OTHERWISE,  ARISING FROM,  OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.ComponentModel;
+using System.CodeDom;
+using System.Globalization;
+
+namespace Nemerle.Compiler
+{
+  //
+  // This type converter provides supported values for MemberAttributes
+  //
+  internal class NemerleMemberAttributeConverter : TypeConverter
+  {
+    public override CanConvertFrom (context : ITypeDescriptorContext, sourceType : Type) : bool
+    {
+      typeof (string).Equals (sourceType) || base.CanConvertFrom (context, sourceType);
+    }
+
+    public override ConvertFrom (_ : ITypeDescriptorContext, _ : CultureInfo, value : object) : object
+    {
+      match (value)
+      {
+      | name is string =>
+        def idx = Array.IndexOf (_names, name);
+        if (idx < 0) _values[0] else _values[idx];
+      | _ => _values[0];
+      }
+    }
+
+    public override ConvertTo (context : ITypeDescriptorContext, culture : CultureInfo, value : object, destinationType : Type) : object
+    {
+      when (destinationType == null)
+        throw ArgumentNullException("destinationType");
+
+      if (typeof (string).Equals (destinationType))
+      {
+        def idx = Array.IndexOf (_values, value);
+        if (idx < 0) _names[0] else _names[idx];
+      }
+      else
+        base.ConvertTo (context, culture, value, destinationType);
+    }
+
+    public override GetStandardValuesExclusive (_ : ITypeDescriptorContext) : bool
+    {
+      true;
+    }
+
+    public override GetStandardValuesSupported (_ : ITypeDescriptorContext) : bool
+    {
+      true;
+    }
+
+    public override GetStandardValues (_ : ITypeDescriptorContext) : StandardValuesCollection
+    {
+      StandardValuesCollection (_values);
+    }
+
+    public static Default : NemerleMemberAttributeConverter
+      = NemerleMemberAttributeConverter();
+
+    private _names  : array [string] = array [ "Public", "Protected", "Protected Internal", "Internal", "Private" ];
+    private _values : array [object] = array [ MemberAttributes.Public : object, MemberAttributes.Family,
+       MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Private ];
+  }
+}
\ No newline at end of file



More information about the svn mailing list