Sfoglia il codice sorgente

* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
tests. Added enum, interface and delegate tests.
* CodeTypeDelegateTest.cs: Added tests for BaseTypes and ReturnType.
* CodeGeneratorTest.cs: Removed duplicate import of NUNit.Framework namespace.
* CodeGeneratorFromTypeTestBase.cs: Added BaseTypes and TypeConstructor tests.
* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
tests. Enabled enum, interface and delegate tests.
* CSharpCodeGenerator.cs: Fixed generated code for enums, interfaces
and delegates to match MS.NET.
* CodeTypeReference.cs: Added internal IsInterface property.
* CodeTypeDelegate.cs: System.Delegate is base type, and make sure
ReturnType is initialized.
* System_test.dll.sources: Added CodeTypeDelegateTest.cs from System.CodeDom.
* CodeGenerator.cs: Threat delegates like any other type.
* VBCodeGenerator.cs: Fixed generated code for enums, interfaces and
delegates to match MS.NET.

svn path=/trunk/mcs/; revision=47604

Gert Driesen 20 anni fa
parent
commit
cafc6003d6

+ 5 - 0
mcs/class/System/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-24 Gert Driesen <[email protected]>
+
+	* System_test.dll.sources: Added CodeTypeDelegateTest.cs from
+	System.CodeDom.
+
 2005-07-21 Gert Driesen <[email protected]>
 
 	* System_test.dll.sources: Added CodeGeneratorTest.cs from

+ 136 - 57
mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs

@@ -43,10 +43,9 @@ namespace Mono.CSharp
 	internal class CSharpCodeGenerator
 		: CodeGenerator
 	{
-            
 		// It is used for beautiful "for" syntax
 		bool dont_write_semicolon;
-            
+
 		//
 		// Constructors
 		//
@@ -527,6 +526,10 @@ namespace Mono.CSharp
 
 		protected override void GenerateEvent( CodeMemberEvent eventRef, CodeTypeDeclaration declaration )
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			OutputAttributes (eventRef.CustomAttributes, null, false);
 
 			if (eventRef.PrivateImplementationType == null) {
@@ -547,6 +550,10 @@ namespace Mono.CSharp
 
 		protected override void GenerateField( CodeMemberField field )
 		{
+			if (IsCurrentDelegate || IsCurrentInterface) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (field.CustomAttributes, null, false);
@@ -588,6 +595,10 @@ namespace Mono.CSharp
 		protected override void GenerateMethod( CodeMemberMethod method,
 							CodeTypeDeclaration declaration )
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (method.CustomAttributes, null, false);
@@ -638,20 +649,26 @@ namespace Mono.CSharp
 		protected override void GenerateProperty( CodeMemberProperty property,
 							  CodeTypeDeclaration declaration )
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (property.CustomAttributes, null, false);
 
-			if (property.PrivateImplementationType == null) {
-				MemberAttributes attributes = property.Attributes;
-				OutputMemberAccessModifier (attributes);
-				OutputMemberScopeModifier (attributes);
+			if (!IsCurrentInterface) {
+				if (property.PrivateImplementationType == null) {
+					MemberAttributes attributes = property.Attributes;
+					OutputMemberAccessModifier (attributes);
+					OutputMemberScopeModifier (attributes);
+				}
 			}
 
 			OutputType (property.Type);
 			output.Write (' ');
 
-			if (property.PrivateImplementationType != null) {
+			if (!IsCurrentInterface && property.PrivateImplementationType != null) {
 				output.Write (property.PrivateImplementationType.BaseType);
 				output.Write ('.');
 			}
@@ -670,8 +687,8 @@ namespace Mono.CSharp
 
 			if (declaration.IsInterface)
 			{
-				if (property.HasGet) output.WriteLine("get; ");
-				if (property.HasSet) output.WriteLine("set; ");
+				if (property.HasGet) output.WriteLine("get;");
+				if (property.HasSet) output.WriteLine("set;");
 			}
 			else
 			{
@@ -702,9 +719,12 @@ namespace Mono.CSharp
 			output.WriteLine ('}');
 		}
 
-		protected override void GenerateConstructor( CodeConstructor constructor,
-							     CodeTypeDeclaration declaration )
+		protected override void GenerateConstructor( CodeConstructor constructor, CodeTypeDeclaration declaration )
 		{
+			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+				return;
+			}
+
 			OutputAttributes (constructor.CustomAttributes, null, false);
 
 			OutputMemberAccessModifier (constructor.Attributes);
@@ -736,6 +756,14 @@ namespace Mono.CSharp
 		
 		protected override void GenerateTypeConstructor( CodeTypeConstructor constructor )
 		{
+			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+				return;
+			}
+
+#if NET_2_0
+			OutputAttributes (constructor.CustomAttributes, null, false);
+#endif
+
 			Output.WriteLine ("static " + GetSafeName (CurrentTypeName) + "() {");
 			Indent++;
 			GenerateStatements (constructor.Statements);
@@ -743,65 +771,63 @@ namespace Mono.CSharp
 			Output.WriteLine ('}');
 		}
 
-		protected override void GenerateTypeStart( CodeTypeDeclaration declaration )
+		protected override void GenerateTypeStart(CodeTypeDeclaration declaration)
 		{
 			TextWriter output = Output;
-			CodeTypeDelegate del = declaration as CodeTypeDelegate;
 
 			OutputAttributes (declaration.CustomAttributes, null, false);
 
-			TypeAttributes attributes = declaration.TypeAttributes;
-			OutputTypeAttributes( attributes,
-					      declaration.IsStruct,
-					      declaration.IsEnum );
-
-			if (del != null) {
-				if (del.ReturnType != null)
-					OutputType (del.ReturnType);
-				else
-					Output.Write ("void");
-				output.Write(' ');
-			}
+			if (!IsCurrentDelegate) {
+				OutputTypeAttributes (declaration);
 
-			output.Write( GetSafeName (declaration.Name) );
+				output.Write (GetSafeName (declaration.Name));
 
 #if NET_2_0
-			GenerateGenericsParameters (declaration.TypeParameters);
+				GenerateGenericsParameters (declaration.TypeParameters);
 #endif
-			
-			IEnumerator enumerator = declaration.BaseTypes.GetEnumerator();
-			if ( enumerator.MoveNext() ) {
-				CodeTypeReference type = (CodeTypeReference)enumerator.Current;
-			
-				output.Write( ": " );
-				OutputType( type );
-				
-				while ( enumerator.MoveNext() ) {
-					type = (CodeTypeReference)enumerator.Current;
-				
-					output.Write( ", " );
-					OutputType( type );
+
+				IEnumerator enumerator = declaration.BaseTypes.GetEnumerator ();
+				if (enumerator.MoveNext ()) {
+					CodeTypeReference type = (CodeTypeReference) enumerator.Current;
+
+					output.Write (" : ");
+					OutputType (type);
+
+					while (enumerator.MoveNext ()) {
+						type = (CodeTypeReference) enumerator.Current;
+
+						output.Write (", ");
+						OutputType (type);
+					}
 				}
-			}
 
-			if (del != null)
-				output.Write ( " (" );
-			else {
 #if NET_2_0
 				GenerateGenericsConstraints (declaration.TypeParameters);
 #endif
-				output.WriteLine ( " {" );
+				output.WriteLine (" {");
+				++Indent;
+			} else {
+				if ((declaration.TypeAttributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
+					output.Write ("public ");
+				}
+
+				CodeTypeDelegate delegateDecl = (CodeTypeDelegate) declaration;
+				output.Write ("delegate ");
+				OutputType (delegateDecl.ReturnType);
+				output.Write (" ");
+				output.Write (GetSafeName (declaration.Name));
+				output.Write ("(");
+				OutputParameters (delegateDecl.Parameters);
+				output.WriteLine (");");
 			}
-			++Indent;
 		}
 
 		protected override void GenerateTypeEnd( CodeTypeDeclaration declaration )
 		{
-			--Indent;
-			if (declaration is CodeTypeDelegate)
-				Output.WriteLine (");");
-			else
+			if (!IsCurrentDelegate) {
+				--Indent;
 				Output.WriteLine ("}");
+			}
 		}
 
 		protected override void GenerateNamespaceStart( CodeNamespace ns )
@@ -885,6 +911,66 @@ namespace Mono.CSharp
 			Output.Write( GetTypeOutput( type ) );
 		}
 
+		private void OutputTypeAttributes (CodeTypeDeclaration declaration)
+		{
+			TextWriter output = Output;
+			TypeAttributes attributes = declaration.TypeAttributes;
+
+			switch (attributes & TypeAttributes.VisibilityMask) {
+				case TypeAttributes.Public:
+				case TypeAttributes.NestedPublic:
+					output.Write ("public ");
+					break;
+				case TypeAttributes.NestedPrivate:
+					output.Write ("private ");
+					break;
+#if NET_2_0
+				case TypeAttributes.NotPublic:
+				case TypeAttributes.NestedFamANDAssem:
+				case TypeAttributes.NestedAssembly:
+					output.Write ("internal ");
+					break; 
+				case TypeAttributes.NestedFamily:
+					output.Write ("protected ");
+					break;
+				case TypeAttributes.NestedFamORAssem:
+					output.Write ("protected internal ");
+					break;
+#endif
+			}
+
+			if (declaration.IsStruct) {
+#if NET_2_0
+				if (declaration.IsPartial) {
+					output.Write ("partial ");
+				}
+#endif
+				output.Write ("struct ");
+			} else if (declaration.IsEnum) {
+				output.Write ("enum ");
+			} else {
+				if ((attributes & TypeAttributes.Interface) != 0) {
+#if NET_2_0
+					if (declaration.IsPartial) {
+						output.Write ("partial ");
+					}
+#endif
+					output.Write ("interface ");
+				} else {
+					if ((attributes & TypeAttributes.Sealed) != 0)
+						output.Write ("sealed ");
+					if ((attributes & TypeAttributes.Abstract) != 0)
+						output.Write ("abstract ");
+#if NET_2_0
+					if (declaration.IsPartial) {
+						output.Write ("partial ");
+					}
+#endif
+					output.Write ("class ");
+				}
+			}
+		}
+
 		[MonoTODO ("Implement missing special characters")]
 		protected override string QuoteSnippetString( string value )
 		{
@@ -1138,15 +1224,8 @@ namespace Mono.CSharp
 			sb [sb.Length - 1] = '>';
 			return sb.ToString ();
 		}
-
-		internal override void OutputExtraTypeAttribute (CodeTypeDeclaration type)
-		{
-			if (type.IsPartial)
-				Output.Write ("partial ");
-		}
 #endif
 
-
 #if false
 		//[MonoTODO]
 		public override void ValidateIdentifier( string identifier )

+ 5 - 0
mcs/class/System/Microsoft.CSharp/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-24 Gert Driesen <[email protected]>
+
+	* CSharpCodeGenerator.cs: Fixed generated code for enums, interfaces
+	and delegates to match MS.NET.
+
 2005-07-02 Gert Driesen <[email protected]>
 
 	* CSharpCodeGenerator.cs: Fixed output of ReturnTypeCustomAttributes.

+ 5 - 0
mcs/class/System/Microsoft.VisualBasic/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-24  Gert Driesen <[email protected]>
+
+	* VBCodeGenerator.cs: Fixed generated code for enums, interfaces and
+	delegates to match MS.NET.
+
 2005-07-02  Gert Driesen <[email protected]>
 
 	* VBCodeGenerator.cs: Added support for ReturnTypeCustomAttributes.

+ 180 - 111
mcs/class/System/Microsoft.VisualBasic/VBCodeGenerator.cs

@@ -565,6 +565,10 @@ namespace Microsoft.VisualBasic
 
 		protected override void GenerateEvent (CodeMemberEvent eventRef, CodeTypeDeclaration declaration)
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (eventRef.CustomAttributes, null, 
@@ -591,16 +595,23 @@ namespace Microsoft.VisualBasic
 
 		protected override void GenerateField (CodeMemberField field)
 		{
+			if (IsCurrentDelegate || IsCurrentInterface) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (field.CustomAttributes, null, 
 				LineHandling.ContinueLine);
 
-			MemberAttributes attributes = field.Attributes;
-			OutputMemberAccessModifier (attributes);
-			OutputFieldScopeModifier (attributes);
-
-			OutputTypeNamePair (field.Type, field.Name);
+			if (IsCurrentEnum) {
+				output.Write (field.Name);
+			} else {
+				MemberAttributes attributes = field.Attributes;
+				OutputMemberAccessModifier (attributes);
+				OutputFieldScopeModifier (attributes);
+				OutputTypeNamePair (field.Type, field.Name);
+			}
 
 			CodeExpression initExpression = field.InitExpression;
 			if (initExpression != null) {
@@ -625,6 +636,10 @@ namespace Microsoft.VisualBasic
 		[MonoTODO ("partially implemented")]
 		protected override void GenerateMethod (CodeMemberMethod method, CodeTypeDeclaration declaration)
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			bool isSub = method.ReturnType.BaseType == typeof(void).FullName;
 
 			TextWriter output = Output;
@@ -634,15 +649,16 @@ namespace Microsoft.VisualBasic
 
 			MemberAttributes attributes = method.Attributes;
 
-			if (method.PrivateImplementationType == null) {
-				OutputMemberAccessModifier (attributes);
-				if (IsOverloaded (method, declaration)) {
-					output.Write ("Overloads ");
+			if (!IsCurrentInterface) {
+				if (method.PrivateImplementationType == null) {
+					OutputMemberAccessModifier (attributes);
+					if (IsOverloaded (method, declaration)) {
+						output.Write ("Overloads ");
+					}
 				}
+				OutputMemberScopeModifier (attributes);
 			}
 
-			OutputMemberScopeModifier (attributes);
-
 			if (isSub)
 				output.Write ("Sub ");
 			else
@@ -669,35 +685,41 @@ namespace Microsoft.VisualBasic
 				output.Write (method.Name);
 			}
 
-			if ((attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract)
-				output.WriteLine ();
-			else {
-				output.WriteLine ();
-				++Indent;
-				GenerateStatements (method.Statements);
-				--Indent;
-				if (isSub)
-					output.WriteLine ("End Sub");
-				else
-					output.WriteLine ("End Function");
+			output.WriteLine ();
+			if (!IsCurrentInterface) {
+				if ((attributes & MemberAttributes.ScopeMask) != MemberAttributes.Abstract) {
+					++Indent;
+					GenerateStatements (method.Statements);
+					--Indent;
+					if (isSub)
+						output.WriteLine ("End Sub");
+					else
+						output.WriteLine ("End Function");
+				}
 			}
 		}
 
 		protected override void GenerateProperty (CodeMemberProperty property, CodeTypeDeclaration declaration)
 		{
+			if (IsCurrentDelegate || IsCurrentEnum) {
+				return;
+			}
+
 			TextWriter output = Output;
 
 			OutputAttributes (property.CustomAttributes, null, 
 				LineHandling.ContinueLine);
 
-			MemberAttributes attributes = property.Attributes;
-			if (property.PrivateImplementationType == null) {
-				OutputMemberAccessModifier (attributes);
-				if (IsOverloaded (property, declaration)) {
-					output.Write ("Overloads ");
+			if (!IsCurrentInterface) {
+				MemberAttributes attributes = property.Attributes;
+				if (property.PrivateImplementationType == null) {
+					OutputMemberAccessModifier (attributes);
+					if (IsOverloaded (property, declaration)) {
+						output.Write ("Overloads ");
+					}
 				}
+				OutputMemberScopeModifier (attributes);
 			}
-			OutputMemberScopeModifier (attributes);
 
 			// mark property as default property if we're dealing with an indexer
 			if (string.Compare (GetPropertyName(property), "Item", true, CultureInfo.InvariantCulture) == 0 && property.Parameters.Count > 0) {
@@ -738,30 +760,36 @@ namespace Microsoft.VisualBasic
 			}
 
 			output.WriteLine ();
-			++Indent;
 
-			if (property.HasGet) {
-				output.WriteLine ("Get");
+			if (!IsCurrentInterface) {
 				++Indent;
-				GenerateStatements (property.GetStatements);
-				--Indent;
-				output.WriteLine ("End Get");
-			}
-			
-			if (property.HasSet) {
-				output.WriteLine ("Set");
-				++Indent;
-				GenerateStatements (property.SetStatements);
+				if (property.HasGet) {
+					output.WriteLine ("Get");
+					++Indent;
+					GenerateStatements (property.GetStatements);
+					--Indent;
+					output.WriteLine ("End Get");
+				}
+
+				if (property.HasSet) {
+					output.WriteLine ("Set");
+					++Indent;
+					GenerateStatements (property.SetStatements);
+					--Indent;
+					output.WriteLine ("End Set");
+				}
+
 				--Indent;
-				output.WriteLine ("End Set");
+				output.WriteLine ("End Property");
 			}
-
-			--Indent;
-			output.WriteLine ("End Property");
 		}
 
 		protected override void GenerateConstructor (CodeConstructor constructor, CodeTypeDeclaration declaration)
 		{
+			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+				return;
+			}
+
 			OutputAttributes (constructor.CustomAttributes, null,
 				LineHandling.ContinueLine);
 			OutputMemberAccessModifier (constructor.Attributes);
@@ -782,7 +810,11 @@ namespace Microsoft.VisualBasic
 					Output.Write ("MyBase.New(");
 					OutputExpressionList (ctorArgs);
 					Output.WriteLine (")");
+#if NET_2_0
+				} else if (IsCurrentClass) {
+#else
 				} else {
+#endif
 					// call default base ctor
 					Output.WriteLine ("MyBase.New");
 				}
@@ -794,6 +826,15 @@ namespace Microsoft.VisualBasic
 		
 		protected override void GenerateTypeConstructor (CodeTypeConstructor constructor)
 		{
+			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+				return;
+			}
+
+#if NET_2_0
+			OutputAttributes (constructor.CustomAttributes, null,
+				LineHandling.ContinueLine);
+#endif
+
 			Output.WriteLine ("Shared Sub New()");
 			Indent++;
 			GenerateStatements (constructor.Statements);
@@ -810,42 +851,76 @@ namespace Microsoft.VisualBasic
 				LineHandling.ContinueLine);
 
 			TypeAttributes attributes = declaration.TypeAttributes;
-			OutputTypeAttributes (attributes,
-				declaration.IsStruct,
-				declaration.IsEnum);
 
-			output.WriteLine (declaration.Name);
+			if (IsCurrentDelegate) {
+				CodeTypeDelegate delegateDecl = (CodeTypeDelegate) declaration;
 
-			++Indent;
-			
-			IEnumerator enumerator = declaration.BaseTypes.GetEnumerator();
-			if (enumerator.MoveNext()) 
-			{
-				CodeTypeReference type = (CodeTypeReference)enumerator.Current;
-			
-				if (type != null)
-				{
-					output.Write ("Inherits ");
-					OutputType (type);
-					output.WriteLine ();
+				if ((attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
+					output.Write ("Public ");
 				}
-				
-				while (enumerator.MoveNext()) 
-				{
-					type = (CodeTypeReference)enumerator.Current;
-				
-					if (type != null)
-					{
-						output.Write ("Implements ");
-						OutputType (type);
-						output.WriteLine ();
+
+				bool isSub = delegateDecl.ReturnType.BaseType == typeof (void).FullName;
+				if (isSub) {
+					output.Write ("Delegate Sub ");
+				} else {
+					output.Write ("Delegate Function ");
+				}
+
+				output.Write (delegateDecl.Name);
+				output.Write ("(");
+				Output.Write (")");
+				if (!isSub) {
+					Output.Write (" As ");
+					OutputType (delegateDecl.ReturnType);
+				}
+				Output.WriteLine ("");
+			} else {
+				OutputTypeAttributes (declaration);
+
+				output.Write (declaration.Name);
+
+				if (IsCurrentEnum) {
+					if (declaration.BaseTypes.Count > 0) {
+						output.Write (" As ");
+						OutputType (declaration.BaseTypes[0]);
+					}
+					output.WriteLine ();
+					++Indent;
+				} else {
+					++Indent;
+
+					bool firstInherits = true;
+					bool firstImplements = true;
+
+					for (int i = 0; i < declaration.BaseTypes.Count; i++) {
+						// a struct can only implement interfaces
+						// an interface can only inherit from other interface
+
+						CodeTypeReference typeRef = declaration.BaseTypes[i];
+						
+						if (firstInherits && !declaration.IsStruct && !typeRef.IsInterface) {
+							output.WriteLine ();
+							output.Write ("Inherits ");
+							firstInherits = false;
+						} else if (!declaration.IsInterface && firstImplements) {
+							output.WriteLine ();
+							output.Write ("Implements ");
+							firstImplements = false;
+						} else {
+							output.Write (", ");
+						}
+						OutputType (typeRef);
 					}
+					output.WriteLine ();
 				}
 			}
 		}
 
 		protected override void GenerateTypeEnd (CodeTypeDeclaration declaration)
 		{
+			if (IsCurrentDelegate) {
+				return;
+			}
 			string output = string.Empty;
 
 			--Indent;
@@ -1079,11 +1154,12 @@ namespace Microsoft.VisualBasic
 			case MemberAttributes.Overloaded:
 				// based on http://gendotnet.com/Code%20Gen%20Articles/codedom.htm
 				Output.Write ("Overloads ");
-                                MemberAttributes access_ovl = attributes & MemberAttributes.AccessMask;
-                                if ( access_ovl == MemberAttributes.Public || 
-                                        access_ovl == MemberAttributes.Family )
-                                        Output.Write ("Overridable ");
-                                break;
+
+				MemberAttributes access_ovl = attributes & MemberAttributes.AccessMask;
+				if (access_ovl == MemberAttributes.Public || access_ovl == MemberAttributes.Family) {
+					Output.Write ("Overridable ");
+				}
+				break;
 			default:
 				//
 				// FUNNY! if the scope value is
@@ -1167,55 +1243,48 @@ namespace Microsoft.VisualBasic
 			}
 		}
 
-		protected override void OutputTypeAttributes (TypeAttributes attributes, bool isStruct, bool isEnum)
+		private void OutputTypeAttributes (CodeTypeDeclaration declaration)
 		{
 			TextWriter output = Output;
+			TypeAttributes attributes = declaration.TypeAttributes;
 
 			switch (attributes & TypeAttributes.VisibilityMask) {
-			case TypeAttributes.NotPublic:
-				// Does this mean friend access?
-				output.Write ("Friend ");
-				break; 
-
-			case TypeAttributes.Public:
-			case TypeAttributes.NestedPublic:
-				output.Write ("Public ");
-				break;
-
-			case TypeAttributes.NestedPrivate:
-				output.Write ("Private ");
-				break;
-			case TypeAttributes.NestedAssembly:
-				output.Write ("Friend ");
-				break;
-			case TypeAttributes.NestedFamily:
-				output.Write ("Protected ");
-				break;
-			case TypeAttributes.NestedFamORAssem:
-				output.Write ("Protected Friend ");
-				break;
-			case TypeAttributes.NestedFamANDAssem:
-				output.Write ("Friend ");
-				break;
+				case TypeAttributes.Public:
+				case TypeAttributes.NestedPublic:
+					output.Write ("Public ");
+					break;
+				case TypeAttributes.NestedPrivate:
+					output.Write ("Private ");
+					break;
+#if NET_2_0
+				case TypeAttributes.NotPublic:
+				case TypeAttributes.NestedFamANDAssem:
+				case TypeAttributes.NestedAssembly:
+					output.Write ("Friend ");
+					break; 
+				case TypeAttributes.NestedFamily:
+					output.Write ("Protected ");
+					break;
+				case TypeAttributes.NestedFamORAssem:
+					output.Write ("Protected Friend ");
+					break;
+#endif
 			}
 
-			if (isStruct)
+			if (declaration.IsStruct) {
 				output.Write ("Structure ");
-
-			else if (isEnum)
-				output.Write ("Enumeration ");
-
-			else {
-				if ((attributes & TypeAttributes.Interface) != 0) 
+			} else if (declaration.IsEnum) {
+				output.Write ("Enum ");
+			} else {
+				if ((attributes & TypeAttributes.Interface) != 0) {
 					output.Write ("Interface ");
-
-				else {
+				} else {
 					if ((attributes & TypeAttributes.Sealed) != 0)
 						output.Write ("NotInheritable ");
 
 					if ((attributes & TypeAttributes.Abstract) != 0)
 						output.Write ("MustInherit ");
-					
+
 					output.Write ("Class ");
 				}
 			}

+ 4 - 0
mcs/class/System/System.CodeDom.Compiler/ChangeLog

@@ -1,3 +1,7 @@
+2005-07-24 Gert Driesen <[email protected]>
+
+	* CodeGenerator.cs: Threat delegates like any other type.
+
 2005-07-21 Gert Driesen <[email protected]>
 
 	* CodeGenerator.cs: Fixed IsCurrentClass to return false for delegate.

+ 26 - 60
mcs/class/System/System.CodeDom.Compiler/CodeGenerator.cs

@@ -927,9 +927,6 @@ namespace System.CodeDom.Compiler {
 				break;
 			}
 
-			if (!IsCurrentClass)
-				OutputExtraTypeAttribute (currentType);
-
 			if (isStruct)
 				output.Write ("struct ");
 
@@ -946,16 +943,11 @@ namespace System.CodeDom.Compiler {
 					if ((attributes & TypeAttributes.Abstract) != 0)
 						output.Write ("abstract ");
 					
-					OutputExtraTypeAttribute (currentType);
 					output.Write ("class ");
 				}
 			}
 		}
 
-		internal virtual void OutputExtraTypeAttribute (CodeTypeDeclaration type)
-		{
-		}
-		
 		protected virtual void OutputTypeNamePair (CodeTypeReference type,
 							   string name)
 		{
@@ -1037,6 +1029,8 @@ namespace System.CodeDom.Compiler {
 
 		private void GenerateType (CodeTypeDeclaration type)
 		{
+			this.currentType = type;
+
 #if NET_2_0
 			if (type.StartDirectives.Count > 0)
 				GenerateDirectives (type.StartDirectives);
@@ -1047,56 +1041,27 @@ namespace System.CodeDom.Compiler {
 			if (type.LinePragma != null)
 				GenerateLinePragmaStart (type.LinePragma);
 
-			CodeTypeDelegate del = type as CodeTypeDelegate;
-			if (del != null)
-				GenerateDelegate (del);
-			else
-				GenerateNonDelegateType (type);
-
-			if (type.LinePragma != null)
-				GenerateLinePragmaEnd (type.LinePragma);
-
-#if NET_2_0
-			if (type.EndDirectives.Count > 0)
-				GenerateDirectives (type.EndDirectives);
-#endif
-		}
-
-		private void GenerateDelegate (CodeTypeDelegate type)
-		{
-			this.currentType = type;
-
-			GenerateTypeStart (type);
-			OutputParameters (type.Parameters);
-			GenerateTypeEnd (type);
-		}
-		
-		private void GenerateNonDelegateType (CodeTypeDeclaration type)
-		{
-			this.currentType = type;
-
 			GenerateTypeStart (type);
 
-			CodeTypeMember [] members = new CodeTypeMember [type.Members.Count];
+			CodeTypeMember[] members = new CodeTypeMember[type.Members.Count];
 			type.Members.CopyTo (members, 0);
 
 #if NET_2_0
 			if (!Options.VerbatimOrder)
 #endif
-			{
+ {
 				int[] order = new int[members.Length];
-				for (int n=0; n<members.Length; n++)
-					order[n] = Array.IndexOf(memberTypes, members[n].GetType()) * members.Length + n;
+				for (int n = 0; n < members.Length; n++)
+					order[n] = Array.IndexOf (memberTypes, members[n].GetType ()) * members.Length + n;
 
 				Array.Sort (order, members);
 			}
-			
+
 			// WARNING: if anything is missing in the foreach loop and you add it, add the type in
 			// its corresponding place in CodeTypeMemberComparer class (below)
 
 			CodeTypeDeclaration subtype = null;
-			foreach (CodeTypeMember member in members) 
-			{
+			foreach (CodeTypeMember member in members) {
 				CodeTypeMember prevMember = this.currentMember;
 				this.currentMember = member;
 
@@ -1130,54 +1095,46 @@ namespace System.CodeDom.Compiler {
 					GenerateLinePragmaStart (member.LinePragma);
 
 				CodeMemberEvent eventm = member as CodeMemberEvent;
-				if (eventm != null) 
-				{
+				if (eventm != null) {
 					GenerateEvent (eventm, type);
 					continue;
 				}
 				CodeMemberField field = member as CodeMemberField;
-				if (field != null) 
-				{
+				if (field != null) {
 					GenerateField (field);
 					continue;
 				}
 				CodeEntryPointMethod epmethod = member as CodeEntryPointMethod;
-				if (epmethod != null) 
-				{
+				if (epmethod != null) {
 					GenerateEntryPointMethod (epmethod, type);
 					continue;
 				}
 				CodeTypeConstructor typeCtor = member as CodeTypeConstructor;
-				if (typeCtor != null) 
-				{
+				if (typeCtor != null) {
 					GenerateTypeConstructor (typeCtor);
 					continue;
 				}
 				CodeConstructor ctor = member as CodeConstructor;
-				if (ctor != null) 
-				{
+				if (ctor != null) {
 					GenerateConstructor (ctor, type);
 					continue;
 				}
 				CodeMemberMethod method = member as CodeMemberMethod;
-				if (method != null) 
-				{
+				if (method != null) {
 					GenerateMethod (method, type);
 					continue;
 				}
 				CodeMemberProperty property = member as CodeMemberProperty;
-				if (property != null) 
-				{
+				if (property != null) {
 					GenerateProperty (property, type);
 					continue;
 				}
 				CodeSnippetTypeMember snippet = member as CodeSnippetTypeMember;
-				if (snippet != null) 
-				{
+				if (snippet != null) {
 					GenerateSnippetMember (snippet);
 					continue;
 				}
-				
+
 				this.currentMember = prevMember;
 			}
 
@@ -1190,8 +1147,17 @@ namespace System.CodeDom.Compiler {
 					GenerateDirectives (currentMember.EndDirectives);
 #endif
 			}
+
 			this.currentType = type;
 			GenerateTypeEnd (type);
+
+			if (type.LinePragma != null)
+				GenerateLinePragmaEnd (type.LinePragma);
+
+#if NET_2_0
+			if (type.EndDirectives.Count > 0)
+				GenerateDirectives (type.EndDirectives);
+#endif
 		}
 
 		protected abstract string GetTypeOutput (CodeTypeReference type);

+ 6 - 0
mcs/class/System/System.CodeDom/ChangeLog

@@ -1,3 +1,9 @@
+2005-07-24 Gert Driesen <[email protected]>
+
+	* CodeTypeReference.cs: Added internal IsInterface property.
+	* CodeTypeDelegate.cs: System.Delegate is base type, and make sure 
+	ReturnType is initialized.
+
 2005-06-28 Gert Driesen <[email protected]>
 
 	* CodeTypeReference.cs: Also consider null type name as void, throw

+ 10 - 6
mcs/class/System/System.CodeDom/CodeTypeDelegate.cs

@@ -35,10 +35,9 @@ namespace System.CodeDom
 	[Serializable]
 	[ClassInterface(ClassInterfaceType.AutoDispatch)]
 	[ComVisible(true)]
-	public class CodeTypeDelegate
-		: CodeTypeDeclaration
+	public class CodeTypeDelegate : CodeTypeDeclaration
 	{
-		private	CodeParameterDeclarationExpressionCollection parameters;
+		private CodeParameterDeclarationExpressionCollection parameters;
 		private CodeTypeReference returnType;
 
 		//
@@ -46,9 +45,10 @@ namespace System.CodeDom
 		//
 		public CodeTypeDelegate()
 		{
+			base.BaseTypes.Add (new CodeTypeReference ("System.Delegate"));
 		}
 
-		public CodeTypeDelegate( string name )
+		public CodeTypeDelegate(string name) : this()
 		{
 			this.Name = name;
 		}
@@ -58,14 +58,18 @@ namespace System.CodeDom
 		//
 		public CodeParameterDeclarationExpressionCollection Parameters {
 			get {
-				if ( parameters == null )
-					parameters = new CodeParameterDeclarationExpressionCollection();
+				if (parameters == null) {
+					parameters = new CodeParameterDeclarationExpressionCollection ();
+				}
 				return parameters;
 			}
 		}
 
 		public CodeTypeReference ReturnType {
 			get {
+				if (returnType == null) {
+					this.returnType = new CodeTypeReference(string.Empty);
+				}
 				return returnType;
 			}
 			set {

+ 15 - 9
mcs/class/System/System.CodeDom/CodeTypeReference.cs

@@ -41,7 +41,8 @@ namespace System.CodeDom
 	{
 		private string baseType;
 		private CodeTypeReference arrayType;
-		private int rank;
+		private int rank;
+		private bool isInterface;
 
 #if NET_2_0
 		CodeTypeReferenceCollection typeArguments;
@@ -83,14 +84,15 @@ namespace System.CodeDom
 			if (baseType == null) {
 				throw new ArgumentNullException ("baseType");
 			}
-#endif
-			if (baseType.IsArray) {
-				this.rank = baseType.GetArrayRank ();
-				this.arrayType = new CodeTypeReference (baseType.GetElementType ());
-				this.baseType = arrayType.BaseType;
-				return;
-			}
-			this.baseType = baseType.FullName;
+#endif
+			if (baseType.IsArray) {
+				this.rank = baseType.GetArrayRank ();
+				this.arrayType = new CodeTypeReference (baseType.GetElementType ());
+				this.baseType = arrayType.BaseType;
+			} else {
+				this.baseType = baseType.FullName;
+			}
+			this.isInterface = baseType.IsInterface;
 		}
 
 		public CodeTypeReference( CodeTypeReference arrayType, int rank )
@@ -163,6 +165,10 @@ namespace System.CodeDom
 			set {
 				baseType = value;
 			}
+		}
+
+		internal bool IsInterface {
+			get { return isInterface; }
 		}
 
 #if NET_2_0

+ 1 - 0
mcs/class/System/System_test.dll.sources

@@ -16,6 +16,7 @@ System/UriTest.cs
 System/UriTest2.cs
 System.CodeDom/CodeMemberFieldTest.cs
 System.CodeDom/CodeMemberPropertyTest.cs
+System.CodeDom/CodeTypeDelegateTest.cs
 System.CodeDom/CodeTypeReferenceTest.cs
 System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs
 System.CodeDom.Compiler/CodeGeneratorTest.cs

+ 5 - 0
mcs/class/System/Test/Microsoft.CSharp/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-24  Gert Driesen <[email protected]>
+
+	* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
+	tests. Added enum, interface and delegate tests.
+
 2005-07-02  Gert Driesen <[email protected]>
 
 	* CodeGeneratorFromTypeTest.cs: Added test for 

File diff suppressed because it is too large
+ 359 - 725
mcs/class/System/Test/Microsoft.CSharp/CodeGeneratorFromTypeTest.cs


+ 5 - 0
mcs/class/System/Test/Microsoft.VisualBasic/ChangeLog

@@ -1,3 +1,8 @@
+2005-07-24  Gert Driesen <[email protected]>
+
+	* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
+	tests. Enabled enum, interface and delegate tests.
+
 2005-07-21  Gert Driesen <[email protected]>
 
 	* CodeGeneratorFromTypeTest.cs: Inherit from

+ 133 - 8
mcs/class/System/Test/Microsoft.VisualBasic/CodeGeneratorFromTypeTest.cs

@@ -71,6 +71,21 @@ namespace MonoTests.Microsoft.VisualBasic
 				"End Class{0}", Writer.NewLine), code);
 		}
 
+		[Test]
+		public override void DerivedTypeTest ()
+		{
+			string code = GenerateDerivedType ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+#if NET_2_0
+				"Friend MustInherit Class Test1{0}" +
+#else
+				"MustInherit Class Test1{0}" +
+#endif
+				"    Inherits Integer{0}" +
+				"    Implements System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
+				"End Class{0}", Writer.NewLine), code);
+		}
+
 		[Test]
 		public override void AttributesAndTypeTest ()
 		{
@@ -179,7 +194,7 @@ namespace MonoTests.Microsoft.VisualBasic
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"Public Class Test1{0}" +
 				"    {0}" +
-				"    Public Name As Integer{0}" +
+				"    Public Name As Integer = 2{0}" +
 				"End Class{0}", Writer.NewLine), code);
 		}
 
@@ -767,10 +782,25 @@ namespace MonoTests.Microsoft.VisualBasic
 				"    End Sub{0}" +
 				"End Class{0}", Writer.NewLine), code);
 		}
+
+		[Test]
+		public override void TypeConstructorTest ()
+		{
+			string code = GenerateTypeConstructor ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Public Class Test1{0}" +
+				"    {0}" +
+#if NET_2_0
+				"    <A(),  _{0}" +
+				"     B()>  _{0}" +
+#endif
+				"    Shared Sub New(){0}" +
+				"    End Sub{0}" +
+				"End Class{0}", Writer.NewLine), code);
+		}
 	}
 
 	[TestFixture]
-	[Category ("NotWorking")]
 	public class CodeGeneratorFromTypeTest_Delegate : CodeGeneratorFromTypeTestBase
 	{
 		private CodeTypeDeclaration _typeDeclaration;
@@ -819,14 +849,27 @@ namespace MonoTests.Microsoft.VisualBasic
 				"Public Delegate Sub Test1(){0}", Writer.NewLine), code);
 		}
 
+		[Test]
+		public override void DerivedTypeTest ()
+		{
+			string code = GenerateDerivedType ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Delegate Sub Test1(){0}", Writer.NewLine), code);
+		}
+
 		[Test]
 		public override void AttributesAndTypeTest ()
 		{
+			CodeTypeDelegate delegateDecl = new CodeTypeDelegate ();
+			delegateDecl.ReturnType = new CodeTypeReference (typeof (int));
+
+			_typeDeclaration = delegateDecl;
+
 			string code = GenerateAttributesAndType ();
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"<A(),  _{0}" +
 				" B()>  _{0}" +
-				"Public Delegate Sub Test1(){0}", Writer.NewLine), code);
+				"Public Delegate Function Test1() As Integer{0}", Writer.NewLine), code);
 		}
 
 		[Test]
@@ -1182,10 +1225,17 @@ namespace MonoTests.Microsoft.VisualBasic
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"Public Delegate Sub Test1(){0}{0}", Writer.NewLine), code);
 		}
+
+		[Test]
+		public override void TypeConstructorTest ()
+		{
+			string code = GenerateTypeConstructor ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Public Delegate Sub Test1(){0}{0}", Writer.NewLine), code);
+		}
 	}
 
 	[TestFixture]
-	[Category ("NotWorking")]
 	public class CodeGeneratorFromTypeTest_Interface : CodeGeneratorFromTypeTestBase
 	{
 		private CodeTypeDeclaration _typeDeclaration;
@@ -1237,6 +1287,20 @@ namespace MonoTests.Microsoft.VisualBasic
 				"End Interface{0}", Writer.NewLine), code);
 		}
 
+		[Test]
+		public override void DerivedTypeTest ()
+		{
+			string code = GenerateDerivedType ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+#if NET_2_0
+				"Friend Interface Test1{0}" +
+#else
+				"Interface Test1{0}" +
+#endif
+				"    Inherits Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
+				"End Interface{0}", Writer.NewLine), code);
+		}
+
 		[Test]
 		public override void AttributesAndTypeTest ()
 		{
@@ -1786,10 +1850,19 @@ namespace MonoTests.Microsoft.VisualBasic
 				"    {0}" +
 				"End Interface{0}", Writer.NewLine), code);
 		}
+
+		[Test]
+		public override void TypeConstructorTest ()
+		{
+			string code = GenerateTypeConstructor ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Public Interface Test1{0}" +
+				"    {0}" +
+				"End Interface{0}", Writer.NewLine), code);
+		}
 	}
 
 	[TestFixture]
-	[Category ("NotWorking")]
 	public class CodeGeneratorFromTypeTest_Struct : CodeGeneratorFromTypeTestBase
 	{
 		private CodeTypeDeclaration _typeDeclaration;
@@ -1841,6 +1914,20 @@ namespace MonoTests.Microsoft.VisualBasic
 				"End Structure{0}", Writer.NewLine), code);
 		}
 
+		[Test]
+		public override void DerivedTypeTest ()
+		{
+			string code = GenerateDerivedType ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+#if NET_2_0
+				"Friend Structure Test1{0}" +
+#else
+				"Structure Test1{0}" +
+#endif
+				"    Implements Integer, System.Security.Principal.IIdentity, String, System.Security.IPermission{0}" +
+				"End Structure{0}", Writer.NewLine), code);
+		}
+
 		[Test]
 		public override void AttributesAndTypeTest ()
 		{
@@ -1941,7 +2028,7 @@ namespace MonoTests.Microsoft.VisualBasic
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"Public Structure Test1{0}" +
 				"    {0}" +
-				"    Public Name As Integer{0}" +
+				"    Public Name As Integer = 2{0}" +
 				"End Structure{0}", Writer.NewLine), code);
 		}
 
@@ -2476,10 +2563,25 @@ namespace MonoTests.Microsoft.VisualBasic
 				"    End Sub{0}" +
 				"End Structure{0}", Writer.NewLine), code);
 		}
+
+		[Test]
+		public override void TypeConstructorTest ()
+		{
+			string code = GenerateTypeConstructor ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Public Structure Test1{0}" +
+				"    {0}" +
+#if NET_2_0
+				"    <A(),  _{0}" +
+				"     B()>  _{0}" +
+#endif
+				"    Shared Sub New(){0}" +
+				"    End Sub{0}" +
+				"End Structure{0}", Writer.NewLine), code);
+		}
 	}
 
 	[TestFixture]
-	[Category ("NotWorking")]
 	public class CodeGeneratorFromTypeTest_Enum : CodeGeneratorFromTypeTestBase
 	{
 		private CodeTypeDeclaration _typeDeclaration;
@@ -2531,6 +2633,19 @@ namespace MonoTests.Microsoft.VisualBasic
 				"End Enum{0}", Writer.NewLine), code);
 		}
 
+		[Test]
+		public override void DerivedTypeTest ()
+		{
+			string code = GenerateDerivedType ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+#if NET_2_0
+				"Friend Enum Test1 As Integer{0}" +
+#else
+				"Enum Test1 As Integer{0}" +
+#endif
+				"End Enum{0}", Writer.NewLine), code);
+		}
+
 		[Test]
 		public override void AttributesAndTypeTest ()
 		{
@@ -2612,7 +2727,7 @@ namespace MonoTests.Microsoft.VisualBasic
 			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
 				"Public Enum Test1{0}" +
 				"    {0}" +
-				"    Name{0}" +
+				"    Name = 2{0}" +
 				"End Enum{0}", Writer.NewLine), code);
 		}
 
@@ -2979,5 +3094,15 @@ namespace MonoTests.Microsoft.VisualBasic
 				"    {0}" +
 				"End Enum{0}", Writer.NewLine), code);
 		}
+
+		[Test]
+		public override void TypeConstructorTest ()
+		{
+			string code = GenerateTypeConstructor ();
+			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+				"Public Enum Test1{0}" +
+				"    {0}" +
+				"End Enum{0}", Writer.NewLine), code);
+		}
 	}
 }

+ 7 - 0
mcs/class/System/Test/System.CodeDom.Compiler/ChangeLog

@@ -1,3 +1,10 @@
+2005-07-24  Gert Driesen <[email protected]>
+
+	* CodeGeneratorTest.cs: Removed duplicate import of NUNit.Framework
+	namespace.
+	* CodeGeneratorFromTypeTestBase.cs: Added BaseTypes and 
+	TypeConstructor tests.
+
 2005-07-21  Gert Driesen <[email protected]>
 
 	* CodeGeneratorTest.cs: Added unit tests for CodeGenerator.IsCurrent*.

+ 65 - 1
mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorFromTypeTestBase.cs

@@ -8,6 +8,9 @@
 //
 
 using System.CodeDom;
+using System.Reflection;
+using System.Security;
+using System.Security.Principal;
 
 using NUnit.Framework;
 
@@ -29,6 +32,9 @@ namespace MonoTests.System.CodeDom.Compiler
 		[Test]
 		public abstract void SimpleTypeTest ();
 
+		[Test]
+		public abstract void DerivedTypeTest ();
+
 		[Test]
 		public abstract void AttributesAndTypeTest ();
 
@@ -158,6 +164,9 @@ namespace MonoTests.System.CodeDom.Compiler
 		[Test]
 		public abstract void ChainedConstructorMultipleArgs ();
 
+		[Test]
+		public abstract void TypeConstructorTest ();
+
 		protected string GenerateDefaultType ()
 		{
 			return GenerateCodeFromType (TypeDeclaration);
@@ -174,6 +183,18 @@ namespace MonoTests.System.CodeDom.Compiler
 			return GenerateCodeFromType (TypeDeclaration);
 		}
 
+		protected string GenerateDerivedType ()
+		{
+			TypeDeclaration.Name = "Test1";
+			TypeDeclaration.TypeAttributes |= TypeAttributes.NestedFamily | 
+				TypeAttributes.Abstract;
+			TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (int)));
+			TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (IIdentity)));
+			TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (string)));
+			TypeDeclaration.BaseTypes.Add (new CodeTypeReference (typeof (IPermission)));
+			return GenerateCodeFromType (TypeDeclaration);
+		}
+
 		protected string GenerateAttributesAndType ()
 		{
 			TypeDeclaration.Name = "Test1";
@@ -294,6 +315,7 @@ namespace MonoTests.System.CodeDom.Compiler
 			fld.Name = "Name";
 			fld.Attributes = MemberAttributes.Public;
 			fld.Type = new CodeTypeReference (typeof (int));
+			fld.InitExpression = new CodePrimitiveExpression (2);
 			TypeDeclaration.Members.Add (fld);
 
 			return GenerateCodeFromType (TypeDeclaration);
@@ -865,7 +887,7 @@ namespace MonoTests.System.CodeDom.Compiler
 			param.Direction = FieldDirection.Out;
 			ctor.Parameters.Add (param);
 
-			// immplementation types should be ignored on ctors
+			// implementation types should be ignored on ctors
 			ctor.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
 
 			// chained ctor args
@@ -883,5 +905,47 @@ namespace MonoTests.System.CodeDom.Compiler
 
 			return GenerateCodeFromType (TypeDeclaration);
 		}
+
+		protected string GenerateTypeConstructor ()
+		{
+			TypeDeclaration.Name = "Test1";
+
+			CodeTypeConstructor typeCtor = new CodeTypeConstructor ();
+			TypeDeclaration.Members.Add (typeCtor);
+
+			// custom attributes
+			CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
+			attrDec.Name = "A";
+			typeCtor.CustomAttributes.Add (attrDec);
+
+			attrDec = new CodeAttributeDeclaration ();
+			attrDec.Name = "B";
+			typeCtor.CustomAttributes.Add (attrDec);
+
+			// parameter should be ignored
+			CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
+				typeof (object), "value1");
+			typeCtor.Parameters.Add (param);
+
+			// implementation types should be ignored on type ctors
+			typeCtor.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));
+
+			// private immplementation type should be ignored on type ctors
+			typeCtor.PrivateImplementationType = new CodeTypeReference (typeof (int));
+
+			// return type should be ignored on type ctors
+			typeCtor.ReturnType = new CodeTypeReference (typeof (int));
+
+			// return TypeDeclaration custom attributes
+			attrDec = new CodeAttributeDeclaration ();
+			attrDec.Name = "A";
+			attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
+				new CodePrimitiveExpression (false)));
+			attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
+				new CodePrimitiveExpression (true)));
+			typeCtor.ReturnTypeCustomAttributes.Add (attrDec);
+
+			return GenerateCodeFromType (TypeDeclaration);
+		}
 	}
 }

+ 0 - 2
mcs/class/System/Test/System.CodeDom.Compiler/CodeGeneratorTest.cs

@@ -7,8 +7,6 @@
 // (c) Novell
 //
 
-using NUnit.Framework;
-
 using System;
 using System.CodeDom;
 using System.CodeDom.Compiler;

+ 4 - 0
mcs/class/System/Test/System.CodeDom/ChangeLog

@@ -1,3 +1,7 @@
+2005-07-24  Gert Driesen  <[email protected]>
+
+	* CodeTypeDelegateTest.cs: Added tests for BaseTypes and ReturnType.
+
 2005-06-28  Gert Driesen  <[email protected]>
 
 	* CodeTypeReferenceTest.cs: Tests for zero-length and null type names,

+ 48 - 0
mcs/class/System/Test/System.CodeDom/CodeTypeDelegateTest.cs

@@ -0,0 +1,48 @@
+//
+// CodeTypeReferenceTest.cs - NUnit Test Cases for System.CodeDom.CodeTypeReference
+//
+// Authors:
+//   Gert Driesen ([email protected])
+//
+// (C) 2005 Novell
+//
+using System;
+using System.CodeDom;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.CodeDom
+{
+	[TestFixture]
+	public class CodeTypeDelegateTest
+	{
+		[Test]
+		public void EmptyTypeName ()
+		{
+			CodeTypeDelegate delegateType = new CodeTypeDelegate (string.Empty);
+			Assert.AreEqual (string.Empty, delegateType.Name);
+		}
+
+		[Test]
+		public void NullTypeName ()
+		{
+			CodeTypeDelegate delegateType = new CodeTypeDelegate ((string) null);
+			Assert.AreEqual (string.Empty, delegateType.Name);
+		}
+
+		[Test]
+		public void BaseTypes ()
+		{
+			CodeTypeDelegate delegateType = new CodeTypeDelegate ((string) null);
+			Assert.AreEqual (1, delegateType.BaseTypes.Count);
+			Assert.AreEqual ("System.Delegate", delegateType.BaseTypes[0].BaseType);
+		}
+
+		[Test]
+		public void DefaultReturnType ()
+		{
+			CodeTypeDelegate delegateType = new CodeTypeDelegate ((string) null);
+			Assert.AreEqual (typeof(void).FullName, delegateType.ReturnType.BaseType);
+		}
+	}
+}

Some files were not shown because too many files changed in this diff