2 // Microsoft.VisualBasic.VBCodeGenerator.cs
5 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
6 // (partially based on CSharpCodeGenerator)
8 // (C) 2003 Andreas Nahr
13 using System.Text.RegularExpressions;
15 using System.CodeDom.Compiler;
17 using System.Reflection;
18 using System.Collections;
20 namespace Microsoft.VisualBasic
22 internal class VBCodeGenerator : CodeGenerator
24 private string[] Keywords = new string[] {
25 "AddHandler", "AddressOf", "Alias", "And",
26 "AndAlso", "Ansi", "As", "Assembly",
27 "Auto", "Boolean", "ByRef", "Byte",
28 "ByVal", "Call", "Case", "Catch",
29 "CBool", "CByte", "CChar", "CDate",
30 "CDec", "CDbl", "Char", "CInt",
31 "Class", "CLng", "CObj", "Const",
32 "CShort", "CSng", "CStr", "CType",
33 "Date", "Decimal", "Declare", "Default",
34 "Delegate", "Dim", "DirectCast", "Do",
35 "Double", "Each", "Else", "ElseIf",
36 "End", "Enum", "Erase", "Error",
37 "Event", "Exit", "False", "Finally",
38 "For", "Friend", "Function", "Get",
39 "GetType", "GoSub", "GoTo", "Handles",
40 "If", "Implements", "Imports", "In",
41 "Inherits", "Integer", "Interface", "Is",
42 "Let", "Lib", "Like", "Long",
43 "Loop", "Me", "Mod", "Module",
44 "MustInherit", "MustOverride", "MyBase", "MyClass",
45 "Namespace", "New", "Next", "Not",
46 "Nothing", "NotInheritable", "NotOverridable", "Object",
47 "On", "Option", "Optional", "Or",
48 "OrElse", "Overloads", "Overridable", "Overrides",
49 "ParamArray", "Preserve", "Private", "Property",
50 "Protected", "Public", "RaiseEvent", "ReadOnly",
51 "ReDim", "REM", "RemoveHandler", "Resume",
52 "Return", "Select", "Set", "Shadows",
53 "Shared", "Short", "Single", "Static",
54 "Step", "Stop", "String", "Structure",
55 "Sub", "SyncLock", "Then", "Throw",
56 "To", "True", "Try", "TypeOf",
57 "Unicode", "Until", "Variant", "When",
58 "While", "With", "WithEvents", "WriteOnly",
62 public VBCodeGenerator()
66 protected override string NullToken {
72 protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression expression)
74 TextWriter output = Output;
76 output.Write ("New ");
78 CodeExpressionCollection initializers = expression.Initializers;
79 CodeTypeReference createType = expression.CreateType;
81 if (initializers.Count > 0) {
83 OutputType (createType);
85 output.WriteLine (" {");
87 OutputExpressionList (initializers, true);
93 CodeTypeReference arrayType = createType.ArrayElementType;
94 while (arrayType != null)
96 createType = arrayType;
97 arrayType = arrayType.ArrayElementType;
100 OutputType (createType);
104 CodeExpression size = expression.SizeExpression;
106 GenerateExpression (size);
108 output.Write (expression.Size);
114 protected override void GenerateBaseReferenceExpression (CodeBaseReferenceExpression expression)
116 Output.Write ("MyBase");
119 protected override void GenerateCastExpression (CodeCastExpression expression)
121 TextWriter output = Output;
122 // ENHANCE: Use a DirectCast if it is known that expression.Expression is no Value-Type
123 output.Write ("CType(");
124 GenerateExpression (expression.Expression);
126 OutputType (expression.TargetType);
130 protected override void GenerateCompileUnitStart (CodeCompileUnit compileUnit)
132 GenerateComment (new CodeComment ("------------------------------------------------------------------------------"));
133 GenerateComment (new CodeComment (" <autogenerated>"));
134 GenerateComment (new CodeComment (" This code was generated by a tool."));
135 GenerateComment (new CodeComment (" Mono Runtime Version: " + System.Environment.Version));
136 GenerateComment (new CodeComment (""));
137 GenerateComment (new CodeComment (" Changes to this file may cause incorrect behavior and will be lost if "));
138 GenerateComment (new CodeComment (" the code is regenerated."));
139 GenerateComment (new CodeComment (" </autogenerated>"));
140 GenerateComment (new CodeComment ("------------------------------------------------------------------------------"));
144 protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression expression)
146 TextWriter output = Output;
148 output.Write ("AddressOf ");
150 CodeExpression targetObject = expression.TargetObject;
151 if (targetObject != null) {
152 GenerateExpression (targetObject);
155 output.Write (expression.MethodName);
158 protected override void GenerateFieldReferenceExpression (CodeFieldReferenceExpression expression)
160 CodeExpression targetObject = expression.TargetObject;
161 if (targetObject != null) {
162 GenerateExpression (targetObject);
165 Output.Write (expression.FieldName);
168 protected override void GenerateArgumentReferenceExpression (CodeArgumentReferenceExpression expression)
170 Output.Write (expression.ParameterName);
173 protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression expression)
175 Output.Write (expression.VariableName);
178 protected override void GenerateIndexerExpression (CodeIndexerExpression expression)
180 TextWriter output = Output;
182 GenerateExpression (expression.TargetObject);
184 OutputExpressionList (expression.Indices);
188 protected override void GenerateArrayIndexerExpression (CodeArrayIndexerExpression expression)
190 TextWriter output = Output;
192 GenerateExpression (expression.TargetObject);
193 output.Write (".Item(");
194 OutputExpressionList (expression.Indices);
198 protected override void GenerateSnippetExpression (CodeSnippetExpression expression)
200 Output.Write (expression.Value);
203 protected override void GenerateMethodInvokeExpression (CodeMethodInvokeExpression expression)
205 TextWriter output = Output;
207 GenerateMethodReferenceExpression (expression.Method);
210 OutputExpressionList (expression.Parameters);
214 protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression expression)
216 GenerateExpression (expression.TargetObject);
218 Output.Write (expression.MethodName);
221 protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression expression)
223 GenerateExpression (expression.TargetObject);
225 Output.Write (expression.EventName);
228 protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression expression)
230 Output.Write ("RaiseEvent ");
231 GenerateExpression (expression.TargetObject);
233 OutputExpressionList (expression.Parameters);
234 Output.WriteLine (')');
237 protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression expression)
239 Output.Write( "New " );
240 OutputType (expression.CreateType);
242 OutputExpressionList (expression.Parameters);
246 protected override void GenerateParameterDeclarationExpression (CodeParameterDeclarationExpression e)
248 if (e.CustomAttributes != null && e.CustomAttributes.Count > 0)
249 OutputAttributeDeclarations (e.CustomAttributes);
250 OutputDirection (e.Direction);
251 OutputTypeNamePair (e.Type, e.Name);
254 protected override void GeneratePrimitiveExpression (CodePrimitiveExpression e)
256 TextWriter output = Output;
258 if (e.Value == null) {
259 output.Write (NullToken);
263 Type type = e.Value.GetType ();
264 if (type == typeof (bool)) {
266 output.Write ("True");
268 output.Write ("False");
270 else if (type == typeof (char)) {
271 output.Write ("\"" + e.Value.ToString () + "\"c");
273 else if (type == typeof (string)) {
274 output.Write (QuoteSnippetString ((string) e.Value));
276 else if (type == typeof (byte) || type == typeof (sbyte) || type == typeof (short) ||
277 type == typeof (int) || type == typeof (long) || type == typeof (float) ||
278 type == typeof (double) || type == typeof (decimal)) {
279 output.Write (e.Value.ToString ());
282 throw new ArgumentException ("Value type (" + type + ") is not a primitive type");
286 protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression expression)
288 GenerateMemberReferenceExpression (expression.TargetObject, expression.PropertyName);
291 protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression expression)
293 Output.Write ("Value");
296 protected override void GenerateThisReferenceExpression (CodeThisReferenceExpression expression)
301 protected override void GenerateExpressionStatement (CodeExpressionStatement statement)
303 GenerateExpression (statement.Expression);
304 Output.WriteLine (); //start new line
307 protected override void GenerateIterationStatement (CodeIterationStatement statement)
309 TextWriter output = Output;
311 GenerateStatement (statement.InitStatement);
312 output.Write ("Do While ");
313 GenerateExpression (statement.TestExpression);
315 GenerateStatements (statement.Statements);
316 GenerateStatement (statement.IncrementStatement);
317 output.WriteLine ("Loop");
320 protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement statement)
322 Output.Write ("Throw ");
323 GenerateExpression (statement.ToThrow);
326 protected override void GenerateComment (CodeComment comment)
328 TextWriter output = Output;
330 if (comment.DocComment)
331 output.Write ("''' ");
335 output.WriteLine (comment.Text);
338 protected override void GenerateMethodReturnStatement (CodeMethodReturnStatement statement)
340 TextWriter output = Output;
342 output.Write ("Return ");
343 GenerateExpression (statement.Expression);
347 protected override void GenerateConditionStatement (CodeConditionStatement statement)
349 TextWriter output = Output;
350 output.Write ("If (");
352 GenerateExpression (statement.Condition);
354 output.WriteLine (") Then");
356 GenerateStatements (statement.TrueStatements);
359 CodeStatementCollection falses = statement.FalseStatements;
360 if (falses.Count > 0) {
361 output.WriteLine ("Else");
363 GenerateStatements (falses);
367 if (Options.ElseOnClosing)
368 output.WriteLine ("Else");
370 output.WriteLine ("End If");
373 protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement statement)
375 TextWriter output = Output;
376 CodeGeneratorOptions options = Options;
378 output.WriteLine ("Try");
380 GenerateStatements (statement.TryStatements);
384 foreach (CodeCatchClause clause in statement.CatchClauses) {
385 output.Write ("Catch ");
386 OutputTypeNamePair (clause.CatchExceptionType, clause.LocalName);
389 GenerateStatements (clause.Statements);
394 CodeStatementCollection finallies = statement.FinallyStatements;
395 if (finallies.Count > 0) {
397 output.WriteLine ("Finally");
399 GenerateStatements (finallies);
404 if (Options.ElseOnClosing) {
405 if (statement.CatchClauses.Count == 0)
406 output.WriteLine ("Catch");
407 if (statement.FinallyStatements.Count == 0)
408 output.WriteLine ("Finally");
411 output.WriteLine("End Try");
414 protected override void GenerateAssignStatement (CodeAssignStatement statement)
416 TextWriter output = Output;
417 GenerateExpression (statement.Left);
418 output.Write (" = ");
419 GenerateExpression (statement.Right);
423 protected override void GenerateAttachEventStatement (CodeAttachEventStatement statement)
425 TextWriter output = Output;
427 Output.Write ("AddHandler ");
428 GenerateEventReferenceExpression (statement.Event);
429 Output.Write ( ", ");
430 GenerateExpression (statement.Listener);
434 protected override void GenerateRemoveEventStatement (CodeRemoveEventStatement statement)
436 TextWriter output = Output;
438 Output.Write ("RemoveHandler ");
439 GenerateEventReferenceExpression (statement.Event);
440 Output.Write ( ", ");
441 GenerateExpression (statement.Listener);
445 protected override void GenerateGotoStatement (CodeGotoStatement statement)
447 TextWriter output = Output;
449 output.Write ("Goto ");
450 output.Write (statement.Label);
454 protected override void GenerateLabeledStatement (CodeLabeledStatement statement)
456 TextWriter output = Output;
458 output.Write (statement.Label + ":");
459 GenerateStatement (statement.Statement);
462 protected override void GenerateTypeOfExpression (CodeTypeOfExpression e)
464 TextWriter output = Output;
466 output.Write ("GetType(");
471 protected override void GenerateVariableDeclarationStatement( CodeVariableDeclarationStatement statement )
473 TextWriter output = Output;
475 output.Write ("Dim ");
476 OutputTypeNamePair (statement.Type, statement.Name);
478 CodeExpression initExpression = statement.InitExpression;
479 if (initExpression != null)
481 output.Write (" = ");
482 GenerateExpression (initExpression);
488 protected override void GenerateLinePragmaStart (CodeLinePragma linePragma)
491 Output.Write ("#ExternalSource(");
492 Output.Write (linePragma.FileName);
494 Output.Write (linePragma.LineNumber);
495 Output.WriteLine (")");
498 protected override void GenerateLinePragmaEnd (CodeLinePragma linePragma)
500 Output.WriteLine ("#End ExternalSource");
503 protected override void GenerateEvent (CodeMemberEvent eventRef, CodeTypeDeclaration declaration)
505 TextWriter output = Output;
507 if (eventRef.CustomAttributes.Count > 0)
508 OutputAttributeDeclarations (eventRef.CustomAttributes);
510 MemberAttributes attributes = eventRef.Attributes;
512 OutputMemberAccessModifier (attributes);
513 OutputMemberScopeModifier (attributes);
515 output.Write ("Event ");
516 OutputTypeNamePair (eventRef.Type, eventRef.Name);
520 protected override void GenerateField (CodeMemberField field)
522 TextWriter output = Output;
524 if (field.CustomAttributes.Count > 0)
525 OutputAttributeDeclarations (field.CustomAttributes);
527 MemberAttributes attributes = field.Attributes;
528 OutputMemberAccessModifier (attributes);
529 OutputFieldScopeModifier (attributes);
531 OutputTypeNamePair (field.Type, field.Name);
533 CodeExpression initExpression = field.InitExpression;
534 if (initExpression != null) {
535 output.Write (" = ");
536 GenerateExpression (initExpression);
542 protected override void GenerateSnippetMember (CodeSnippetTypeMember member)
544 Output.Write (member.Text);
547 protected override void GenerateEntryPointMethod( CodeEntryPointMethod method, CodeTypeDeclaration declaration )
549 method.Name = "Main";
550 GenerateMethod (method, declaration);
553 [MonoTODO ("partially implemented")]
554 protected override void GenerateMethod (CodeMemberMethod method, CodeTypeDeclaration declaration)
556 bool isSub = method.ReturnType == null || method.ReturnType.ToString() == "System.Void";
558 TextWriter output = Output;
560 if (method.CustomAttributes.Count > 0)
561 OutputAttributeDeclarations (method.CustomAttributes);
563 MemberAttributes attributes = method.Attributes;
565 OutputMemberAccessModifier (attributes);
566 OutputMemberScopeModifier (attributes);
569 output.Write ("Sub ");
571 output.Write ("Function ");
573 output.Write (method.Name);
575 OutputParameters (method.Parameters);
579 output.Write (" As ");
580 OutputType (method.ReturnType);
583 if (method.ImplementationTypes.Count > 0) {
584 output.Write (" Implements ");
585 foreach (CodeTypeReference type in method.ImplementationTypes)
589 // TODO implementation incomplete
594 // TODO private implementations
596 if ((attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract)
601 GenerateStatements (method.Statements);
604 output.WriteLine ("End Sub");
606 output.WriteLine ("End Function");
610 protected override void GenerateProperty (CodeMemberProperty property, CodeTypeDeclaration declaration)
612 TextWriter output = Output;
614 if (property.CustomAttributes.Count > 0)
615 OutputAttributeDeclarations (property.CustomAttributes);
617 MemberAttributes attributes = property.Attributes;
618 OutputMemberAccessModifier (attributes);
619 OutputMemberScopeModifier (attributes);
621 if (property.HasGet && (property.HasSet = false))
622 output.Write ("ReadOnly" );
624 if (property.HasSet && (property.HasGet = false))
625 output.Write ("WriteOnly" );
627 output.Write ("Property" );
629 OutputTypeNamePair (property.Type, property.Name);
633 if (property.HasGet) {
634 output.WriteLine ("Get");
637 GenerateStatements (property.GetStatements);
640 output.WriteLine ("End Get");
643 if (property.HasSet) {
644 output.WriteLine ("Set");
647 GenerateStatements (property.SetStatements);
650 output.WriteLine ("End Set");
654 output.WriteLine ("End Property");
657 [MonoTODO ("not implemented")]
658 protected override void GenerateConstructor (CodeConstructor constructor, CodeTypeDeclaration declaration)
660 if (constructor.CustomAttributes.Count > 0)
661 OutputAttributeDeclarations (constructor.CustomAttributes);
662 OutputMemberAccessModifier (constructor.Attributes);
663 Output.Write ("Sub New(");
664 OutputParameters (constructor.Parameters);
665 Output.WriteLine (")");
666 // Handle BaseConstructorArgs, ChainedConstructorArgs, ImplementationTypes
668 GenerateStatements (constructor.Statements);
670 Output.WriteLine ("End Sub");
673 protected override void GenerateTypeConstructor (CodeTypeConstructor constructor)
675 Output.WriteLine ("Shared Sub New()");
677 GenerateStatements (constructor.Statements);
679 Output.WriteLine ("End Sub");
682 [MonoTODO ("not implemented")]
683 protected override void GenerateTypeStart (CodeTypeDeclaration declaration)
685 TextWriter output = Output;
687 if (declaration.CustomAttributes.Count > 0)
688 OutputAttributeDeclarations (declaration.CustomAttributes);
689 TypeAttributes attributes = declaration.TypeAttributes;
690 OutputTypeAttributes (attributes,
691 declaration.IsStruct,
694 output.WriteLine (declaration.Name);
698 IEnumerator enumerator = declaration.BaseTypes.GetEnumerator();
699 if (enumerator.MoveNext())
701 CodeTypeReference type = (CodeTypeReference)enumerator.Current;
705 output.Write ("Inherits ");
710 while (enumerator.MoveNext())
712 type = (CodeTypeReference)enumerator.Current;
716 output.Write ("Implements ");
724 protected override void GenerateTypeEnd (CodeTypeDeclaration declaration)
726 string output = string.Empty;
729 if (declaration.IsStruct)
730 output = "End Structure";
731 if (declaration.IsInterface)
732 output = "End Interface";
733 if (declaration.IsEnum)
735 if (declaration.IsClass)
736 output = "End Class";
738 Output.WriteLine (output);
741 protected override void GenerateNamespaceStart (CodeNamespace ns)
743 TextWriter output = Output;
745 string name = ns.Name;
746 if (name != null && name != string.Empty) {
747 output.Write ("Namespace ");
748 output.WriteLine (name);
753 protected override void GenerateNamespaceEnd (CodeNamespace ns)
755 string name = ns.Name;
756 if (name != null && name != string.Empty) {
758 Output.WriteLine ("End Namespace");
762 protected override void GenerateNamespaceImport (CodeNamespaceImport import)
764 TextWriter output = Output;
766 output.Write ("Imports ");
767 output.Write (import.Namespace);
771 protected override void GenerateAttributeDeclarationsStart (CodeAttributeDeclarationCollection attributes)
776 protected override void GenerateAttributeDeclarationsEnd (CodeAttributeDeclarationCollection attributes)
778 Output.WriteLine ('>');
781 protected override void OutputDirection (FieldDirection direction)
784 case FieldDirection.In:
787 case FieldDirection.Out:
788 Output.Write ("ByVal ");
790 case FieldDirection.Ref:
791 Output.Write ("ByRef ");
796 protected override void OutputFieldScopeModifier (MemberAttributes attributes)
798 if ((attributes & MemberAttributes.VTableMask) == MemberAttributes.New)
799 Output.Write ("New ");
801 switch (attributes & MemberAttributes.ScopeMask) {
802 case MemberAttributes.Static:
803 Output.Write ("Shared ");
805 case MemberAttributes.Const:
806 Output.Write ("Const ");
811 protected override void OutputMemberAccessModifier (MemberAttributes attributes)
813 switch (attributes & MemberAttributes.AccessMask) {
814 case MemberAttributes.Assembly:
815 Output.Write ("Friend ");
817 case MemberAttributes.FamilyAndAssembly:
818 Output.Write ("Friend ");
820 case MemberAttributes.Family:
821 Output.Write ("Protected ");
823 case MemberAttributes.FamilyOrAssembly:
824 Output.Write ("Protected Friend ");
826 case MemberAttributes.Private:
827 Output.Write ("Private ");
829 case MemberAttributes.Public:
830 Output.Write ("Public ");
835 protected override void OutputMemberScopeModifier (MemberAttributes attributes)
837 if ((attributes & MemberAttributes.VTableMask) == MemberAttributes.New)
838 Output.Write ("New ");
840 switch (attributes & MemberAttributes.ScopeMask) {
841 case MemberAttributes.Abstract:
842 Output.Write ("MustOverride ");
844 case MemberAttributes.Final:
845 Output.Write ("NotOverridable ");
847 case MemberAttributes.Static:
848 Output.Write ("Shared ");
850 case MemberAttributes.Override:
851 Output.Write ("Overrides ");
855 // FUNNY! if the scope value is
856 // rubbish (0 or >Const), and access
857 // is public or protected, make it
860 // i'm not sure whether this is 100%
861 // correct, but it seems to be MS
864 MemberAttributes access = attributes & MemberAttributes.AccessMask;
865 if ( access == MemberAttributes.Public ||
866 access == MemberAttributes.Family )
867 Output.Write ("Overridable ");
872 protected override void OutputOperator (CodeBinaryOperatorType op)
875 case CodeBinaryOperatorType.Add:
878 case CodeBinaryOperatorType.Subtract:
881 case CodeBinaryOperatorType.Multiply:
884 case CodeBinaryOperatorType.Divide:
887 case CodeBinaryOperatorType.Modulus:
888 Output.Write ("Mod");
890 case CodeBinaryOperatorType.Assign:
893 case CodeBinaryOperatorType.IdentityInequality:
896 case CodeBinaryOperatorType.IdentityEquality:
899 case CodeBinaryOperatorType.ValueEquality:
902 case CodeBinaryOperatorType.BitwiseOr:
905 case CodeBinaryOperatorType.BitwiseAnd:
906 Output.Write ("And");
908 case CodeBinaryOperatorType.BooleanOr:
909 Output.Write ("OrElse");
911 case CodeBinaryOperatorType.BooleanAnd:
912 Output.Write ("AndAlso");
914 case CodeBinaryOperatorType.LessThan:
917 case CodeBinaryOperatorType.LessThanOrEqual:
920 case CodeBinaryOperatorType.GreaterThan:
923 case CodeBinaryOperatorType.GreaterThanOrEqual:
929 protected override void OutputTypeAttributes (TypeAttributes attributes, bool isStruct, bool isEnum)
931 TextWriter output = Output;
933 switch (attributes & TypeAttributes.VisibilityMask) {
934 case TypeAttributes.NotPublic:
935 // Does this mean friend access?
936 output.Write ("Friend ");
939 case TypeAttributes.Public:
940 case TypeAttributes.NestedPublic:
941 output.Write ("Public ");
944 case TypeAttributes.NestedPrivate:
945 output.Write ("Private ");
947 case TypeAttributes.NestedAssembly:
948 output.Write ("Friend ");
950 case TypeAttributes.NestedFamily:
951 output.Write ("Protected ");
953 case TypeAttributes.NestedFamORAssem:
954 output.Write ("Protected Friend");
956 case TypeAttributes.NestedFamANDAssem:
957 output.Write ("Friend ");
962 output.Write ("Structure ");
965 output.Write ("Enumeration ");
968 if ((attributes & TypeAttributes.Interface) != 0)
969 output.Write ("Interface ");
972 if ((attributes & TypeAttributes.Sealed) != 0)
973 output.Write ("NotInheritable ");
975 if ((attributes & TypeAttributes.Abstract) != 0)
976 output.Write ("MustInherit ");
978 output.Write ("Class ");
983 protected override void OutputTypeNamePair (CodeTypeReference typeRef, String name)
985 Output.Write (name + " As " + GetTypeOutput (typeRef));
988 protected override void OutputType (CodeTypeReference type)
990 Output.Write (GetTypeOutput (type));
993 [MonoTODO ("not implemented")]
994 protected override string QuoteSnippetString (string value)
996 // FIXME: escape ASCII chars that are not code compatible (e.g. vbcrlf)
1000 private void GenerateDeclaration (CodeTypeReference type, string name, CodeExpression initExpression)
1002 TextWriter output = Output;
1004 OutputTypeNamePair (type, name);
1006 if (initExpression != null) {
1007 output.Write (" = ");
1008 GenerateExpression (initExpression);
1011 output.WriteLine ();
1014 private void GenerateMemberReferenceExpression (CodeExpression targetObject, string memberName)
1016 GenerateExpression (targetObject);
1018 Output.Write (memberName);
1025 protected override string CreateEscapedIdentifier (string value)
1027 for (int x = 0; x < Keywords.Length; x++)
1028 if (value.ToLower().Equals (Keywords[x].ToLower()))
1029 return "[" + value + "]";
1033 protected override string CreateValidIdentifier (string value)
1035 for (int x = 0; x < Keywords.Length; x++)
1036 if (value.ToLower().Equals (Keywords[x].ToLower()))
1041 protected override string GetTypeOutput (CodeTypeReference type)
1044 CodeTypeReference arrayType;
1046 arrayType = type.ArrayElementType;
1047 if (arrayType != null)
1048 output = GetTypeOutput (arrayType);
1050 switch (type.BaseType) {
1052 case "System.Decimal":
1055 case "System.Double":
1058 case "System.Single":
1065 case "System.SByte":
1068 case "System.Int32":
1071 case "System.UInt32":
1074 case "System.Int64":
1077 case "System.UInt64":
1080 case "System.Int16":
1083 case "System.UInt16":
1087 case "System.Boolean":
1095 case "System.String":
1098 case "System.Object":
1107 output = type.BaseType;
1112 int rank = type.ArrayRank;
1115 for (--rank; rank > 0; --rank)
1123 protected override bool IsValidIdentifier (string identifier)
1125 for (int x = 0; x < Keywords.Length; x++)
1126 if (identifier.ToLower().Equals (Keywords[x].ToLower()))
1131 protected override bool Supports (GeneratorSupport supports)