Mono.CSharp.CSharpCodeGenerator.GenerateArrayCreateExpression C# (CSharp) Method

GenerateArrayCreateExpression() protected method

protected GenerateArrayCreateExpression ( CodeArrayCreateExpression expression ) : void
expression System.CodeDom.CodeArrayCreateExpression
return void
		protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression expression)
		{
			//
			// This tries to replicate MS behavior as good as
			// possible.
			//
			// The Code-Array stuff in ms.net seems to be broken
			// anyways, or I'm too stupid to understand it.
			//
			// I'm sick of it. If you try to develop array
			// creations, test them on windows. If it works there
			// but not in mono, drop me a note.  I'd be especially
			// interested in jagged-multidimensional combinations
			// with proper initialization :}
			//

			TextWriter output = Output;

			output.Write ("new ");

			CodeExpressionCollection initializers = expression.Initializers;
			CodeTypeReference createType = expression.CreateType;

			if (initializers.Count > 0) {

				OutputType (createType);

				if (expression.CreateType.ArrayRank == 0) {
					output.Write ("[]");
				}

				OutputStartBrace ();
				++Indent;
				OutputExpressionList (initializers, true);
				--Indent;
				output.Write ("}");
			} else {
				CodeTypeReference arrayType = createType.ArrayElementType;
				while (arrayType != null) {
					createType = arrayType;
					arrayType = arrayType.ArrayElementType;
				}

				OutputType (createType);

				output.Write ('[');

				CodeExpression size = expression.SizeExpression;
				if (size != null)
					GenerateExpression (size);
				else
					output.Write (expression.Size);

				output.Write(']');
			}
		}
		
CSharpCodeGenerator