// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
// (partially based on CSharpCodeGenerator)
// Jochen Wezel (jwezel@compumaster.de)
+// Frederik Carlier (frederik.carlier@carlier-online.be)
+// Rolf Bjarne Kvinge (RKvinge@novell.com)
//
// (C) 2003 Andreas Nahr
// (C) 2003 Jochen Wezel (http://www.compumaster.de)
// 2003-11-12 JW: some corrections to allow correct compilation
// 2003-11-28 JW: implementing code differences into current build of this file
// 2003-12-10 JW: added "String." for the ChrW method because mbas doesn't support it without the String currently / TODO: remove it ASAP!
+// 2007-04-13 FC: Added support for the IdentityInequality operator when comparing against Nothing
//
// Permission is hereby granted, free of charge, to any person obtaining
{
internal class VBCodeGenerator : CodeGenerator
{
- private string[] Keywords = new string[] {
+ private string [] Keywords = new string [] {
"AddHandler", "AddressOf", "Alias", "And",
"AndAlso", "Ansi", "As", "Assembly",
"Auto", "Boolean", "ByRef", "Byte",
"End", "Enum", "Erase", "Error",
"Event", "Exit", "False", "Finally",
"For", "Friend", "Function", "Get",
- "GetType", "GoSub", "GoTo", "Handles",
+ "GetType", "Global", "GoSub", "GoTo", "Handles",
"If", "Implements", "Imports", "In",
"Inherits", "Integer", "Interface", "Is",
"Let", "Lib", "Like", "Long",
"Nothing", "NotInheritable", "NotOverridable", "Object",
"On", "Option", "Optional", "Or",
"OrElse", "Overloads", "Overridable", "Overrides",
- "ParamArray", "Preserve", "Private", "Property",
+ "ParamArray", "Partial", "Preserve", "Private", "Property",
"Protected", "Public", "RaiseEvent", "ReadOnly",
"ReDim", "REM", "RemoveHandler", "Resume",
"Return", "Select", "Set", "Shadows",
"While", "With", "WithEvents", "WriteOnly",
"Xor"
};
-
public VBCodeGenerator()
{
}
Output.WriteLine (" _");
}
+ protected override void GenerateBinaryOperatorExpression (CodeBinaryOperatorExpression e)
+ {
+ // We need to special case for comparisons against null;
+ // in Visual Basic the "Not (Expr) Is Nothing" construct is used
+
+ bool null_comparison = false;
+ bool reverse = false;
+ if (e.Operator == CodeBinaryOperatorType.IdentityInequality) {
+ CodePrimitiveExpression nothing;
+ nothing = e.Left as CodePrimitiveExpression;
+ if (nothing == null) {
+ nothing = e.Right as CodePrimitiveExpression;
+ } else {
+ reverse = true;
+ }
+ null_comparison = nothing != null && nothing.Value == null;
+ }
+
+ if (null_comparison) {
+ TextWriter output = Output;
+
+ output.Write ("(Not (");
+ GenerateExpression (reverse ? e.Right : e.Left);
+ output.Write (") Is ");
+ GenerateExpression (reverse ? e.Left : e.Right);
+ output.Write (')');
+ } else {
+ base.GenerateBinaryOperatorExpression (e);
+ }
+ }
+
protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression expression)
{
TextWriter output = Output;
OutputType (createType);
- output.WriteLine (" {");
+ output.Write ("() {");
++Indent;
- OutputExpressionList (initializers, true);
+ OutputExpressionList (initializers);
--Indent;
output.Write ("}");
-
- }
- else {
+ } else {
CodeTypeReference arrayType = createType.ArrayElementType;
- while (arrayType != null)
- {
+ while (arrayType != null) {
createType = arrayType;
arrayType = arrayType.ArrayElementType;
}
OutputType (createType);
- output.Write ('(');
+ output.Write ("((");
CodeExpression size = expression.SizeExpression;
if (size != null)
else
output.Write (expression.Size);
- output.Write (')');
+ output.Write (") - 1) {}");
}
}
output.Write (")");
}
- private bool AsBool(object datavalue)
+ private bool AsBool (object datavalue)
{
- return datavalue != null && datavalue is bool && (bool)datavalue;
+ return datavalue != null && datavalue is bool && (bool) datavalue;
}
- private string OnOff(bool datavalue)
+ private string OnOff (bool datavalue)
{
- return datavalue?"On":"Off";
+ return datavalue ? "On" : "Off";
}
protected override void GenerateCompileUnitStart (CodeCompileUnit compileUnit)
GenerateComment (new CodeComment (" </autogenerated>"));
GenerateComment (new CodeComment ("------------------------------------------------------------------------------"));
Output.WriteLine ();
- if (AsBool(compileUnit.UserData["AllowLateBound"])) {
- Output.WriteLine("Option Explicit {0}",OnOff(AsBool(compileUnit.UserData["RequireVariableDeclaration"])));
+ if (AsBool (compileUnit.UserData ["AllowLateBound"])) {
+ Output.WriteLine("Option Explicit {0}", OnOff (AsBool (compileUnit.UserData ["RequireVariableDeclaration"])));
Output.WriteLine("Option Strict Off");
} else {
Output.WriteLine("Option Explicit On"); // Strict On implies Explicit On
GenerateExpression (targetObject);
Output.Write ('.');
}
- Output.Write (expression.FieldName);
+ Output.Write (CreateEscapedIdentifier (expression.FieldName));
}
protected override void GenerateArgumentReferenceExpression (CodeArgumentReferenceExpression expression)
{
- Output.Write (expression.ParameterName);
+ Output.Write (CreateEscapedIdentifier (expression.ParameterName));
}
protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression expression)
{
- Output.Write (expression.VariableName);
+ Output.Write (CreateEscapedIdentifier (expression.VariableName));
}
protected override void GenerateIndexerExpression (CodeIndexerExpression expression)
TextWriter output = Output;
GenerateExpression (expression.TargetObject);
- output.Write (".Item(");
+ output.Write ("(");
OutputExpressionList (expression.Indices);
output.Write (')');
}
protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression expression)
{
- GenerateExpression (expression.TargetObject);
- Output.Write ('.');
- Output.Write (expression.MethodName);
+ if (expression.TargetObject != null) {
+ GenerateExpression (expression.TargetObject);
+ Output.Write ('.');
+ }
+ Output.Write (CreateEscapedIdentifier (expression.MethodName));
}
protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression expression)
if (expression.TargetObject != null) {
GenerateExpression (expression.TargetObject);
Output.Write ('.');
+ if (expression.TargetObject is CodeThisReferenceExpression) {
+ // We're actually creating a reference to a compiler-generated field here...
+ Output.Write (expression.EventName + "Event");
+ } else {
+ Output.Write (CreateEscapedIdentifier (expression.EventName));
+ }
+ } else {
+ Output.Write (CreateEscapedIdentifier (expression.EventName + "Event"));
}
- Output.Write (CreateEscapedIdentifier(expression.EventName));
}
protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression expression)
{
- Output.Write ("RaiseEvent ");
- GenerateExpression (expression.TargetObject);
+ CodeEventReferenceExpression ev = expression.TargetObject as CodeEventReferenceExpression;
+
+ if (ev != null) {
+ Output.Write ("RaiseEvent ");
+ if (ev.TargetObject != null && !(ev.TargetObject is CodeThisReferenceExpression)) {
+ GenerateExpression (ev.TargetObject);
+ Output.Write (".");
+ }
+ Output.Write (ev.EventName);
+ } else if (expression.TargetObject != null) {
+ GenerateExpression (expression.TargetObject);
+ }
Output.Write ('(');
OutputExpressionList (expression.Parameters);
- Output.WriteLine (')');
+ Output.Write (')');
}
protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression expression)
if (e.Value is char) {
char c = (char) e.Value;
int ch = (int) c;
-#if NET_2_0
Output.Write("Global.Microsoft.VisualBasic.ChrW(" + ch.ToString(CultureInfo.InvariantCulture) + ")");
} else if (e.Value is ushort) {
ushort uc = (ushort) e.Value;
Output.Write ("CSByte(");
Output.Write (sb.ToString(CultureInfo.InvariantCulture));
Output.Write (')');
-#else
- Output.Write("Microsoft.VisualBasic.ChrW(" + ch.ToString(CultureInfo.InvariantCulture) + ")");
-#endif
} else {
base.GeneratePrimitiveExpression(e);
}
protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression expression)
{
- GenerateMemberReferenceExpression (expression.TargetObject, expression.PropertyName);
+ if (expression.TargetObject != null) {
+ GenerateMemberReferenceExpression (expression.TargetObject, expression.PropertyName);
+ } else {
+ Output.Write (CreateEscapedIdentifier (expression.PropertyName));
+ }
}
protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression expression)
string text = comment.Text;
for (int i = 0; i < text.Length; i++) {
- output.Write (text[i]);
+ output.Write (text [i]);
if (text[i] == '\r') {
- if (i < (text.Length - 1) && text[i + 1] == '\n') {
+ if (i < (text.Length - 1) && text [i + 1] == '\n') {
continue;
}
output.Write (commentChars);
- } else if (text[i] == '\n') {
+ } else if (text [i] == '\n') {
output.Write (commentChars);
}
}
CodeStatementCollection finallies = statement.FinallyStatements;
if (finallies.Count > 0) {
-
output.WriteLine ("Finally");
++Indent;
GenerateStatements (finallies);
}
protected override void GenerateAssignStatement (CodeAssignStatement statement)
- {
+ {
TextWriter output = Output;
GenerateExpression (statement.Left);
output.Write (" = ");
TextWriter output = Output;
Output.Write ("AddHandler ");
- GenerateEventReferenceExpression (statement.Event);
+ if (statement.Event.TargetObject != null) {
+ GenerateEventReferenceExpression (statement.Event);
+ } else {
+ Output.Write (CreateEscapedIdentifier (statement.Event.EventName));
+ }
Output.Write ( ", ");
GenerateExpression (statement.Listener);
output.WriteLine ();
TextWriter output = Output;
Output.Write ("RemoveHandler ");
- GenerateEventReferenceExpression (statement.Event);
+ if (statement.Event.TargetObject != null) {
+ GenerateEventReferenceExpression (statement.Event);
+ } else {
+ Output.Write (CreateEscapedIdentifier (statement.Event.EventName));
+ }
Output.Write ( ", ");
GenerateExpression (statement.Listener);
output.WriteLine ();
OutputTypeNamePair (statement.Type, statement.Name);
CodeExpression initExpression = statement.InitExpression;
- if (initExpression != null)
- {
+ if (initExpression != null) {
output.Write (" = ");
GenerateExpression (initExpression);
}
protected override void GenerateLinePragmaStart (CodeLinePragma linePragma)
{
Output.WriteLine ();
- Output.Write ("#ExternalSource(");
+ Output.Write ("#ExternalSource(\"");
Output.Write (linePragma.FileName);
- Output.Write (", ");
+ Output.Write ("\",");
Output.Write (linePragma.LineNumber);
Output.WriteLine (")");
+ Output.WriteLine ("");
}
protected override void GenerateLinePragmaEnd (CodeLinePragma linePragma)
protected override void GenerateEvent (CodeMemberEvent eventRef, CodeTypeDeclaration declaration)
{
- if (IsCurrentDelegate || IsCurrentEnum) {
+ if (IsCurrentDelegate || IsCurrentEnum)
return;
- }
TextWriter output = Output;
- OutputAttributes (eventRef.CustomAttributes, null,
+ OutputAttributes (eventRef.CustomAttributes, null,
LineHandling.ContinueLine);
OutputMemberAccessModifier (eventRef.Attributes);
output.Write ("Event ");
OutputTypeNamePair (eventRef.Type, GetEventName(eventRef));
-#if NET_2_0
if (eventRef.ImplementationTypes.Count > 0) {
OutputImplementationTypes (eventRef.ImplementationTypes, eventRef.Name);
} else if (eventRef.PrivateImplementationType != null) {
output.Write ('.');
output.Write (eventRef.Name);
}
-#endif
output.WriteLine ();
}
protected override void GenerateField (CodeMemberField field)
{
- if (IsCurrentDelegate || IsCurrentInterface) {
+ if (IsCurrentDelegate || IsCurrentInterface)
return;
- }
TextWriter output = Output;
protected override void GenerateEntryPointMethod (CodeEntryPointMethod method, CodeTypeDeclaration declaration)
{
-#if NET_2_0
- OutputAttributes (method.CustomAttributes, null,
+ OutputAttributes (method.CustomAttributes, null,
LineHandling.ContinueLine);
-#endif
Output.WriteLine ("Public Shared Sub Main()");
Indent++;
[MonoTODO ("partially implemented")]
protected override void GenerateMethod (CodeMemberMethod method, CodeTypeDeclaration declaration)
{
- if (IsCurrentDelegate || IsCurrentEnum) {
+ if (IsCurrentDelegate || IsCurrentEnum)
return;
- }
bool isSub = method.ReturnType.BaseType == typeof(void).FullName;
output.Write ("Function ");
output.Write (GetMethodName(method));
+ OutputTypeParameters (method.TypeParameters);
output.Write ('(');
OutputParameters (method.Parameters);
output.Write (')');
protected override void GenerateProperty (CodeMemberProperty property, CodeTypeDeclaration declaration)
{
- if (IsCurrentDelegate || IsCurrentEnum) {
+ if (IsCurrentDelegate || IsCurrentEnum)
return;
- }
TextWriter output = Output;
output.Write ("Property ");
Output.Write (GetPropertyName (property));
-#if NET_2_0
// in .NET 2.0, always output parantheses (whether or not there
// are any parameters to output
Output.Write ('(');
OutputParameters (property.Parameters);
Output.Write (')');
-#else
- if (property.Parameters.Count > 0) {
- Output.Write ('(');
- OutputParameters (property.Parameters);
- Output.Write (')');
- }
-#endif
Output.Write (" As ");
Output.Write (GetTypeOutput(property.Type));
++Indent;
if (property.HasGet) {
output.WriteLine ("Get");
- ++Indent;
- GenerateStatements (property.GetStatements);
- --Indent;
- output.WriteLine ("End Get");
+ if (!IsAbstract (property.Attributes)) {
+ ++Indent;
+ GenerateStatements (property.GetStatements);
+ --Indent;
+ output.WriteLine ("End Get");
+ }
}
if (property.HasSet) {
output.WriteLine ("Set");
- ++Indent;
- GenerateStatements (property.SetStatements);
- --Indent;
- output.WriteLine ("End Set");
+ if (!IsAbstract (property.Attributes)) {
+ ++Indent;
+ GenerateStatements (property.SetStatements);
+ --Indent;
+ output.WriteLine ("End Set");
+ }
}
--Indent;
protected override void GenerateConstructor (CodeConstructor constructor, CodeTypeDeclaration declaration)
{
- if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+ if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface)
return;
- }
OutputAttributes (constructor.CustomAttributes, null,
LineHandling.ContinueLine);
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()");
+ Output.WriteLine ("MyBase.New");
}
}
GenerateStatements (constructor.Statements);
protected override void GenerateTypeConstructor (CodeTypeConstructor constructor)
{
- if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
+ if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface)
return;
- }
-#if NET_2_0
OutputAttributes (constructor.CustomAttributes, null,
LineHandling.ContinueLine);
-#endif
Output.WriteLine ("Shared Sub New()");
Indent++;
output.Write ("Delegate Function ");
}
- output.Write (delegateDecl.Name);
+ output.Write (CreateEscapedIdentifier (delegateDecl.Name));
+ OutputTypeParameters (delegateDecl.TypeParameters);
output.Write ("(");
+ OutputParameters (delegateDecl.Parameters);
Output.Write (")");
if (!isSub) {
Output.Write (" As ");
Output.WriteLine ("");
} else {
OutputTypeAttributes (declaration);
-
- output.Write (declaration.Name);
+ output.Write (CreateEscapedIdentifier (declaration.Name));
+ OutputTypeParameters (declaration.TypeParameters);
if (IsCurrentEnum) {
if (declaration.BaseTypes.Count > 0) {
protected override void OutputFieldScopeModifier (MemberAttributes attributes)
{
switch (attributes & MemberAttributes.ScopeMask) {
- case MemberAttributes.Static:
- Output.Write ("Shared ");
- break;
- case MemberAttributes.Const:
- Output.Write ("Const ");
- break;
+ case MemberAttributes.Static:
+ Output.Write ("Shared ");
+ break;
+ case MemberAttributes.Const:
+ Output.Write ("Const ");
+ break;
}
}
protected override void OutputMemberAccessModifier (MemberAttributes attributes)
{
switch (attributes & MemberAttributes.AccessMask) {
- case MemberAttributes.Assembly:
- case MemberAttributes.FamilyAndAssembly:
- Output.Write ("Friend ");
- break;
- case MemberAttributes.Family:
- Output.Write ("Protected ");
- break;
- case MemberAttributes.FamilyOrAssembly:
- Output.Write ("Protected Friend ");
- break;
- case MemberAttributes.Private:
- Output.Write ("Private ");
- break;
- case MemberAttributes.Public:
- Output.Write ("Public ");
- break;
+ case MemberAttributes.Assembly:
+ case MemberAttributes.FamilyAndAssembly:
+ Output.Write ("Friend ");
+ break;
+ case MemberAttributes.Family:
+ Output.Write ("Protected ");
+ break;
+ case MemberAttributes.FamilyOrAssembly:
+ Output.Write ("Protected Friend ");
+ break;
+ case MemberAttributes.Private:
+ Output.Write ("Private ");
+ break;
+ case MemberAttributes.Public:
+ Output.Write ("Public ");
+ break;
}
}
private void OutputVTableModifier (MemberAttributes attributes)
{
- if ((attributes & MemberAttributes.VTableMask) == MemberAttributes.New) {
+ if ((attributes & MemberAttributes.VTableMask) == MemberAttributes.New)
Output.Write ("Shadows ");
- }
}
protected override void OutputMemberScopeModifier (MemberAttributes attributes)
{
switch (attributes & MemberAttributes.ScopeMask) {
- case MemberAttributes.Abstract:
- Output.Write ("MustOverride ");
- break;
- case MemberAttributes.Final:
- // do nothing
- break;
- case MemberAttributes.Static:
- Output.Write ("Shared ");
- break;
- case MemberAttributes.Override:
- Output.Write ("Overrides ");
- break;
- case MemberAttributes.Overloaded:
- // based on http://gendotnet.com/Code%20Gen%20Articles/codedom.htm
- Output.Write ("Overloads ");
+ case MemberAttributes.Abstract:
+ Output.Write ("MustOverride ");
+ break;
+ case MemberAttributes.Final:
+ // do nothing
+ break;
+ case MemberAttributes.Static:
+ Output.Write ("Shared ");
+ break;
+ case MemberAttributes.Override:
+ Output.Write ("Overrides ");
+ break;
+ 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;
- default:
- //
- // FUNNY! if the scope value is
- // rubbish (0 or >Const), and access
- // is public, protected make it
- // "virtual".
- //
- // i'm not sure whether this is 100%
- // correct, but it seems to be MS
- // behavior.
- //
- // On MS.NET 2.0, internal properties
- // are also marked "virtual".
- //
- MemberAttributes access = attributes & MemberAttributes.AccessMask;
- if (access == MemberAttributes.Public ||
-#if NET_2_0
- access == MemberAttributes.Family || access == MemberAttributes.Assembly)
-#else
- access == MemberAttributes.Family)
-#endif
- 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
+ // rubbish (0 or >Const), and access
+ // is public, protected make it
+ // "virtual".
+ //
+ // i'm not sure whether this is 100%
+ // correct, but it seems to be MS
+ // behavior.
+ //
+ // On MS.NET 2.0, internal properties
+ // are also marked "virtual".
+ //
+ MemberAttributes access = attributes & MemberAttributes.AccessMask;
+ if (access == MemberAttributes.Public ||
+ access == MemberAttributes.Family || access == MemberAttributes.Assembly)
+ Output.Write ("Overridable ");
+ break;
}
}
TextWriter output = Output;
TypeAttributes attributes = declaration.TypeAttributes;
+ if (declaration.IsPartial)
+ output.Write ("Partial ");
+
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 ("Friend ");
- break;
- case TypeAttributes.NestedFamily:
- output.Write ("Protected ");
- break;
- case TypeAttributes.NestedFamORAssem:
- output.Write ("Protected Friend ");
- break;
-#endif
+ case TypeAttributes.Public:
+ case TypeAttributes.NestedPublic:
+ output.Write ("Public ");
+ break;
+ case TypeAttributes.NestedPrivate:
+ output.Write ("Private ");
+ break;
+ 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;
}
if (declaration.IsStruct) {
}
}
+ void OutputTypeParameters (CodeTypeParameterCollection parameters)
+ {
+ int count = parameters.Count;
+ if (count == 0)
+ return;
+
+ Output.Write ("(Of ");
+ for (int i = 0; i < count; ++i) {
+ if (i > 0)
+ Output.Write (", ");
+ CodeTypeParameter p = parameters [i];
+ Output.Write (p.Name);
+ OutputTypeParameterConstraints (p);
+ }
+ Output.Write (')');
+ }
+
+ void OutputTypeParameterConstraints (CodeTypeParameter parameter)
+ {
+ int constraint_count = parameter.Constraints.Count +
+ (parameter.HasConstructorConstraint ? 1 : 0);
+
+ if (constraint_count == 0)
+ return;
+
+ Output.Write (" As ");
+
+ if (constraint_count > 1)
+ Output.Write (" {");
+
+ for (int i = 0; i < parameter.Constraints.Count; i++) {
+ if (i > 0)
+ Output.Write (", ");
+ OutputType (parameter.Constraints [i]);
+ }
+
+ if (parameter.HasConstructorConstraint) {
+ if (constraint_count > 1)
+ Output.Write (", ");
+ Output.Write ("New");
+ }
+
+ if (constraint_count > 1)
+ Output.Write ("}");
+ }
+
protected override void OutputTypeNamePair (CodeTypeReference typeRef, String name)
{
-#if NET_2_0
- if (name.Length == 0) {
+ if (name.Length == 0)
name = "__exception";
- }
-#endif
Output.Write (CreateEscapedIdentifier(name) + " As " + GetTypeOutput (typeRef));
}
StringBuilder mySBuilder = new StringBuilder(value.Length);
mySBuilder.Append ("\"");
bool inQuotes = true;
- for (int MyCounter = 0; MyCounter < value.Length; MyCounter++)
- {
+ for (int MyCounter = 0; MyCounter < value.Length; MyCounter++) {
if (value[MyCounter] == 34) //quotation mark
{
- if (!inQuotes)
- {
+ if (!inQuotes) {
mySBuilder.Append ("&\"");
inQuotes = true;
}
}
else if (value[MyCounter] >= 32) //standard ansi/unicode characters
{
- if (!inQuotes)
- {
+ if (!inQuotes) {
mySBuilder.Append ("&\"");
inQuotes = true;
}
}
else //special chars, e.g. line break
{
- if (inQuotes)
- {
+ if (inQuotes) {
mySBuilder.Append ("\"");
inQuotes = false;
}
mySBuilder.Append ("&Microsoft.VisualBasic.ChrW(");
mySBuilder.Append ((int)value[MyCounter]);
mySBuilder.Append (")");
- }
+ }
}
if (inQuotes)
mySBuilder.Append ("\"");
arrayType = type.ArrayElementType;
if (arrayType != null)
output = GetTypeOutput (arrayType);
- else {
+ else {
switch (type.BaseType) {
case "System.DateTime":
output = "Date";
case "System.Object":
output = "Object";
break;
-#if NET_2_0
case "System.SByte":
output = "SByte";
break;
case "System.UInt64":
output = "ULong";
break;
-#endif
default:
output = type.BaseType.Replace('+', '.');
+ output = CreateEscapedIdentifier (output);
break;
}
}
continue;
}
- if (p != property && p.Name == property.Name && p.PrivateImplementationType == null) {
+ if (p != property && p.Name == property.Name && p.PrivateImplementationType == null)
return true;
- }
}
return false;
}
continue;
}
- if (!(m is CodeTypeConstructor) && !(m is CodeConstructor) && m != method && m.Name == method.Name && m.PrivateImplementationType == null) {
+ if (!(m is CodeTypeConstructor) && !(m is CodeConstructor) && m != method && m.Name == method.Name && m.PrivateImplementationType == null)
return true;
- }
}
return false;
}
private string GetEventName (CodeMemberEvent evt)
{
-#if NET_2_0
- if (evt.PrivateImplementationType == null) {
+ if (evt.PrivateImplementationType == null)
return evt.Name;
- }
string baseType = evt.PrivateImplementationType.BaseType.Replace ('.', '_');
return baseType + "_" + evt.Name;
-#else
- return evt.Name;
-#endif
}
private string GetMethodName (CodeMemberMethod method)
{
- if (method.PrivateImplementationType == null) {
+ if (method.PrivateImplementationType == null)
return method.Name;
- }
string baseType = method.PrivateImplementationType.BaseType.Replace ('.', '_');
return baseType + "_" + method.Name;
private string GetPropertyName (CodeMemberProperty property)
{
- if (property.PrivateImplementationType == null) {
+ if (property.PrivateImplementationType == null)
return property.Name;
- }
string baseType = property.PrivateImplementationType.BaseType.Replace ('.', '_');
return baseType + "_" + property.Name;
}
+ static bool IsAbstract (MemberAttributes attributes)
+ {
+ return (attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract;
+ }
+
private enum LineHandling
{
InLine,