/LinqToCodedomProject/LinqToCodedom/Generator/VBCodeGenerator.cs
C# | 2572 lines | 2422 code | 147 blank | 3 comment | 481 complexity | c5f764d5deec43e770fd9b48223036ce MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.CodeDom;
- using System.CodeDom.Compiler;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime;
- using System.Security;
- using System.Security.Permissions;
- using System.Text;
- using System.Text.RegularExpressions;
-
- namespace LinqToCodedom.Generator
- {
- public class VBCodeGenerator : CodeCompiler
- {
- // Fields
- private static readonly string[][] keywords;
- private const GeneratorSupport LanguageSupport = (GeneratorSupport.DeclareIndexerProperties | GeneratorSupport.GenericTypeDeclaration | GeneratorSupport.GenericTypeReference | GeneratorSupport.PartialTypes | GeneratorSupport.Resources | GeneratorSupport.Win32Resources | GeneratorSupport.ComplexExpressions | GeneratorSupport.PublicStaticMembers | GeneratorSupport.MultipleInterfaceMembers | GeneratorSupport.NestedTypes | GeneratorSupport.ChainedConstructorArguments | GeneratorSupport.ReferenceParameters | GeneratorSupport.ParameterAttributes | GeneratorSupport.AssemblyAttributes | GeneratorSupport.DeclareEvents | GeneratorSupport.DeclareInterfaces | GeneratorSupport.DeclareDelegates | GeneratorSupport.DeclareEnums | GeneratorSupport.DeclareValueTypes | GeneratorSupport.ReturnTypeAttributes | GeneratorSupport.TryCatchStatements | GeneratorSupport.StaticConstructors | GeneratorSupport.MultidimensionalArrays | GeneratorSupport.GotoStatements | GeneratorSupport.EntryPointMethod | GeneratorSupport.ArraysOfArrays);
- private const int MaxLineLength = 80;
- private static volatile Regex outputReg;
- private IDictionary<string, string> provOptions;
- private int statementDepth;
-
- // Methods
- static VBCodeGenerator()
- {
- string[][] strArray = new string[16][];
- strArray[1] = new string[] { "as", "do", "if", "in", "is", "me", "of", "on", "or", "to" };
- strArray[2] = new string[] { "and", "dim", "end", "for", "get", "let", "lib", "mod", "new", "not", "rem", "set", "sub", "try", "xor" };
- strArray[3] = new string[] {
- "ansi", "auto", "byte", "call", "case", "cdbl", "cdec", "char", "cint", "clng", "cobj", "csng", "cstr", "date", "each", "else",
- "enum", "exit", "goto", "like", "long", "loop", "next", "step", "stop", "then", "true", "wend", "when", "with"
- };
- strArray[4] = new string[] {
- "alias", "byref", "byval", "catch", "cbool", "cbyte", "cchar", "cdate", "class", "const", "ctype", "cuint", "culng", "endif", "erase", "error",
- "event", "false", "gosub", "isnot", "redim", "sbyte", "short", "throw", "ulong", "until", "using", "while"
- };
- strArray[5] = new string[] {
- "csbyte", "cshort", "double", "elseif", "friend", "global", "module", "mybase", "object", "option", "orelse", "public", "resume", "return", "select", "shared",
- "single", "static", "string", "typeof", "ushort"
- };
- strArray[6] = new string[] {
- "andalso", "boolean", "cushort", "decimal", "declare", "default", "finally", "gettype", "handles", "imports", "integer", "myclass", "nothing", "partial", "private", "shadows",
- "trycast", "unicode", "variant"
- };
- strArray[7] = new string[] { "assembly", "continue", "delegate", "function", "inherits", "operator", "optional", "preserve", "property", "readonly", "synclock", "uinteger", "widening" };
- strArray[8] = new string[] { "addressof", "interface", "namespace", "narrowing", "overloads", "overrides", "protected", "structure", "writeonly" };
- strArray[9] = new string[] { "addhandler", "directcast", "implements", "paramarray", "raiseevent", "withevents" };
- strArray[10] = new string[] { "mustinherit", "overridable" };
- strArray[11] = new string[] { "mustoverride" };
- strArray[12] = new string[] { "removehandler" };
- strArray[13] = new string[] { "class_finalize", "notinheritable", "notoverridable" };
- strArray[15] = new string[] { "class_initialize" };
- keywords = strArray;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- internal VBCodeGenerator()
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- internal VBCodeGenerator(IDictionary<string, string> providerOptions)
- {
- this.provOptions = providerOptions;
- }
-
- protected bool AllowLateBound(CodeCompileUnit e)
- {
- object obj2 = e.UserData["AllowLateBound"];
- if ((obj2 != null) && (obj2 is bool))
- {
- return (bool)obj2;
- }
- return true;
- }
-
- private static void AppendEscapedChar(StringBuilder b, char value)
- {
- b.Append("&Global.Microsoft.VisualBasic.ChrW(");
- b.Append(((int)value).ToString(CultureInfo.InvariantCulture));
- b.Append(")");
- }
-
- protected override string CmdArgsFromParameters(CompilerParameters options)
- {
- string str3;
- using (StringEnumerator enumerator = options.ReferencedAssemblies.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- if (string.IsNullOrEmpty(enumerator.Current))
- {
- throw new ArgumentException(SR.GetString("NullOrEmpty_Value_in_Property", new object[] { "ReferencedAssemblies" }), "options");
- }
- }
- }
- StringBuilder builder = new StringBuilder(128);
- if (options.GenerateExecutable)
- {
- builder.Append("/t:exe ");
- if ((options.MainClass != null) && (options.MainClass.Length > 0))
- {
- builder.Append("/main:");
- builder.Append(options.MainClass);
- builder.Append(" ");
- }
- }
- else
- {
- builder.Append("/t:library ");
- }
- builder.Append("/utf8output ");
- string coreAssemblyFileName = options.CoreAssemblyFileName;
- if (string.IsNullOrWhiteSpace(options.CoreAssemblyFileName) && CodeDomProvider.TryGetProbableCoreAssemblyFilePath(options, out str3))
- {
- coreAssemblyFileName = str3;
- }
- if (!string.IsNullOrWhiteSpace(coreAssemblyFileName))
- {
- string path = coreAssemblyFileName.Trim();
- string directoryName = Path.GetDirectoryName(path);
- builder.Append("/nostdlib ");
- builder.Append("/sdkpath:\"").Append(directoryName).Append("\" ");
- builder.Append("/R:\"").Append(path).Append("\" ");
- }
- foreach (string str6 in options.ReferencedAssemblies)
- {
- string fileName = Path.GetFileName(str6);
- if ((string.Compare(fileName, "Microsoft.VisualBasic.dll", StringComparison.OrdinalIgnoreCase) != 0) && (string.Compare(fileName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) != 0))
- {
- builder.Append("/R:");
- builder.Append("\"");
- builder.Append(str6);
- builder.Append("\"");
- builder.Append(" ");
- }
- }
- builder.Append("/out:");
- builder.Append("\"");
- builder.Append(options.OutputAssembly);
- builder.Append("\"");
- builder.Append(" ");
- if (options.IncludeDebugInformation)
- {
- builder.Append("/D:DEBUG=1 ");
- builder.Append("/debug+ ");
- }
- else
- {
- builder.Append("/debug- ");
- }
- if (options.Win32Resource != null)
- {
- builder.Append("/win32resource:\"" + options.Win32Resource + "\" ");
- }
- foreach (string str8 in options.EmbeddedResources)
- {
- builder.Append("/res:\"");
- builder.Append(str8);
- builder.Append("\" ");
- }
- foreach (string str9 in options.LinkedResources)
- {
- builder.Append("/linkres:\"");
- builder.Append(str9);
- builder.Append("\" ");
- }
- if (options.TreatWarningsAsErrors)
- {
- builder.Append("/warnaserror+ ");
- }
- if (options.CompilerOptions != null)
- {
- builder.Append(options.CompilerOptions + " ");
- }
- return builder.ToString();
- }
-
- protected override void ContinueOnNewLine(string st)
- {
- base.Output.Write(st);
- base.Output.WriteLine(" _");
- }
-
- protected override string CreateEscapedIdentifier(string name)
- {
- if (IsKeyword(name))
- {
- return ("[" + name + "]");
- }
- return name;
- }
-
- protected override string CreateValidIdentifier(string name)
- {
- if (IsKeyword(name))
- {
- return ("_" + name);
- }
- return name;
- }
-
- private void EnsureInDoubleQuotes(ref bool fInDoubleQuotes, StringBuilder b)
- {
- if (!fInDoubleQuotes)
- {
- b.Append("&\"");
- fInDoubleQuotes = true;
- }
- }
-
- private void EnsureNotInDoubleQuotes(ref bool fInDoubleQuotes, StringBuilder b)
- {
- if (fInDoubleQuotes)
- {
- b.Append("\"");
- fInDoubleQuotes = false;
- }
- }
-
- protected override CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames)
- {
- if (options == null)
- {
- throw new ArgumentNullException("options");
- }
- if (fileNames == null)
- {
- throw new ArgumentNullException("fileNames");
- }
- new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
- string outputFile = null;
- int nativeReturnValue = 0;
- CompilerResults results = new CompilerResults(options.TempFiles);
- new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert();
- try
- {
- results.Evidence = options.Evidence;
- }
- finally
- {
- CodeAccessPermission.RevertAssert();
- }
- bool flag = false;
- string fileExtension = options.GenerateExecutable ? "exe" : "dll";
- string str3 = '.' + fileExtension;
- if ((options.OutputAssembly == null) || (options.OutputAssembly.Length == 0))
- {
- options.OutputAssembly = results.TempFiles.AddExtension(fileExtension, !options.GenerateInMemory);
- new FileStream(options.OutputAssembly, FileMode.Create, FileAccess.ReadWrite).Close();
- flag = true;
- }
- string outputAssembly = options.OutputAssembly;
- if (!Path.GetExtension(outputAssembly).Equals(str3, StringComparison.OrdinalIgnoreCase))
- {
- outputAssembly = outputAssembly + str3;
- }
- string str5 = "pdb";
- if ((options.CompilerOptions != null) && (options.CompilerOptions.IndexOf("/debug:pdbonly", StringComparison.OrdinalIgnoreCase) != -1))
- {
- results.TempFiles.AddExtension(str5, true);
- }
- else
- {
- results.TempFiles.AddExtension(str5);
- }
- string cmdArgs = this.CmdArgsFromParameters(options) + " " + CodeCompiler.JoinStringArray(fileNames, " ");
- string responseFileCmdArgs = this.GetResponseFileCmdArgs(options, cmdArgs);
- string trueArgs = null;
- if (responseFileCmdArgs != null)
- {
- trueArgs = cmdArgs;
- cmdArgs = responseFileCmdArgs;
- }
- base.Compile(options, RedistVersionInfo.GetCompilerPath(this.provOptions, this.CompilerName), this.CompilerName, cmdArgs, ref outputFile, ref nativeReturnValue, trueArgs);
- results.NativeCompilerReturnValue = nativeReturnValue;
- if ((nativeReturnValue != 0) || (options.WarningLevel > 0))
- {
- byte[] bytes = ReadAllBytes(outputFile, FileShare.ReadWrite);
- foreach (string str10 in Regex.Split(Encoding.UTF8.GetString(bytes), @"\r\n"))
- {
- results.Output.Add(str10);
- this.ProcessCompilerOutputLine(results, str10);
- }
- if ((nativeReturnValue != 0) && flag)
- {
- File.Delete(outputAssembly);
- }
- }
- if (!results.Errors.HasErrors && options.GenerateInMemory)
- {
- FileStream stream = new FileStream(outputAssembly, FileMode.Open, FileAccess.Read, FileShare.Read);
- try
- {
- int length = (int)stream.Length;
- byte[] buffer = new byte[length];
- stream.Read(buffer, 0, length);
- new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert();
- try
- {
- results.CompiledAssembly = Assembly.Load(buffer, null, options.Evidence);
- }
- finally
- {
- CodeAccessPermission.RevertAssert();
- }
- return results;
- }
- finally
- {
- stream.Close();
- }
- }
- results.PathToAssembly = outputAssembly;
- return results;
- }
-
- protected override void GenerateArgumentReferenceExpression(CodeArgumentReferenceExpression e)
- {
- this.OutputIdentifier(e.ParameterName);
- }
-
- protected override void GenerateArrayCreateExpression(CodeArrayCreateExpression e)
- {
- base.Output.Write("New ");
- CodeExpressionCollection initializers = e.Initializers;
- if (initializers.Count > 0)
- {
- string typeOutput = this.GetTypeOutput(e.CreateType);
- base.Output.Write(typeOutput);
- if (typeOutput.IndexOf('(') == -1)
- {
- base.Output.Write("()");
- }
- base.Output.Write(" {");
- base.Indent++;
- this.OutputExpressionList(initializers);
- base.Indent--;
- base.Output.Write("}");
- }
- else
- {
- string str2 = this.GetTypeOutput(e.CreateType);
- int index = str2.IndexOf('(');
- if (index == -1)
- {
- base.Output.Write(str2);
- base.Output.Write('(');
- }
- else
- {
- base.Output.Write(str2.Substring(0, index + 1));
- }
- if (e.SizeExpression != null)
- {
- base.Output.Write("(");
- base.GenerateExpression(e.SizeExpression);
- base.Output.Write(") - 1");
- }
- else
- {
- base.Output.Write((int)(e.Size - 1));
- }
- if (index == -1)
- {
- base.Output.Write(')');
- }
- else
- {
- base.Output.Write(str2.Substring(index + 1));
- }
- base.Output.Write(" {}");
- }
- }
-
- protected override void GenerateArrayIndexerExpression(CodeArrayIndexerExpression e)
- {
- base.GenerateExpression(e.TargetObject);
- base.Output.Write("(");
- bool flag = true;
- foreach (CodeExpression expression in e.Indices)
- {
- if (flag)
- {
- flag = false;
- }
- else
- {
- base.Output.Write(", ");
- }
- base.GenerateExpression(expression);
- }
- base.Output.Write(")");
- }
-
- protected override void GenerateAssignStatement(CodeAssignStatement e)
- {
- base.GenerateExpression(e.Left);
- base.Output.Write(" = ");
- base.GenerateExpression(e.Right);
- base.Output.WriteLine("");
- }
-
- protected override void GenerateAttachEventStatement(CodeAttachEventStatement e)
- {
- base.Output.Write("AddHandler ");
- this.GenerateFormalEventReferenceExpression(e.Event);
- base.Output.Write(", ");
- base.GenerateExpression(e.Listener);
- base.Output.WriteLine("");
- }
-
- protected override void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes)
- {
- base.Output.Write(">");
- }
-
- protected override void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes)
- {
- base.Output.Write("<");
- }
-
- protected override void GenerateBaseReferenceExpression(CodeBaseReferenceExpression e)
- {
- base.Output.Write("MyBase");
- }
-
- protected override void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression e)
- {
- if (e.Operator != CodeBinaryOperatorType.IdentityInequality)
- {
- base.GenerateBinaryOperatorExpression(e);
- }
- else if ((e.Right is CodePrimitiveExpression) && (((CodePrimitiveExpression)e.Right).Value == null))
- {
- this.GenerateNotIsNullExpression(e.Left);
- }
- else if ((e.Left is CodePrimitiveExpression) && (((CodePrimitiveExpression)e.Left).Value == null))
- {
- this.GenerateNotIsNullExpression(e.Right);
- }
- else
- {
- base.GenerateBinaryOperatorExpression(e);
- }
- }
-
- protected override void GenerateCastExpression(CodeCastExpression e)
- {
- base.Output.Write("CType(");
- base.GenerateExpression(e.Expression);
- base.Output.Write(",");
- this.OutputType(e.TargetType);
- this.OutputArrayPostfix(e.TargetType);
- base.Output.Write(")");
- }
-
- private void GenerateChecksumPragma(CodeChecksumPragma checksumPragma)
- {
- base.Output.Write("#ExternalChecksum(\"");
- base.Output.Write(checksumPragma.FileName);
- base.Output.Write("\",\"");
- base.Output.Write(checksumPragma.ChecksumAlgorithmId.ToString("B", CultureInfo.InvariantCulture));
- base.Output.Write("\",\"");
- if (checksumPragma.ChecksumData != null)
- {
- foreach (byte num in checksumPragma.ChecksumData)
- {
- base.Output.Write(num.ToString("X2", CultureInfo.InvariantCulture));
- }
- }
- base.Output.WriteLine("\")");
- }
-
- private void GenerateCodeRegionDirective(CodeRegionDirective regionDirective)
- {
- if (!this.IsGeneratingStatements())
- {
- if (regionDirective.RegionMode == CodeRegionMode.Start)
- {
- base.Output.Write("#Region \"");
- base.Output.Write(regionDirective.RegionText);
- base.Output.WriteLine("\"");
- }
- else if (regionDirective.RegionMode == CodeRegionMode.End)
- {
- base.Output.WriteLine("#End Region");
- }
- }
- }
-
- protected override void GenerateComment(CodeComment e)
- {
- string str = e.DocComment ? "'''" : "'";
- base.Output.Write(str);
- string text = e.Text;
- for (int i = 0; i < text.Length; i++)
- {
- base.Output.Write(text[i]);
- if (text[i] == '\r')
- {
- if ((i < (text.Length - 1)) && (text[i + 1] == '\n'))
- {
- base.Output.Write('\n');
- i++;
- }
- ((IndentedTextWriter)base.Output).InternalOutputTabs();
- base.Output.Write(str);
- }
- else if (text[i] == '\n')
- {
- ((IndentedTextWriter)base.Output).InternalOutputTabs();
- base.Output.Write(str);
- }
- else if (((text[i] == '\u2028') || (text[i] == '\u2029')) || (text[i] == '\x0085'))
- {
- base.Output.Write(str);
- }
- }
- base.Output.WriteLine();
- }
-
- protected override void GenerateCommentStatements(CodeCommentStatementCollection e)
- {
- foreach (CodeCommentStatement statement in e)
- {
- if (!this.IsDocComment(statement))
- {
- this.GenerateCommentStatement(statement);
- }
- }
- foreach (CodeCommentStatement statement2 in e)
- {
- if (this.IsDocComment(statement2))
- {
- this.GenerateCommentStatement(statement2);
- }
- }
- }
-
- protected override void GenerateCompileUnit(CodeCompileUnit e)
- {
- this.GenerateCompileUnitStart(e);
- SortedList list = new SortedList(StringComparer.OrdinalIgnoreCase);
- foreach (CodeNamespace namespace2 in e.Namespaces)
- {
- namespace2.UserData["GenerateImports"] = false;
- foreach (CodeNamespaceImport import in namespace2.Imports)
- {
- if (!list.Contains(import.Namespace))
- {
- list.Add(import.Namespace, import.Namespace);
- }
- }
- }
- foreach (string str in list.Keys)
- {
- base.Output.Write("Imports ");
- this.OutputIdentifier(str);
- base.Output.WriteLine("");
- }
- if (e.AssemblyCustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.AssemblyCustomAttributes, false, "Assembly: ", true);
- }
- base.GenerateNamespaces(e);
- this.GenerateCompileUnitEnd(e);
- }
-
- protected override void GenerateCompileUnitStart(CodeCompileUnit e)
- {
- base.GenerateCompileUnitStart(e);
- base.Output.WriteLine("'------------------------------------------------------------------------------");
- base.Output.Write("' <");
- base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line1"));
- base.Output.Write("' ");
- base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line2"));
- base.Output.Write("' ");
- base.Output.Write(SR.GetString("AutoGen_Comment_Line3"));
- base.Output.WriteLine(Environment.Version.ToString());
- base.Output.WriteLine("'");
- base.Output.Write("' ");
- base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line4"));
- base.Output.Write("' ");
- base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line5"));
- base.Output.Write("' </");
- base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line1"));
- base.Output.WriteLine("'------------------------------------------------------------------------------");
- base.Output.WriteLine("");
- if (this.AllowLateBound(e))
- {
- base.Output.WriteLine("Option Strict Off");
- }
- else
- {
- base.Output.WriteLine("Option Strict On");
- }
- if (!this.RequireVariableDeclaration(e))
- {
- base.Output.WriteLine("Option Explicit Off");
- }
- else
- {
- base.Output.WriteLine("Option Explicit On");
- }
- base.Output.WriteLine();
- }
-
- protected override void GenerateConditionStatement(CodeConditionStatement e)
- {
- base.Output.Write("If ");
- base.GenerateExpression(e.Condition);
- base.Output.WriteLine(" Then");
- base.Indent++;
- this.GenerateVBStatements(e.TrueStatements);
- base.Indent--;
- if (e.FalseStatements.Count > 0)
- {
- base.Output.Write("Else");
- base.Output.WriteLine("");
- base.Indent++;
- this.GenerateVBStatements(e.FalseStatements);
- base.Indent--;
- }
- base.Output.WriteLine("End If");
- }
-
- protected override void GenerateConstructor(CodeConstructor e, CodeTypeDeclaration c)
- {
- if (base.IsCurrentClass || base.IsCurrentStruct)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- this.OutputMemberAccessModifier(e.Attributes);
- base.Output.Write("Sub New(");
- this.OutputParameters(e.Parameters);
- base.Output.WriteLine(")");
- base.Indent++;
- CodeExpressionCollection baseConstructorArgs = e.BaseConstructorArgs;
- CodeExpressionCollection chainedConstructorArgs = e.ChainedConstructorArgs;
- if (chainedConstructorArgs.Count > 0)
- {
- base.Output.Write("Me.New(");
- this.OutputExpressionList(chainedConstructorArgs);
- base.Output.Write(")");
- base.Output.WriteLine("");
- }
- else if (baseConstructorArgs.Count > 0)
- {
- base.Output.Write("MyBase.New(");
- this.OutputExpressionList(baseConstructorArgs);
- base.Output.Write(")");
- base.Output.WriteLine("");
- }
- else if (base.IsCurrentClass)
- {
- base.Output.WriteLine("MyBase.New");
- }
- this.GenerateVBStatements(e.Statements);
- base.Indent--;
- base.Output.WriteLine("End Sub");
- }
- }
-
- protected override void GenerateDecimalValue(decimal d)
- {
- base.Output.Write(d.ToString(CultureInfo.InvariantCulture));
- base.Output.Write('D');
- }
-
- protected override void GenerateDefaultValueExpression(CodeDefaultValueExpression e)
- {
- base.Output.Write("CType(Nothing, " + this.GetTypeOutput(e.Type) + ")");
- }
-
- protected override void GenerateDelegateCreateExpression(CodeDelegateCreateExpression e)
- {
- base.Output.Write("AddressOf ");
- base.GenerateExpression(e.TargetObject);
- base.Output.Write(".");
- this.OutputIdentifier(e.MethodName);
- }
-
- protected override void GenerateDelegateInvokeExpression(CodeDelegateInvokeExpression e)
- {
- if (e.TargetObject != null)
- {
- if (e.TargetObject is CodeEventReferenceExpression)
- {
- base.Output.Write("RaiseEvent ");
- this.GenerateFormalEventReferenceExpression((CodeEventReferenceExpression)e.TargetObject);
- }
- else
- {
- base.GenerateExpression(e.TargetObject);
- }
- }
- if (e.Parameters.Count > 0)
- {
- base.Output.Write("(");
- this.OutputExpressionList(e.Parameters);
- base.Output.Write(")");
- }
- }
-
- protected override void GenerateDirectionExpression(CodeDirectionExpression e)
- {
- base.GenerateExpression(e.Expression);
- }
-
- protected override void GenerateDirectives(CodeDirectiveCollection directives)
- {
- for (int i = 0; i < directives.Count; i++)
- {
- CodeDirective directive = directives[i];
- if (directive is CodeChecksumPragma)
- {
- this.GenerateChecksumPragma((CodeChecksumPragma)directive);
- }
- else if (directive is CodeRegionDirective)
- {
- this.GenerateCodeRegionDirective((CodeRegionDirective)directive);
- }
- }
- }
-
- protected override void GenerateDoubleValue(double d)
- {
- if (double.IsNaN(d))
- {
- base.Output.Write("Double.NaN");
- }
- else if (double.IsNegativeInfinity(d))
- {
- base.Output.Write("Double.NegativeInfinity");
- }
- else if (double.IsPositiveInfinity(d))
- {
- base.Output.Write("Double.PositiveInfinity");
- }
- else
- {
- base.Output.Write(d.ToString("R", CultureInfo.InvariantCulture));
- base.Output.Write("R");
- }
- }
-
- protected override void GenerateEntryPointMethod(CodeEntryPointMethod e, CodeTypeDeclaration c)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- base.Output.WriteLine("Public Shared Sub Main()");
- base.Indent++;
- this.GenerateVBStatements(e.Statements);
- base.Indent--;
- base.Output.WriteLine("End Sub");
- }
-
- protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c)
- {
- if (!base.IsCurrentDelegate && !base.IsCurrentEnum)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- string name = e.Name;
- if (e.PrivateImplementationType != null)
- {
- string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
- e.Name = str2 + "_" + e.Name;
- }
- this.OutputMemberAccessModifier(e.Attributes);
- base.Output.Write("Event ");
- this.OutputTypeNamePair(e.Type, e.Name);
- if (e.ImplementationTypes.Count > 0)
- {
- base.Output.Write(" Implements ");
- bool flag = true;
- foreach (CodeTypeReference reference in e.ImplementationTypes)
- {
- if (flag)
- {
- flag = false;
- }
- else
- {
- base.Output.Write(" , ");
- }
- this.OutputType(reference);
- base.Output.Write(".");
- this.OutputIdentifier(name);
- }
- }
- else if (e.PrivateImplementationType != null)
- {
- base.Output.Write(" Implements ");
- this.OutputType(e.PrivateImplementationType);
- base.Output.Write(".");
- this.OutputIdentifier(name);
- }
- base.Output.WriteLine("");
- }
- }
-
- protected override void GenerateEventReferenceExpression(CodeEventReferenceExpression e)
- {
- if (e.TargetObject != null)
- {
- bool flag = e.TargetObject is CodeThisReferenceExpression;
- base.GenerateExpression(e.TargetObject);
- base.Output.Write(".");
- if (flag)
- {
- base.Output.Write(e.EventName + "Event");
- }
- else
- {
- base.Output.Write(e.EventName);
- }
- }
- else
- {
- this.OutputIdentifier(e.EventName + "Event");
- }
- }
-
- protected override void GenerateExpressionStatement(CodeExpressionStatement e)
- {
- base.GenerateExpression(e.Expression);
- base.Output.WriteLine("");
- }
-
- protected override void GenerateField(CodeMemberField e)
- {
- if (!base.IsCurrentDelegate && !base.IsCurrentInterface)
- {
- if (base.IsCurrentEnum)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- this.OutputIdentifier(e.Name);
- if (e.InitExpression != null)
- {
- base.Output.Write(" = ");
- base.GenerateExpression(e.InitExpression);
- }
- base.Output.WriteLine("");
- }
- else
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- this.OutputMemberAccessModifier(e.Attributes);
- this.OutputVTableModifier(e.Attributes);
- this.OutputFieldScopeModifier(e.Attributes);
- if (this.GetUserData(e, "WithEvents", false))
- {
- base.Output.Write("WithEvents ");
- }
- this.OutputTypeNamePair(e.Type, e.Name);
- if (e.InitExpression != null)
- {
- base.Output.Write(" = ");
- base.GenerateExpression(e.InitExpression);
- }
- base.Output.WriteLine("");
- }
- }
- }
-
- protected override void GenerateFieldReferenceExpression(CodeFieldReferenceExpression e)
- {
- if (e.TargetObject != null)
- {
- base.GenerateExpression(e.TargetObject);
- base.Output.Write(".");
- }
- this.OutputIdentifier(e.FieldName);
- }
-
- private void GenerateFormalEventReferenceExpression(CodeEventReferenceExpression e)
- {
- if ((e.TargetObject != null) && !(e.TargetObject is CodeThisReferenceExpression))
- {
- base.GenerateExpression(e.TargetObject);
- base.Output.Write(".");
- }
- this.OutputIdentifier(e.EventName);
- }
-
- protected override void GenerateGotoStatement(CodeGotoStatement e)
- {
- base.Output.Write("goto ");
- base.Output.WriteLine(e.Label);
- }
-
- protected override void GenerateIndexerExpression(CodeIndexerExpression e)
- {
- base.GenerateExpression(e.TargetObject);
- if (e.TargetObject is CodeBaseReferenceExpression)
- {
- base.Output.Write(".Item");
- }
- base.Output.Write("(");
- bool flag = true;
- foreach (CodeExpression expression in e.Indices)
- {
- if (flag)
- {
- flag = false;
- }
- else
- {
- base.Output.Write(", ");
- }
- base.GenerateExpression(expression);
- }
- base.Output.Write(")");
- }
-
- protected override void GenerateIterationStatement(CodeIterationStatement e)
- {
- base.GenerateStatement(e.InitStatement);
- base.Output.Write("Do While ");
- base.GenerateExpression(e.TestExpression);
- base.Output.WriteLine("");
- base.Indent++;
- this.GenerateVBStatements(e.Statements);
- base.GenerateStatement(e.IncrementStatement);
- base.Indent--;
- base.Output.WriteLine("Loop");
- }
-
- protected override void GenerateLabeledStatement(CodeLabeledStatement e)
- {
- base.Indent--;
- base.Output.Write(e.Label);
- base.Output.WriteLine(":");
- base.Indent++;
- if (e.Statement != null)
- {
- base.GenerateStatement(e.Statement);
- }
- }
-
- protected override void GenerateLinePragmaEnd(CodeLinePragma e)
- {
- base.Output.WriteLine("");
- base.Output.WriteLine("#End ExternalSource");
- }
-
- protected override void GenerateLinePragmaStart(CodeLinePragma e)
- {
- base.Output.WriteLine("");
- base.Output.Write("#ExternalSource(\"");
- base.Output.Write(e.FileName);
- base.Output.Write("\",");
- base.Output.Write(e.LineNumber);
- base.Output.WriteLine(")");
- }
-
- protected override void GenerateMethod(CodeMemberMethod e, CodeTypeDeclaration c)
- {
- if ((base.IsCurrentClass || base.IsCurrentStruct) || base.IsCurrentInterface)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- string name = e.Name;
- if (e.PrivateImplementationType != null)
- {
- string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
- e.Name = str2 + "_" + e.Name;
- }
- if (!base.IsCurrentInterface)
- {
- if (e.PrivateImplementationType == null)
- {
- this.OutputMemberAccessModifier(e.Attributes);
- if (this.MethodIsOverloaded(e, c))
- {
- base.Output.Write("Overloads ");
- }
- }
- this.OutputVTableModifier(e.Attributes);
- this.OutputMemberScopeModifier(e.Attributes);
- }
- else
- {
- this.OutputVTableModifier(e.Attributes);
- }
- bool flag = false;
- if ((e.ReturnType.BaseType.Length == 0) || (string.Compare(e.ReturnType.BaseType, typeof(void).FullName, StringComparison.OrdinalIgnoreCase) == 0))
- {
- flag = true;
- }
- if (flag)
- {
- base.Output.Write("Sub ");
- }
- else
- {
- base.Output.Write("Function ");
- }
- this.OutputIdentifier(e.Name);
- this.OutputTypeParameters(e.TypeParameters);
- base.Output.Write("(");
- this.OutputParameters(e.Parameters);
- base.Output.Write(")");
- if (!flag)
- {
- base.Output.Write(" As ");
- if (e.ReturnTypeCustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.ReturnTypeCustomAttributes, true);
- }
- this.OutputType(e.ReturnType);
- this.OutputArrayPostfix(e.ReturnType);
- }
- if (e.ImplementationTypes.Count > 0)
- {
- base.Output.Write(" Implements ");
- bool flag2 = true;
- foreach (CodeTypeReference reference in e.ImplementationTypes)
- {
- if (flag2)
- {
- flag2 = false;
- }
- else
- {
- base.Output.Write(" , ");
- }
- this.OutputType(reference);
- base.Output.Write(".");
- this.OutputIdentifier(name);
- }
- }
- else if (e.PrivateImplementationType != null)
- {
- base.Output.Write(" Implements ");
- this.OutputType(e.PrivateImplementationType);
- base.Output.Write(".");
- this.OutputIdentifier(name);
- }
- base.Output.WriteLine("");
- if (!base.IsCurrentInterface && ((e.Attributes & MemberAttributes.ScopeMask) != MemberAttributes.Abstract))
- {
- base.Indent++;
- this.GenerateVBStatements(e.Statements);
- base.Indent--;
- if (flag)
- {
- base.Output.WriteLine("End Sub");
- }
- else
- {
- base.Output.WriteLine("End Function");
- }
- }
- e.Name = name;
- }
- }
-
- protected override void GenerateMethodInvokeExpression(CodeMethodInvokeExpression e)
- {
- this.GenerateMethodReferenceExpression(e.Method);
- if (e.Parameters.Count > 0)
- {
- base.Output.Write("(");
- this.OutputExpressionList(e.Parameters);
- base.Output.Write(")");
- }
- }
-
- protected override void GenerateMethodReferenceExpression(CodeMethodReferenceExpression e)
- {
- if (e.TargetObject != null)
- {
- base.GenerateExpression(e.TargetObject);
- base.Output.Write(".");
- base.Output.Write(e.MethodName);
- }
- else
- {
- this.OutputIdentifier(e.MethodName);
- }
- if (e.TypeArguments.Count > 0)
- {
- base.Output.Write(this.GetTypeArgumentsOutput(e.TypeArguments));
- }
- }
-
- protected override void GenerateMethodReturnStatement(CodeMethodReturnStatement e)
- {
- if (e.Expression != null)
- {
- base.Output.Write("Return ");
- base.GenerateExpression(e.Expression);
- base.Output.WriteLine("");
- }
- else
- {
- base.Output.WriteLine("Return");
- }
- }
-
- protected override void GenerateNamespace(CodeNamespace e)
- {
- if (this.GetUserData(e, "GenerateImports", true))
- {
- base.GenerateNamespaceImports(e);
- }
- base.Output.WriteLine();
- this.GenerateCommentStatements(e.Comments);
- this.GenerateNamespaceStart(e);
- base.GenerateTypes(e);
- this.GenerateNamespaceEnd(e);
- }
-
- protected override void GenerateNamespaceEnd(CodeNamespace e)
- {
- if ((e.Name != null) && (e.Name.Length > 0))
- {
- base.Indent--;
- base.Output.WriteLine("End Namespace");
- }
- }
-
- protected override void GenerateNamespaceImport(CodeNamespaceImport e)
- {
- base.Output.Write("Imports ");
- this.OutputIdentifier(e.Namespace);
- base.Output.WriteLine("");
- }
-
- protected override void GenerateNamespaceStart(CodeNamespace e)
- {
- if ((e.Name != null) && (e.Name.Length > 0))
- {
- base.Output.Write("Namespace ");
- string[] strArray = e.Name.Split(new char[] { '.' });
- this.OutputIdentifier(strArray[0]);
- for (int i = 1; i < strArray.Length; i++)
- {
- base.Output.Write(".");
- this.OutputIdentifier(strArray[i]);
- }
- base.Output.WriteLine();
- base.Indent++;
- }
- }
-
- private void GenerateNotIsNullExpression(CodeExpression e)
- {
- base.Output.Write("(Not (");
- base.GenerateExpression(e);
- base.Output.Write(") Is ");
- base.Output.Write(this.NullToken);
- base.Output.Write(")");
- }
-
- protected override void GenerateObjectCreateExpression(CodeObjectCreateExpression e)
- {
- base.Output.Write("New ");
- this.OutputType(e.CreateType);
- base.Output.Write("(");
- this.OutputExpressionList(e.Parameters);
- base.Output.Write(")");
- }
-
- protected override void GenerateParameterDeclarationExpression(CodeParameterDeclarationExpression e)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, true);
- }
- this.OutputDirection(e.Direction);
- this.OutputTypeNamePair(e.Type, e.Name);
- }
-
- protected override void GeneratePrimitiveExpression(CodePrimitiveExpression e)
- {
- if (e.Value is char)
- {
- base.Output.Write("Global.Microsoft.VisualBasic.ChrW(" + ((IConvertible)e.Value).ToInt32(CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture) + ")");
- }
- else if (e.Value is sbyte)
- {
- base.Output.Write("CSByte(");
- sbyte num2 = (sbyte)e.Value;
- base.Output.Write(num2.ToString(CultureInfo.InvariantCulture));
- base.Output.Write(")");
- }
- else if (e.Value is ushort)
- {
- ushort num3 = (ushort)e.Value;
- base.Output.Write(num3.ToString(CultureInfo.InvariantCulture));
- base.Output.Write("US");
- }
- else if (e.Value is uint)
- {
- uint num4 = (uint)e.Value;
- base.Output.Write(num4.ToString(CultureInfo.InvariantCulture));
- base.Output.Write("UI");
- }
- else if (e.Value is ulong)
- {
- ulong num5 = (ulong)e.Value;
- base.Output.Write(num5.ToString(CultureInfo.InvariantCulture));
- base.Output.Write("UL");
- }
- else
- {
- base.GeneratePrimitiveExpression(e);
- }
- }
-
- protected override void GenerateProperty(CodeMemberProperty e, CodeTypeDeclaration c)
- {
- if ((base.IsCurrentClass || base.IsCurrentStruct) || base.IsCurrentInterface)
- {
- if (e.CustomAttributes.Count > 0)
- {
- this.OutputAttributes(e.CustomAttributes, false);
- }
- string name = e.Name;
- if (e.PrivateImplementationType != null)
- {
- string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
- e.Name = str2 + "_" + e.Name;
- }
- if (!base.IsCurrentInterface)
- {
- if (e.PrivateImplementationType == null)
- {
- this.OutputMemberAccessModifier(e.Attributes);
- if (this.PropertyIsOverloaded(e, c))
- {
- …
Large files files are truncated, but you can click here to view the full file