PageRenderTime 79ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/LinqToCodedomProject/LinqToCodedom/Generator/VBCodeGenerator.cs

#
C# | 2572 lines | 2422 code | 147 blank | 3 comment | 481 complexity | c5f764d5deec43e770fd9b48223036ce MD5 | raw file
  1. using System;
  2. using System.CodeDom;
  3. using System.CodeDom.Compiler;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.Globalization;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime;
  12. using System.Security;
  13. using System.Security.Permissions;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. namespace LinqToCodedom.Generator
  17. {
  18. public class VBCodeGenerator : CodeCompiler
  19. {
  20. // Fields
  21. private static readonly string[][] keywords;
  22. 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);
  23. private const int MaxLineLength = 80;
  24. private static volatile Regex outputReg;
  25. private IDictionary<string, string> provOptions;
  26. private int statementDepth;
  27. // Methods
  28. static VBCodeGenerator()
  29. {
  30. string[][] strArray = new string[16][];
  31. strArray[1] = new string[] { "as", "do", "if", "in", "is", "me", "of", "on", "or", "to" };
  32. strArray[2] = new string[] { "and", "dim", "end", "for", "get", "let", "lib", "mod", "new", "not", "rem", "set", "sub", "try", "xor" };
  33. strArray[3] = new string[] {
  34. "ansi", "auto", "byte", "call", "case", "cdbl", "cdec", "char", "cint", "clng", "cobj", "csng", "cstr", "date", "each", "else",
  35. "enum", "exit", "goto", "like", "long", "loop", "next", "step", "stop", "then", "true", "wend", "when", "with"
  36. };
  37. strArray[4] = new string[] {
  38. "alias", "byref", "byval", "catch", "cbool", "cbyte", "cchar", "cdate", "class", "const", "ctype", "cuint", "culng", "endif", "erase", "error",
  39. "event", "false", "gosub", "isnot", "redim", "sbyte", "short", "throw", "ulong", "until", "using", "while"
  40. };
  41. strArray[5] = new string[] {
  42. "csbyte", "cshort", "double", "elseif", "friend", "global", "module", "mybase", "object", "option", "orelse", "public", "resume", "return", "select", "shared",
  43. "single", "static", "string", "typeof", "ushort"
  44. };
  45. strArray[6] = new string[] {
  46. "andalso", "boolean", "cushort", "decimal", "declare", "default", "finally", "gettype", "handles", "imports", "integer", "myclass", "nothing", "partial", "private", "shadows",
  47. "trycast", "unicode", "variant"
  48. };
  49. strArray[7] = new string[] { "assembly", "continue", "delegate", "function", "inherits", "operator", "optional", "preserve", "property", "readonly", "synclock", "uinteger", "widening" };
  50. strArray[8] = new string[] { "addressof", "interface", "namespace", "narrowing", "overloads", "overrides", "protected", "structure", "writeonly" };
  51. strArray[9] = new string[] { "addhandler", "directcast", "implements", "paramarray", "raiseevent", "withevents" };
  52. strArray[10] = new string[] { "mustinherit", "overridable" };
  53. strArray[11] = new string[] { "mustoverride" };
  54. strArray[12] = new string[] { "removehandler" };
  55. strArray[13] = new string[] { "class_finalize", "notinheritable", "notoverridable" };
  56. strArray[15] = new string[] { "class_initialize" };
  57. keywords = strArray;
  58. }
  59. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  60. internal VBCodeGenerator()
  61. {
  62. }
  63. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  64. internal VBCodeGenerator(IDictionary<string, string> providerOptions)
  65. {
  66. this.provOptions = providerOptions;
  67. }
  68. protected bool AllowLateBound(CodeCompileUnit e)
  69. {
  70. object obj2 = e.UserData["AllowLateBound"];
  71. if ((obj2 != null) && (obj2 is bool))
  72. {
  73. return (bool)obj2;
  74. }
  75. return true;
  76. }
  77. private static void AppendEscapedChar(StringBuilder b, char value)
  78. {
  79. b.Append("&Global.Microsoft.VisualBasic.ChrW(");
  80. b.Append(((int)value).ToString(CultureInfo.InvariantCulture));
  81. b.Append(")");
  82. }
  83. protected override string CmdArgsFromParameters(CompilerParameters options)
  84. {
  85. string str3;
  86. using (StringEnumerator enumerator = options.ReferencedAssemblies.GetEnumerator())
  87. {
  88. while (enumerator.MoveNext())
  89. {
  90. if (string.IsNullOrEmpty(enumerator.Current))
  91. {
  92. throw new ArgumentException(SR.GetString("NullOrEmpty_Value_in_Property", new object[] { "ReferencedAssemblies" }), "options");
  93. }
  94. }
  95. }
  96. StringBuilder builder = new StringBuilder(128);
  97. if (options.GenerateExecutable)
  98. {
  99. builder.Append("/t:exe ");
  100. if ((options.MainClass != null) && (options.MainClass.Length > 0))
  101. {
  102. builder.Append("/main:");
  103. builder.Append(options.MainClass);
  104. builder.Append(" ");
  105. }
  106. }
  107. else
  108. {
  109. builder.Append("/t:library ");
  110. }
  111. builder.Append("/utf8output ");
  112. string coreAssemblyFileName = options.CoreAssemblyFileName;
  113. if (string.IsNullOrWhiteSpace(options.CoreAssemblyFileName) && CodeDomProvider.TryGetProbableCoreAssemblyFilePath(options, out str3))
  114. {
  115. coreAssemblyFileName = str3;
  116. }
  117. if (!string.IsNullOrWhiteSpace(coreAssemblyFileName))
  118. {
  119. string path = coreAssemblyFileName.Trim();
  120. string directoryName = Path.GetDirectoryName(path);
  121. builder.Append("/nostdlib ");
  122. builder.Append("/sdkpath:\"").Append(directoryName).Append("\" ");
  123. builder.Append("/R:\"").Append(path).Append("\" ");
  124. }
  125. foreach (string str6 in options.ReferencedAssemblies)
  126. {
  127. string fileName = Path.GetFileName(str6);
  128. if ((string.Compare(fileName, "Microsoft.VisualBasic.dll", StringComparison.OrdinalIgnoreCase) != 0) && (string.Compare(fileName, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) != 0))
  129. {
  130. builder.Append("/R:");
  131. builder.Append("\"");
  132. builder.Append(str6);
  133. builder.Append("\"");
  134. builder.Append(" ");
  135. }
  136. }
  137. builder.Append("/out:");
  138. builder.Append("\"");
  139. builder.Append(options.OutputAssembly);
  140. builder.Append("\"");
  141. builder.Append(" ");
  142. if (options.IncludeDebugInformation)
  143. {
  144. builder.Append("/D:DEBUG=1 ");
  145. builder.Append("/debug+ ");
  146. }
  147. else
  148. {
  149. builder.Append("/debug- ");
  150. }
  151. if (options.Win32Resource != null)
  152. {
  153. builder.Append("/win32resource:\"" + options.Win32Resource + "\" ");
  154. }
  155. foreach (string str8 in options.EmbeddedResources)
  156. {
  157. builder.Append("/res:\"");
  158. builder.Append(str8);
  159. builder.Append("\" ");
  160. }
  161. foreach (string str9 in options.LinkedResources)
  162. {
  163. builder.Append("/linkres:\"");
  164. builder.Append(str9);
  165. builder.Append("\" ");
  166. }
  167. if (options.TreatWarningsAsErrors)
  168. {
  169. builder.Append("/warnaserror+ ");
  170. }
  171. if (options.CompilerOptions != null)
  172. {
  173. builder.Append(options.CompilerOptions + " ");
  174. }
  175. return builder.ToString();
  176. }
  177. protected override void ContinueOnNewLine(string st)
  178. {
  179. base.Output.Write(st);
  180. base.Output.WriteLine(" _");
  181. }
  182. protected override string CreateEscapedIdentifier(string name)
  183. {
  184. if (IsKeyword(name))
  185. {
  186. return ("[" + name + "]");
  187. }
  188. return name;
  189. }
  190. protected override string CreateValidIdentifier(string name)
  191. {
  192. if (IsKeyword(name))
  193. {
  194. return ("_" + name);
  195. }
  196. return name;
  197. }
  198. private void EnsureInDoubleQuotes(ref bool fInDoubleQuotes, StringBuilder b)
  199. {
  200. if (!fInDoubleQuotes)
  201. {
  202. b.Append("&\"");
  203. fInDoubleQuotes = true;
  204. }
  205. }
  206. private void EnsureNotInDoubleQuotes(ref bool fInDoubleQuotes, StringBuilder b)
  207. {
  208. if (fInDoubleQuotes)
  209. {
  210. b.Append("\"");
  211. fInDoubleQuotes = false;
  212. }
  213. }
  214. protected override CompilerResults FromFileBatch(CompilerParameters options, string[] fileNames)
  215. {
  216. if (options == null)
  217. {
  218. throw new ArgumentNullException("options");
  219. }
  220. if (fileNames == null)
  221. {
  222. throw new ArgumentNullException("fileNames");
  223. }
  224. new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
  225. string outputFile = null;
  226. int nativeReturnValue = 0;
  227. CompilerResults results = new CompilerResults(options.TempFiles);
  228. new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert();
  229. try
  230. {
  231. results.Evidence = options.Evidence;
  232. }
  233. finally
  234. {
  235. CodeAccessPermission.RevertAssert();
  236. }
  237. bool flag = false;
  238. string fileExtension = options.GenerateExecutable ? "exe" : "dll";
  239. string str3 = '.' + fileExtension;
  240. if ((options.OutputAssembly == null) || (options.OutputAssembly.Length == 0))
  241. {
  242. options.OutputAssembly = results.TempFiles.AddExtension(fileExtension, !options.GenerateInMemory);
  243. new FileStream(options.OutputAssembly, FileMode.Create, FileAccess.ReadWrite).Close();
  244. flag = true;
  245. }
  246. string outputAssembly = options.OutputAssembly;
  247. if (!Path.GetExtension(outputAssembly).Equals(str3, StringComparison.OrdinalIgnoreCase))
  248. {
  249. outputAssembly = outputAssembly + str3;
  250. }
  251. string str5 = "pdb";
  252. if ((options.CompilerOptions != null) && (options.CompilerOptions.IndexOf("/debug:pdbonly", StringComparison.OrdinalIgnoreCase) != -1))
  253. {
  254. results.TempFiles.AddExtension(str5, true);
  255. }
  256. else
  257. {
  258. results.TempFiles.AddExtension(str5);
  259. }
  260. string cmdArgs = this.CmdArgsFromParameters(options) + " " + CodeCompiler.JoinStringArray(fileNames, " ");
  261. string responseFileCmdArgs = this.GetResponseFileCmdArgs(options, cmdArgs);
  262. string trueArgs = null;
  263. if (responseFileCmdArgs != null)
  264. {
  265. trueArgs = cmdArgs;
  266. cmdArgs = responseFileCmdArgs;
  267. }
  268. base.Compile(options, RedistVersionInfo.GetCompilerPath(this.provOptions, this.CompilerName), this.CompilerName, cmdArgs, ref outputFile, ref nativeReturnValue, trueArgs);
  269. results.NativeCompilerReturnValue = nativeReturnValue;
  270. if ((nativeReturnValue != 0) || (options.WarningLevel > 0))
  271. {
  272. byte[] bytes = ReadAllBytes(outputFile, FileShare.ReadWrite);
  273. foreach (string str10 in Regex.Split(Encoding.UTF8.GetString(bytes), @"\r\n"))
  274. {
  275. results.Output.Add(str10);
  276. this.ProcessCompilerOutputLine(results, str10);
  277. }
  278. if ((nativeReturnValue != 0) && flag)
  279. {
  280. File.Delete(outputAssembly);
  281. }
  282. }
  283. if (!results.Errors.HasErrors && options.GenerateInMemory)
  284. {
  285. FileStream stream = new FileStream(outputAssembly, FileMode.Open, FileAccess.Read, FileShare.Read);
  286. try
  287. {
  288. int length = (int)stream.Length;
  289. byte[] buffer = new byte[length];
  290. stream.Read(buffer, 0, length);
  291. new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Assert();
  292. try
  293. {
  294. results.CompiledAssembly = Assembly.Load(buffer, null, options.Evidence);
  295. }
  296. finally
  297. {
  298. CodeAccessPermission.RevertAssert();
  299. }
  300. return results;
  301. }
  302. finally
  303. {
  304. stream.Close();
  305. }
  306. }
  307. results.PathToAssembly = outputAssembly;
  308. return results;
  309. }
  310. protected override void GenerateArgumentReferenceExpression(CodeArgumentReferenceExpression e)
  311. {
  312. this.OutputIdentifier(e.ParameterName);
  313. }
  314. protected override void GenerateArrayCreateExpression(CodeArrayCreateExpression e)
  315. {
  316. base.Output.Write("New ");
  317. CodeExpressionCollection initializers = e.Initializers;
  318. if (initializers.Count > 0)
  319. {
  320. string typeOutput = this.GetTypeOutput(e.CreateType);
  321. base.Output.Write(typeOutput);
  322. if (typeOutput.IndexOf('(') == -1)
  323. {
  324. base.Output.Write("()");
  325. }
  326. base.Output.Write(" {");
  327. base.Indent++;
  328. this.OutputExpressionList(initializers);
  329. base.Indent--;
  330. base.Output.Write("}");
  331. }
  332. else
  333. {
  334. string str2 = this.GetTypeOutput(e.CreateType);
  335. int index = str2.IndexOf('(');
  336. if (index == -1)
  337. {
  338. base.Output.Write(str2);
  339. base.Output.Write('(');
  340. }
  341. else
  342. {
  343. base.Output.Write(str2.Substring(0, index + 1));
  344. }
  345. if (e.SizeExpression != null)
  346. {
  347. base.Output.Write("(");
  348. base.GenerateExpression(e.SizeExpression);
  349. base.Output.Write(") - 1");
  350. }
  351. else
  352. {
  353. base.Output.Write((int)(e.Size - 1));
  354. }
  355. if (index == -1)
  356. {
  357. base.Output.Write(')');
  358. }
  359. else
  360. {
  361. base.Output.Write(str2.Substring(index + 1));
  362. }
  363. base.Output.Write(" {}");
  364. }
  365. }
  366. protected override void GenerateArrayIndexerExpression(CodeArrayIndexerExpression e)
  367. {
  368. base.GenerateExpression(e.TargetObject);
  369. base.Output.Write("(");
  370. bool flag = true;
  371. foreach (CodeExpression expression in e.Indices)
  372. {
  373. if (flag)
  374. {
  375. flag = false;
  376. }
  377. else
  378. {
  379. base.Output.Write(", ");
  380. }
  381. base.GenerateExpression(expression);
  382. }
  383. base.Output.Write(")");
  384. }
  385. protected override void GenerateAssignStatement(CodeAssignStatement e)
  386. {
  387. base.GenerateExpression(e.Left);
  388. base.Output.Write(" = ");
  389. base.GenerateExpression(e.Right);
  390. base.Output.WriteLine("");
  391. }
  392. protected override void GenerateAttachEventStatement(CodeAttachEventStatement e)
  393. {
  394. base.Output.Write("AddHandler ");
  395. this.GenerateFormalEventReferenceExpression(e.Event);
  396. base.Output.Write(", ");
  397. base.GenerateExpression(e.Listener);
  398. base.Output.WriteLine("");
  399. }
  400. protected override void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes)
  401. {
  402. base.Output.Write(">");
  403. }
  404. protected override void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes)
  405. {
  406. base.Output.Write("<");
  407. }
  408. protected override void GenerateBaseReferenceExpression(CodeBaseReferenceExpression e)
  409. {
  410. base.Output.Write("MyBase");
  411. }
  412. protected override void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression e)
  413. {
  414. if (e.Operator != CodeBinaryOperatorType.IdentityInequality)
  415. {
  416. base.GenerateBinaryOperatorExpression(e);
  417. }
  418. else if ((e.Right is CodePrimitiveExpression) && (((CodePrimitiveExpression)e.Right).Value == null))
  419. {
  420. this.GenerateNotIsNullExpression(e.Left);
  421. }
  422. else if ((e.Left is CodePrimitiveExpression) && (((CodePrimitiveExpression)e.Left).Value == null))
  423. {
  424. this.GenerateNotIsNullExpression(e.Right);
  425. }
  426. else
  427. {
  428. base.GenerateBinaryOperatorExpression(e);
  429. }
  430. }
  431. protected override void GenerateCastExpression(CodeCastExpression e)
  432. {
  433. base.Output.Write("CType(");
  434. base.GenerateExpression(e.Expression);
  435. base.Output.Write(",");
  436. this.OutputType(e.TargetType);
  437. this.OutputArrayPostfix(e.TargetType);
  438. base.Output.Write(")");
  439. }
  440. private void GenerateChecksumPragma(CodeChecksumPragma checksumPragma)
  441. {
  442. base.Output.Write("#ExternalChecksum(\"");
  443. base.Output.Write(checksumPragma.FileName);
  444. base.Output.Write("\",\"");
  445. base.Output.Write(checksumPragma.ChecksumAlgorithmId.ToString("B", CultureInfo.InvariantCulture));
  446. base.Output.Write("\",\"");
  447. if (checksumPragma.ChecksumData != null)
  448. {
  449. foreach (byte num in checksumPragma.ChecksumData)
  450. {
  451. base.Output.Write(num.ToString("X2", CultureInfo.InvariantCulture));
  452. }
  453. }
  454. base.Output.WriteLine("\")");
  455. }
  456. private void GenerateCodeRegionDirective(CodeRegionDirective regionDirective)
  457. {
  458. if (!this.IsGeneratingStatements())
  459. {
  460. if (regionDirective.RegionMode == CodeRegionMode.Start)
  461. {
  462. base.Output.Write("#Region \"");
  463. base.Output.Write(regionDirective.RegionText);
  464. base.Output.WriteLine("\"");
  465. }
  466. else if (regionDirective.RegionMode == CodeRegionMode.End)
  467. {
  468. base.Output.WriteLine("#End Region");
  469. }
  470. }
  471. }
  472. protected override void GenerateComment(CodeComment e)
  473. {
  474. string str = e.DocComment ? "'''" : "'";
  475. base.Output.Write(str);
  476. string text = e.Text;
  477. for (int i = 0; i < text.Length; i++)
  478. {
  479. base.Output.Write(text[i]);
  480. if (text[i] == '\r')
  481. {
  482. if ((i < (text.Length - 1)) && (text[i + 1] == '\n'))
  483. {
  484. base.Output.Write('\n');
  485. i++;
  486. }
  487. ((IndentedTextWriter)base.Output).InternalOutputTabs();
  488. base.Output.Write(str);
  489. }
  490. else if (text[i] == '\n')
  491. {
  492. ((IndentedTextWriter)base.Output).InternalOutputTabs();
  493. base.Output.Write(str);
  494. }
  495. else if (((text[i] == '\u2028') || (text[i] == '\u2029')) || (text[i] == '\x0085'))
  496. {
  497. base.Output.Write(str);
  498. }
  499. }
  500. base.Output.WriteLine();
  501. }
  502. protected override void GenerateCommentStatements(CodeCommentStatementCollection e)
  503. {
  504. foreach (CodeCommentStatement statement in e)
  505. {
  506. if (!this.IsDocComment(statement))
  507. {
  508. this.GenerateCommentStatement(statement);
  509. }
  510. }
  511. foreach (CodeCommentStatement statement2 in e)
  512. {
  513. if (this.IsDocComment(statement2))
  514. {
  515. this.GenerateCommentStatement(statement2);
  516. }
  517. }
  518. }
  519. protected override void GenerateCompileUnit(CodeCompileUnit e)
  520. {
  521. this.GenerateCompileUnitStart(e);
  522. SortedList list = new SortedList(StringComparer.OrdinalIgnoreCase);
  523. foreach (CodeNamespace namespace2 in e.Namespaces)
  524. {
  525. namespace2.UserData["GenerateImports"] = false;
  526. foreach (CodeNamespaceImport import in namespace2.Imports)
  527. {
  528. if (!list.Contains(import.Namespace))
  529. {
  530. list.Add(import.Namespace, import.Namespace);
  531. }
  532. }
  533. }
  534. foreach (string str in list.Keys)
  535. {
  536. base.Output.Write("Imports ");
  537. this.OutputIdentifier(str);
  538. base.Output.WriteLine("");
  539. }
  540. if (e.AssemblyCustomAttributes.Count > 0)
  541. {
  542. this.OutputAttributes(e.AssemblyCustomAttributes, false, "Assembly: ", true);
  543. }
  544. base.GenerateNamespaces(e);
  545. this.GenerateCompileUnitEnd(e);
  546. }
  547. protected override void GenerateCompileUnitStart(CodeCompileUnit e)
  548. {
  549. base.GenerateCompileUnitStart(e);
  550. base.Output.WriteLine("'------------------------------------------------------------------------------");
  551. base.Output.Write("' <");
  552. base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line1"));
  553. base.Output.Write("' ");
  554. base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line2"));
  555. base.Output.Write("' ");
  556. base.Output.Write(SR.GetString("AutoGen_Comment_Line3"));
  557. base.Output.WriteLine(Environment.Version.ToString());
  558. base.Output.WriteLine("'");
  559. base.Output.Write("' ");
  560. base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line4"));
  561. base.Output.Write("' ");
  562. base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line5"));
  563. base.Output.Write("' </");
  564. base.Output.WriteLine(SR.GetString("AutoGen_Comment_Line1"));
  565. base.Output.WriteLine("'------------------------------------------------------------------------------");
  566. base.Output.WriteLine("");
  567. if (this.AllowLateBound(e))
  568. {
  569. base.Output.WriteLine("Option Strict Off");
  570. }
  571. else
  572. {
  573. base.Output.WriteLine("Option Strict On");
  574. }
  575. if (!this.RequireVariableDeclaration(e))
  576. {
  577. base.Output.WriteLine("Option Explicit Off");
  578. }
  579. else
  580. {
  581. base.Output.WriteLine("Option Explicit On");
  582. }
  583. base.Output.WriteLine();
  584. }
  585. protected override void GenerateConditionStatement(CodeConditionStatement e)
  586. {
  587. base.Output.Write("If ");
  588. base.GenerateExpression(e.Condition);
  589. base.Output.WriteLine(" Then");
  590. base.Indent++;
  591. this.GenerateVBStatements(e.TrueStatements);
  592. base.Indent--;
  593. if (e.FalseStatements.Count > 0)
  594. {
  595. base.Output.Write("Else");
  596. base.Output.WriteLine("");
  597. base.Indent++;
  598. this.GenerateVBStatements(e.FalseStatements);
  599. base.Indent--;
  600. }
  601. base.Output.WriteLine("End If");
  602. }
  603. protected override void GenerateConstructor(CodeConstructor e, CodeTypeDeclaration c)
  604. {
  605. if (base.IsCurrentClass || base.IsCurrentStruct)
  606. {
  607. if (e.CustomAttributes.Count > 0)
  608. {
  609. this.OutputAttributes(e.CustomAttributes, false);
  610. }
  611. this.OutputMemberAccessModifier(e.Attributes);
  612. base.Output.Write("Sub New(");
  613. this.OutputParameters(e.Parameters);
  614. base.Output.WriteLine(")");
  615. base.Indent++;
  616. CodeExpressionCollection baseConstructorArgs = e.BaseConstructorArgs;
  617. CodeExpressionCollection chainedConstructorArgs = e.ChainedConstructorArgs;
  618. if (chainedConstructorArgs.Count > 0)
  619. {
  620. base.Output.Write("Me.New(");
  621. this.OutputExpressionList(chainedConstructorArgs);
  622. base.Output.Write(")");
  623. base.Output.WriteLine("");
  624. }
  625. else if (baseConstructorArgs.Count > 0)
  626. {
  627. base.Output.Write("MyBase.New(");
  628. this.OutputExpressionList(baseConstructorArgs);
  629. base.Output.Write(")");
  630. base.Output.WriteLine("");
  631. }
  632. else if (base.IsCurrentClass)
  633. {
  634. base.Output.WriteLine("MyBase.New");
  635. }
  636. this.GenerateVBStatements(e.Statements);
  637. base.Indent--;
  638. base.Output.WriteLine("End Sub");
  639. }
  640. }
  641. protected override void GenerateDecimalValue(decimal d)
  642. {
  643. base.Output.Write(d.ToString(CultureInfo.InvariantCulture));
  644. base.Output.Write('D');
  645. }
  646. protected override void GenerateDefaultValueExpression(CodeDefaultValueExpression e)
  647. {
  648. base.Output.Write("CType(Nothing, " + this.GetTypeOutput(e.Type) + ")");
  649. }
  650. protected override void GenerateDelegateCreateExpression(CodeDelegateCreateExpression e)
  651. {
  652. base.Output.Write("AddressOf ");
  653. base.GenerateExpression(e.TargetObject);
  654. base.Output.Write(".");
  655. this.OutputIdentifier(e.MethodName);
  656. }
  657. protected override void GenerateDelegateInvokeExpression(CodeDelegateInvokeExpression e)
  658. {
  659. if (e.TargetObject != null)
  660. {
  661. if (e.TargetObject is CodeEventReferenceExpression)
  662. {
  663. base.Output.Write("RaiseEvent ");
  664. this.GenerateFormalEventReferenceExpression((CodeEventReferenceExpression)e.TargetObject);
  665. }
  666. else
  667. {
  668. base.GenerateExpression(e.TargetObject);
  669. }
  670. }
  671. if (e.Parameters.Count > 0)
  672. {
  673. base.Output.Write("(");
  674. this.OutputExpressionList(e.Parameters);
  675. base.Output.Write(")");
  676. }
  677. }
  678. protected override void GenerateDirectionExpression(CodeDirectionExpression e)
  679. {
  680. base.GenerateExpression(e.Expression);
  681. }
  682. protected override void GenerateDirectives(CodeDirectiveCollection directives)
  683. {
  684. for (int i = 0; i < directives.Count; i++)
  685. {
  686. CodeDirective directive = directives[i];
  687. if (directive is CodeChecksumPragma)
  688. {
  689. this.GenerateChecksumPragma((CodeChecksumPragma)directive);
  690. }
  691. else if (directive is CodeRegionDirective)
  692. {
  693. this.GenerateCodeRegionDirective((CodeRegionDirective)directive);
  694. }
  695. }
  696. }
  697. protected override void GenerateDoubleValue(double d)
  698. {
  699. if (double.IsNaN(d))
  700. {
  701. base.Output.Write("Double.NaN");
  702. }
  703. else if (double.IsNegativeInfinity(d))
  704. {
  705. base.Output.Write("Double.NegativeInfinity");
  706. }
  707. else if (double.IsPositiveInfinity(d))
  708. {
  709. base.Output.Write("Double.PositiveInfinity");
  710. }
  711. else
  712. {
  713. base.Output.Write(d.ToString("R", CultureInfo.InvariantCulture));
  714. base.Output.Write("R");
  715. }
  716. }
  717. protected override void GenerateEntryPointMethod(CodeEntryPointMethod e, CodeTypeDeclaration c)
  718. {
  719. if (e.CustomAttributes.Count > 0)
  720. {
  721. this.OutputAttributes(e.CustomAttributes, false);
  722. }
  723. base.Output.WriteLine("Public Shared Sub Main()");
  724. base.Indent++;
  725. this.GenerateVBStatements(e.Statements);
  726. base.Indent--;
  727. base.Output.WriteLine("End Sub");
  728. }
  729. protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c)
  730. {
  731. if (!base.IsCurrentDelegate && !base.IsCurrentEnum)
  732. {
  733. if (e.CustomAttributes.Count > 0)
  734. {
  735. this.OutputAttributes(e.CustomAttributes, false);
  736. }
  737. string name = e.Name;
  738. if (e.PrivateImplementationType != null)
  739. {
  740. string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
  741. e.Name = str2 + "_" + e.Name;
  742. }
  743. this.OutputMemberAccessModifier(e.Attributes);
  744. base.Output.Write("Event ");
  745. this.OutputTypeNamePair(e.Type, e.Name);
  746. if (e.ImplementationTypes.Count > 0)
  747. {
  748. base.Output.Write(" Implements ");
  749. bool flag = true;
  750. foreach (CodeTypeReference reference in e.ImplementationTypes)
  751. {
  752. if (flag)
  753. {
  754. flag = false;
  755. }
  756. else
  757. {
  758. base.Output.Write(" , ");
  759. }
  760. this.OutputType(reference);
  761. base.Output.Write(".");
  762. this.OutputIdentifier(name);
  763. }
  764. }
  765. else if (e.PrivateImplementationType != null)
  766. {
  767. base.Output.Write(" Implements ");
  768. this.OutputType(e.PrivateImplementationType);
  769. base.Output.Write(".");
  770. this.OutputIdentifier(name);
  771. }
  772. base.Output.WriteLine("");
  773. }
  774. }
  775. protected override void GenerateEventReferenceExpression(CodeEventReferenceExpression e)
  776. {
  777. if (e.TargetObject != null)
  778. {
  779. bool flag = e.TargetObject is CodeThisReferenceExpression;
  780. base.GenerateExpression(e.TargetObject);
  781. base.Output.Write(".");
  782. if (flag)
  783. {
  784. base.Output.Write(e.EventName + "Event");
  785. }
  786. else
  787. {
  788. base.Output.Write(e.EventName);
  789. }
  790. }
  791. else
  792. {
  793. this.OutputIdentifier(e.EventName + "Event");
  794. }
  795. }
  796. protected override void GenerateExpressionStatement(CodeExpressionStatement e)
  797. {
  798. base.GenerateExpression(e.Expression);
  799. base.Output.WriteLine("");
  800. }
  801. protected override void GenerateField(CodeMemberField e)
  802. {
  803. if (!base.IsCurrentDelegate && !base.IsCurrentInterface)
  804. {
  805. if (base.IsCurrentEnum)
  806. {
  807. if (e.CustomAttributes.Count > 0)
  808. {
  809. this.OutputAttributes(e.CustomAttributes, false);
  810. }
  811. this.OutputIdentifier(e.Name);
  812. if (e.InitExpression != null)
  813. {
  814. base.Output.Write(" = ");
  815. base.GenerateExpression(e.InitExpression);
  816. }
  817. base.Output.WriteLine("");
  818. }
  819. else
  820. {
  821. if (e.CustomAttributes.Count > 0)
  822. {
  823. this.OutputAttributes(e.CustomAttributes, false);
  824. }
  825. this.OutputMemberAccessModifier(e.Attributes);
  826. this.OutputVTableModifier(e.Attributes);
  827. this.OutputFieldScopeModifier(e.Attributes);
  828. if (this.GetUserData(e, "WithEvents", false))
  829. {
  830. base.Output.Write("WithEvents ");
  831. }
  832. this.OutputTypeNamePair(e.Type, e.Name);
  833. if (e.InitExpression != null)
  834. {
  835. base.Output.Write(" = ");
  836. base.GenerateExpression(e.InitExpression);
  837. }
  838. base.Output.WriteLine("");
  839. }
  840. }
  841. }
  842. protected override void GenerateFieldReferenceExpression(CodeFieldReferenceExpression e)
  843. {
  844. if (e.TargetObject != null)
  845. {
  846. base.GenerateExpression(e.TargetObject);
  847. base.Output.Write(".");
  848. }
  849. this.OutputIdentifier(e.FieldName);
  850. }
  851. private void GenerateFormalEventReferenceExpression(CodeEventReferenceExpression e)
  852. {
  853. if ((e.TargetObject != null) && !(e.TargetObject is CodeThisReferenceExpression))
  854. {
  855. base.GenerateExpression(e.TargetObject);
  856. base.Output.Write(".");
  857. }
  858. this.OutputIdentifier(e.EventName);
  859. }
  860. protected override void GenerateGotoStatement(CodeGotoStatement e)
  861. {
  862. base.Output.Write("goto ");
  863. base.Output.WriteLine(e.Label);
  864. }
  865. protected override void GenerateIndexerExpression(CodeIndexerExpression e)
  866. {
  867. base.GenerateExpression(e.TargetObject);
  868. if (e.TargetObject is CodeBaseReferenceExpression)
  869. {
  870. base.Output.Write(".Item");
  871. }
  872. base.Output.Write("(");
  873. bool flag = true;
  874. foreach (CodeExpression expression in e.Indices)
  875. {
  876. if (flag)
  877. {
  878. flag = false;
  879. }
  880. else
  881. {
  882. base.Output.Write(", ");
  883. }
  884. base.GenerateExpression(expression);
  885. }
  886. base.Output.Write(")");
  887. }
  888. protected override void GenerateIterationStatement(CodeIterationStatement e)
  889. {
  890. base.GenerateStatement(e.InitStatement);
  891. base.Output.Write("Do While ");
  892. base.GenerateExpression(e.TestExpression);
  893. base.Output.WriteLine("");
  894. base.Indent++;
  895. this.GenerateVBStatements(e.Statements);
  896. base.GenerateStatement(e.IncrementStatement);
  897. base.Indent--;
  898. base.Output.WriteLine("Loop");
  899. }
  900. protected override void GenerateLabeledStatement(CodeLabeledStatement e)
  901. {
  902. base.Indent--;
  903. base.Output.Write(e.Label);
  904. base.Output.WriteLine(":");
  905. base.Indent++;
  906. if (e.Statement != null)
  907. {
  908. base.GenerateStatement(e.Statement);
  909. }
  910. }
  911. protected override void GenerateLinePragmaEnd(CodeLinePragma e)
  912. {
  913. base.Output.WriteLine("");
  914. base.Output.WriteLine("#End ExternalSource");
  915. }
  916. protected override void GenerateLinePragmaStart(CodeLinePragma e)
  917. {
  918. base.Output.WriteLine("");
  919. base.Output.Write("#ExternalSource(\"");
  920. base.Output.Write(e.FileName);
  921. base.Output.Write("\",");
  922. base.Output.Write(e.LineNumber);
  923. base.Output.WriteLine(")");
  924. }
  925. protected override void GenerateMethod(CodeMemberMethod e, CodeTypeDeclaration c)
  926. {
  927. if ((base.IsCurrentClass || base.IsCurrentStruct) || base.IsCurrentInterface)
  928. {
  929. if (e.CustomAttributes.Count > 0)
  930. {
  931. this.OutputAttributes(e.CustomAttributes, false);
  932. }
  933. string name = e.Name;
  934. if (e.PrivateImplementationType != null)
  935. {
  936. string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
  937. e.Name = str2 + "_" + e.Name;
  938. }
  939. if (!base.IsCurrentInterface)
  940. {
  941. if (e.PrivateImplementationType == null)
  942. {
  943. this.OutputMemberAccessModifier(e.Attributes);
  944. if (this.MethodIsOverloaded(e, c))
  945. {
  946. base.Output.Write("Overloads ");
  947. }
  948. }
  949. this.OutputVTableModifier(e.Attributes);
  950. this.OutputMemberScopeModifier(e.Attributes);
  951. }
  952. else
  953. {
  954. this.OutputVTableModifier(e.Attributes);
  955. }
  956. bool flag = false;
  957. if ((e.ReturnType.BaseType.Length == 0) || (string.Compare(e.ReturnType.BaseType, typeof(void).FullName, StringComparison.OrdinalIgnoreCase) == 0))
  958. {
  959. flag = true;
  960. }
  961. if (flag)
  962. {
  963. base.Output.Write("Sub ");
  964. }
  965. else
  966. {
  967. base.Output.Write("Function ");
  968. }
  969. this.OutputIdentifier(e.Name);
  970. this.OutputTypeParameters(e.TypeParameters);
  971. base.Output.Write("(");
  972. this.OutputParameters(e.Parameters);
  973. base.Output.Write(")");
  974. if (!flag)
  975. {
  976. base.Output.Write(" As ");
  977. if (e.ReturnTypeCustomAttributes.Count > 0)
  978. {
  979. this.OutputAttributes(e.ReturnTypeCustomAttributes, true);
  980. }
  981. this.OutputType(e.ReturnType);
  982. this.OutputArrayPostfix(e.ReturnType);
  983. }
  984. if (e.ImplementationTypes.Count > 0)
  985. {
  986. base.Output.Write(" Implements ");
  987. bool flag2 = true;
  988. foreach (CodeTypeReference reference in e.ImplementationTypes)
  989. {
  990. if (flag2)
  991. {
  992. flag2 = false;
  993. }
  994. else
  995. {
  996. base.Output.Write(" , ");
  997. }
  998. this.OutputType(reference);
  999. base.Output.Write(".");
  1000. this.OutputIdentifier(name);
  1001. }
  1002. }
  1003. else if (e.PrivateImplementationType != null)
  1004. {
  1005. base.Output.Write(" Implements ");
  1006. this.OutputType(e.PrivateImplementationType);
  1007. base.Output.Write(".");
  1008. this.OutputIdentifier(name);
  1009. }
  1010. base.Output.WriteLine("");
  1011. if (!base.IsCurrentInterface && ((e.Attributes & MemberAttributes.ScopeMask) != MemberAttributes.Abstract))
  1012. {
  1013. base.Indent++;
  1014. this.GenerateVBStatements(e.Statements);
  1015. base.Indent--;
  1016. if (flag)
  1017. {
  1018. base.Output.WriteLine("End Sub");
  1019. }
  1020. else
  1021. {
  1022. base.Output.WriteLine("End Function");
  1023. }
  1024. }
  1025. e.Name = name;
  1026. }
  1027. }
  1028. protected override void GenerateMethodInvokeExpression(CodeMethodInvokeExpression e)
  1029. {
  1030. this.GenerateMethodReferenceExpression(e.Method);
  1031. if (e.Parameters.Count > 0)
  1032. {
  1033. base.Output.Write("(");
  1034. this.OutputExpressionList(e.Parameters);
  1035. base.Output.Write(")");
  1036. }
  1037. }
  1038. protected override void GenerateMethodReferenceExpression(CodeMethodReferenceExpression e)
  1039. {
  1040. if (e.TargetObject != null)
  1041. {
  1042. base.GenerateExpression(e.TargetObject);
  1043. base.Output.Write(".");
  1044. base.Output.Write(e.MethodName);
  1045. }
  1046. else
  1047. {
  1048. this.OutputIdentifier(e.MethodName);
  1049. }
  1050. if (e.TypeArguments.Count > 0)
  1051. {
  1052. base.Output.Write(this.GetTypeArgumentsOutput(e.TypeArguments));
  1053. }
  1054. }
  1055. protected override void GenerateMethodReturnStatement(CodeMethodReturnStatement e)
  1056. {
  1057. if (e.Expression != null)
  1058. {
  1059. base.Output.Write("Return ");
  1060. base.GenerateExpression(e.Expression);
  1061. base.Output.WriteLine("");
  1062. }
  1063. else
  1064. {
  1065. base.Output.WriteLine("Return");
  1066. }
  1067. }
  1068. protected override void GenerateNamespace(CodeNamespace e)
  1069. {
  1070. if (this.GetUserData(e, "GenerateImports", true))
  1071. {
  1072. base.GenerateNamespaceImports(e);
  1073. }
  1074. base.Output.WriteLine();
  1075. this.GenerateCommentStatements(e.Comments);
  1076. this.GenerateNamespaceStart(e);
  1077. base.GenerateTypes(e);
  1078. this.GenerateNamespaceEnd(e);
  1079. }
  1080. protected override void GenerateNamespaceEnd(CodeNamespace e)
  1081. {
  1082. if ((e.Name != null) && (e.Name.Length > 0))
  1083. {
  1084. base.Indent--;
  1085. base.Output.WriteLine("End Namespace");
  1086. }
  1087. }
  1088. protected override void GenerateNamespaceImport(CodeNamespaceImport e)
  1089. {
  1090. base.Output.Write("Imports ");
  1091. this.OutputIdentifier(e.Namespace);
  1092. base.Output.WriteLine("");
  1093. }
  1094. protected override void GenerateNamespaceStart(CodeNamespace e)
  1095. {
  1096. if ((e.Name != null) && (e.Name.Length > 0))
  1097. {
  1098. base.Output.Write("Namespace ");
  1099. string[] strArray = e.Name.Split(new char[] { '.' });
  1100. this.OutputIdentifier(strArray[0]);
  1101. for (int i = 1; i < strArray.Length; i++)
  1102. {
  1103. base.Output.Write(".");
  1104. this.OutputIdentifier(strArray[i]);
  1105. }
  1106. base.Output.WriteLine();
  1107. base.Indent++;
  1108. }
  1109. }
  1110. private void GenerateNotIsNullExpression(CodeExpression e)
  1111. {
  1112. base.Output.Write("(Not (");
  1113. base.GenerateExpression(e);
  1114. base.Output.Write(") Is ");
  1115. base.Output.Write(this.NullToken);
  1116. base.Output.Write(")");
  1117. }
  1118. protected override void GenerateObjectCreateExpression(CodeObjectCreateExpression e)
  1119. {
  1120. base.Output.Write("New ");
  1121. this.OutputType(e.CreateType);
  1122. base.Output.Write("(");
  1123. this.OutputExpressionList(e.Parameters);
  1124. base.Output.Write(")");
  1125. }
  1126. protected override void GenerateParameterDeclarationExpression(CodeParameterDeclarationExpression e)
  1127. {
  1128. if (e.CustomAttributes.Count > 0)
  1129. {
  1130. this.OutputAttributes(e.CustomAttributes, true);
  1131. }
  1132. this.OutputDirection(e.Direction);
  1133. this.OutputTypeNamePair(e.Type, e.Name);
  1134. }
  1135. protected override void GeneratePrimitiveExpression(CodePrimitiveExpression e)
  1136. {
  1137. if (e.Value is char)
  1138. {
  1139. base.Output.Write("Global.Microsoft.VisualBasic.ChrW(" + ((IConvertible)e.Value).ToInt32(CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture) + ")");
  1140. }
  1141. else if (e.Value is sbyte)
  1142. {
  1143. base.Output.Write("CSByte(");
  1144. sbyte num2 = (sbyte)e.Value;
  1145. base.Output.Write(num2.ToString(CultureInfo.InvariantCulture));
  1146. base.Output.Write(")");
  1147. }
  1148. else if (e.Value is ushort)
  1149. {
  1150. ushort num3 = (ushort)e.Value;
  1151. base.Output.Write(num3.ToString(CultureInfo.InvariantCulture));
  1152. base.Output.Write("US");
  1153. }
  1154. else if (e.Value is uint)
  1155. {
  1156. uint num4 = (uint)e.Value;
  1157. base.Output.Write(num4.ToString(CultureInfo.InvariantCulture));
  1158. base.Output.Write("UI");
  1159. }
  1160. else if (e.Value is ulong)
  1161. {
  1162. ulong num5 = (ulong)e.Value;
  1163. base.Output.Write(num5.ToString(CultureInfo.InvariantCulture));
  1164. base.Output.Write("UL");
  1165. }
  1166. else
  1167. {
  1168. base.GeneratePrimitiveExpression(e);
  1169. }
  1170. }
  1171. protected override void GenerateProperty(CodeMemberProperty e, CodeTypeDeclaration c)
  1172. {
  1173. if ((base.IsCurrentClass || base.IsCurrentStruct) || base.IsCurrentInterface)
  1174. {
  1175. if (e.CustomAttributes.Count > 0)
  1176. {
  1177. this.OutputAttributes(e.CustomAttributes, false);
  1178. }
  1179. string name = e.Name;
  1180. if (e.PrivateImplementationType != null)
  1181. {
  1182. string str2 = this.GetBaseTypeOutput(e.PrivateImplementationType).Replace('.', '_');
  1183. e.Name = str2 + "_" + e.Name;
  1184. }
  1185. if (!base.IsCurrentInterface)
  1186. {
  1187. if (e.PrivateImplementationType == null)
  1188. {
  1189. this.OutputMemberAccessModifier(e.Attributes);
  1190. if (this.PropertyIsOverloaded(e, c))
  1191. {
  1192. base.Output.Write("Overloads ");
  1193. }
  1194. }
  1195. this.OutputVTableModifier(e.Attributes);
  1196. this.OutputMemberScopeModifier(e.Attributes);
  1197. }
  1198. else
  1199. {
  1200. this.OutputVTableModifier(e.Attributes);
  1201. }
  1202. if ((e.Parameters.Count > 0) && (string.Compare(e.Name, "Item", StringComparison.OrdinalIgnoreCase) == 0))
  1203. {
  1204. base.Output.Write("Default ");
  1205. }
  1206. if (e.HasGet)
  1207. {
  1208. if (!e.HasSet)
  1209. {
  1210. base.Output.Write("ReadOnly ");
  1211. }
  1212. }
  1213. else if (e.HasSet)
  1214. {
  1215. base.Output.Write("WriteOnly ");
  1216. }
  1217. base.Output.Write("Property ");
  1218. this.OutputIdentifier(e.Name);
  1219. base.Output.Write("(");
  1220. if (e.Parameters.Count > 0)
  1221. {
  1222. this.OutputParameters(e.Parameters);
  1223. }
  1224. base.Output.Write(")");
  1225. base.Output.Write(" As ");
  1226. this.OutputType(e.Type);
  1227. this.OutputArrayPostfix(e.Type);
  1228. if (e.ImplementationTypes.Count > 0)
  1229. {
  1230. base.Output.Write(" Implements ");
  1231. bool flag = true;
  1232. foreach (CodeTypeReference reference in e.ImplementationTypes)
  1233. {
  1234. if (flag)
  1235. {
  1236. flag = false;
  1237. }
  1238. else
  1239. {
  1240. base.Output.Write(" , ");
  1241. }
  1242. this.OutputType(reference);
  1243. base.Output.Write(".");
  1244. this.OutputIdentifier(name);
  1245. }
  1246. }
  1247. else if (e.PrivateImplementationType != null)
  1248. {
  1249. base.Output.Write(" Implements ");
  1250. this.OutputType(e.PrivateImplementationType);
  1251. base.Output.Write(".");
  1252. this.OutputIdentifier(name);
  1253. }
  1254. base.Output.WriteLine("");
  1255. if (!c.IsInterface && ((e.Attributes & MemberAttributes.ScopeMask) != MemberAttributes.Abstract))
  1256. {
  1257. base.Indent++;
  1258. if (e.HasGet)
  1259. {
  1260. base.Output.WriteLine("Get");
  1261. if (!base.IsCurrentInterface)
  1262. {
  1263. base.Indent++;
  1264. this.GenerateVBStatements(e.GetStatements);
  1265. e.Name = name;
  1266. base.Indent--;
  1267. base.Output.WriteLine("End Get");
  1268. }
  1269. }
  1270. if (e.HasSet)
  1271. {
  1272. base.Output.WriteLine("Set");
  1273. if (!base.IsCurrentInterface)
  1274. {
  1275. base.Indent++;
  1276. this.GenerateVBStatements(e.SetStatements);
  1277. base.Indent--;
  1278. base.Output.WriteLine("End Set");
  1279. }
  1280. }
  1281. base.Indent--;
  1282. base.Output.WriteLine("End Property");
  1283. }
  1284. e.Name = name;
  1285. }
  1286. }
  1287. protected override void GeneratePropertyReferenceExpression(CodePropertyReferenceExpression e)
  1288. {
  1289. if (e.TargetObject != null)
  1290. {
  1291. base.GenerateExpression(e.TargetObject);
  1292. base.Output.Write(".");
  1293. base.Output.Write(e.PropertyName);
  1294. }
  1295. else
  1296. {
  1297. this.OutputIdentifier(e.PropertyName);
  1298. }
  1299. }
  1300. protected override void GeneratePropertySetValueReferenceExpression(CodePropertySetValueReferenceExpression e)
  1301. {
  1302. base.Output.Write("value");
  1303. }
  1304. protected override void GenerateRemoveEventStatement(CodeRemoveEventStatement e)
  1305. {
  1306. base.Output.Write("RemoveHandler ");
  1307. this.GenerateFormalEventReferenceExpression(e.Event);
  1308. base.Output.Write(", ");
  1309. base.GenerateExpression(e.Listener);
  1310. base.Output.WriteLine("");
  1311. }
  1312. protected override void GenerateSingleFloatValue(float s)
  1313. {
  1314. if (float.IsNaN(s))
  1315. {
  1316. base.Output.Write("Single.NaN");
  1317. }
  1318. else if (float.IsNegativeInfinity(s))
  1319. {
  1320. base.Output.Write("Single.NegativeInfinity");
  1321. }
  1322. else if (float.IsPositiveInfinity(s))
  1323. {
  1324. base.Output.Write("Single.PositiveInfinity");
  1325. }
  1326. else
  1327. {
  1328. base.Output.Write(s.ToString(CultureInfo.InvariantCulture));
  1329. base.Output.Write('!');
  1330. }
  1331. }
  1332. protected override void GenerateSnippetExpression(CodeSnippetExpression e)
  1333. {
  1334. base.Output.Write(e.Value);
  1335. }
  1336. protected override void GenerateSnippetMember(CodeSnippetTypeMember e)
  1337. {
  1338. base.Output.Write(e.Text);
  1339. }
  1340. protected override void GenerateSnippetStatement(CodeSnippetStatement e)
  1341. {
  1342. base.Output.WriteLine(e.Value);
  1343. }
  1344. protected override void GenerateThisReferenceExpression(CodeThisReferenceExpression e)
  1345. {
  1346. base.Output.Write("Me");
  1347. }
  1348. protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
  1349. {
  1350. base.Output.Write("Throw");
  1351. if (e.ToThrow != null)
  1352. {
  1353. base.Output.Write(" ");
  1354. base.GenerateExpression(e.ToThrow);
  1355. }
  1356. base.Output.WriteLine("");
  1357. }
  1358. protected override void GenerateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e)
  1359. {
  1360. base.Output.WriteLine("Try ");
  1361. base.Indent++;
  1362. this.GenerateVBStatements(e.TryStatements);
  1363. base.Indent--;
  1364. CodeCatchClauseCollection catchClauses = e.CatchClauses;
  1365. if (catchClauses.Count > 0)
  1366. {
  1367. IEnumerator enumerator = catchClauses.GetEnumerator();
  1368. while (enumerator.MoveNext())
  1369. {
  1370. CodeCatchClause current = (CodeCatchClause)enumerator.Current;
  1371. base.Output.Write("Catch ");
  1372. this.OutputTypeNamePair(current.CatchExceptionType, current.LocalName);
  1373. base.Output.WriteLine("");
  1374. base.Indent++;
  1375. this.GenerateVBStatements(current.Statements);
  1376. base.Indent--;
  1377. }
  1378. }
  1379. CodeStatementCollection finallyStatements = e.FinallyStatements;
  1380. if (finallyStatements.Count > 0)
  1381. {
  1382. base.Output.WriteLine("Finally");
  1383. base.Indent++;
  1384. this.GenerateVBStatements(finallyStatements);
  1385. base.Indent--;
  1386. }
  1387. base.Output.WriteLine("End Try");
  1388. }
  1389. protected override void GenerateTypeConstructor(CodeTypeConstructor e)
  1390. {
  1391. if (base.IsCurrentClass || base.IsCurrentStruct)
  1392. {
  1393. if (e.CustomAttributes.Count > 0)
  1394. {
  1395. this.OutputAttributes(e.CustomAttributes, false);
  1396. }
  1397. base.Output.WriteLine("Shared Sub New()");
  1398. base.Indent++;
  1399. this.GenerateVBStatements(e.Statements);
  1400. base.Indent--;
  1401. base.Output.WriteLine("End Sub");
  1402. }
  1403. }
  1404. protected override void GenerateTypeEnd(CodeTypeDeclaration e)
  1405. {
  1406. if (!base.IsCurrentDelegate)
  1407. {
  1408. string str;
  1409. base.Indent--;
  1410. if (e.IsEnum)
  1411. {
  1412. str = "End Enum";
  1413. }
  1414. else if (e.IsInterface)
  1415. {
  1416. str = "End Interface";
  1417. }
  1418. else if (e.IsStruct)
  1419. {
  1420. str = "End Structure";
  1421. }
  1422. else if (this.IsCurrentModule)
  1423. {
  1424. str = "End Module";
  1425. }
  1426. else
  1427. {
  1428. str = "End Class";
  1429. }
  1430. base.Output.WriteLine(str);
  1431. }
  1432. }
  1433. protected override void GenerateTypeOfExpression(CodeTypeOfExpression e)
  1434. {
  1435. base.Output.Write("GetType(");
  1436. base.Output.Write(this.GetTypeOutput(e.Type));
  1437. base.Output.Write(")");
  1438. }
  1439. protected override void GenerateTypeStart(CodeTypeDeclaration e)
  1440. {
  1441. if (!base.IsCurrentDelegate)
  1442. {
  1443. if (e.IsEnum)
  1444. {
  1445. if (e.CustomAttributes.Count > 0)
  1446. {
  1447. this.OutputAttributes(e.CustomAttributes, false);
  1448. }
  1449. this.OutputTypeAttributes(e);
  1450. this.OutputIdentifier(e.Name);
  1451. if (e.BaseTypes.Count > 0)
  1452. {
  1453. base.Output.Write(" As ");
  1454. this.OutputType(e.BaseTypes[0]);
  1455. }
  1456. base.Output.WriteLine("");
  1457. base.Indent++;
  1458. }
  1459. else
  1460. {
  1461. if (e.CustomAttributes.Count > 0)
  1462. {
  1463. this.OutputAttributes(e.CustomAttributes, false);
  1464. }
  1465. this.OutputTypeAttributes(e);
  1466. this.OutputIdentifier(e.Name);
  1467. this.OutputTypeParameters(e.TypeParameters);
  1468. bool flag = false;
  1469. bool flag2 = false;
  1470. if (e.IsStruct)
  1471. {
  1472. flag = true;
  1473. }
  1474. if (e.IsInterface)
  1475. {
  1476. flag2 = true;
  1477. }
  1478. base.Indent++;
  1479. foreach (CodeTypeReference reference in e.BaseTypes)
  1480. {
  1481. if (!flag && (e.IsInterface || !reference.IsInterface))
  1482. {
  1483. base.Output.WriteLine("");
  1484. base.Output.Write("Inherits ");
  1485. flag = true;
  1486. }
  1487. else if (!flag2)
  1488. {
  1489. base.Output.WriteLine("");
  1490. base.Output.Write("Implements ");
  1491. flag2 = true;
  1492. }
  1493. else
  1494. {
  1495. base.Output.Write(", ");
  1496. }
  1497. this.OutputType(reference);
  1498. }
  1499. base.Output.WriteLine("");
  1500. }
  1501. }
  1502. else
  1503. {
  1504. if (e.CustomAttributes.Count > 0)
  1505. {
  1506. this.OutputAttributes(e.CustomAttributes, false);
  1507. }
  1508. switch ((e.TypeAttributes & TypeAttributes.NestedFamORAssem))
  1509. {
  1510. case TypeAttributes.Public:
  1511. base.Output.Write("Public ");
  1512. break;
  1513. }
  1514. CodeTypeDelegate delegate2 = (CodeTypeDelegate)e;
  1515. if ((delegate2.ReturnType.BaseType.Length > 0) && (string.Compare(delegate2.ReturnType.BaseType, "System.Void", StringComparison.OrdinalIgnoreCase) != 0))
  1516. {
  1517. base.Output.Write("Delegate Function ");
  1518. }
  1519. else
  1520. {
  1521. base.Output.Write("Delegate Sub ");
  1522. }
  1523. this.OutputIdentifier(e.Name);
  1524. base.Output.Write("(");
  1525. this.OutputParameters(delegate2.Parameters);
  1526. base.Output.Write(")");
  1527. if ((delegate2.ReturnType.BaseType.Length > 0) && (string.Compare(delegate2.ReturnType.BaseType, "System.Void", StringComparison.OrdinalIgnoreCase) != 0))
  1528. {
  1529. base.Output.Write(" As ");
  1530. this.OutputType(delegate2.ReturnType);
  1531. this.OutputArrayPostfix(delegate2.ReturnType);
  1532. }
  1533. base.Output.WriteLine("");
  1534. }
  1535. }
  1536. protected override void GenerateVariableDeclarationStatement(CodeVariableDeclarationStatement e)
  1537. {
  1538. bool flag = true;
  1539. base.Output.Write("Dim ");
  1540. CodeTypeReference type = e.Type;
  1541. if ((type.ArrayRank == 1) && (e.InitExpression != null))
  1542. {
  1543. CodeArrayCreateExpression initExpression = e.InitExpression as CodeArrayCreateExpression;
  1544. if ((initExpression != null) && (initExpression.Initializers.Count == 0))
  1545. {
  1546. flag = false;
  1547. this.OutputIdentifier(e.Name);
  1548. base.Output.Write("(");
  1549. if (initExpression.SizeExpression != null)
  1550. {
  1551. base.Output.Write("(");
  1552. base.GenerateExpression(initExpression.SizeExpression);
  1553. base.Output.Write(") - 1");
  1554. }
  1555. else
  1556. {
  1557. base.Output.Write((int)(initExpression.Size - 1));
  1558. }
  1559. base.Output.Write(")");
  1560. if (type.ArrayElementType != null)
  1561. {
  1562. this.OutputArrayPostfix(type.ArrayElementType);
  1563. }
  1564. base.Output.Write(" As ");
  1565. this.OutputType(type);
  1566. }
  1567. else
  1568. {
  1569. this.OutputTypeNamePair(e.Type, e.Name);
  1570. }
  1571. }
  1572. else
  1573. {
  1574. this.OutputTypeNamePair(e.Type, e.Name);
  1575. }
  1576. if (flag && (e.InitExpression != null))
  1577. {
  1578. base.Output.Write(" = ");
  1579. base.GenerateExpression(e.InitExpression);
  1580. }
  1581. base.Output.WriteLine("");
  1582. }
  1583. protected override void GenerateVariableReferenceExpression(CodeVariableReferenceExpression e)
  1584. {
  1585. this.OutputIdentifier(e.VariableName);
  1586. }
  1587. private void GenerateVBStatements(CodeStatementCollection stms)
  1588. {
  1589. this.statementDepth++;
  1590. try
  1591. {
  1592. base.GenerateStatements(stms);
  1593. }
  1594. finally
  1595. {
  1596. this.statementDepth--;
  1597. }
  1598. }
  1599. private string GetArrayPostfix(CodeTypeReference typeRef)
  1600. {
  1601. string arrayPostfix = "";
  1602. if (typeRef.ArrayElementType != null)
  1603. {
  1604. arrayPostfix = this.GetArrayPostfix(typeRef.ArrayElementType);
  1605. }
  1606. if (typeRef.ArrayRank <= 0)
  1607. {
  1608. return arrayPostfix;
  1609. }
  1610. char[] chArray = new char[typeRef.ArrayRank + 1];
  1611. chArray[0] = '(';
  1612. chArray[typeRef.ArrayRank] = ')';
  1613. for (int i = 1; i < typeRef.ArrayRank; i++)
  1614. {
  1615. chArray[i] = ',';
  1616. }
  1617. return (new string(chArray) + arrayPostfix);
  1618. }
  1619. private string GetBaseTypeOutput(CodeTypeReference typeRef)
  1620. {
  1621. string baseType = typeRef.BaseType;
  1622. if (baseType.Length == 0)
  1623. {
  1624. return "Void";
  1625. }
  1626. if (string.Compare(baseType, "System.Byte", StringComparison.OrdinalIgnoreCase) == 0)
  1627. {
  1628. return "Byte";
  1629. }
  1630. if (string.Compare(baseType, "System.SByte", StringComparison.OrdinalIgnoreCase) == 0)
  1631. {
  1632. return "SByte";
  1633. }
  1634. if (string.Compare(baseType, "System.Int16", StringComparison.OrdinalIgnoreCase) == 0)
  1635. {
  1636. return "Short";
  1637. }
  1638. if (string.Compare(baseType, "System.Int32", StringComparison.OrdinalIgnoreCase) == 0)
  1639. {
  1640. return "Integer";
  1641. }
  1642. if (string.Compare(baseType, "System.Int64", StringComparison.OrdinalIgnoreCase) == 0)
  1643. {
  1644. return "Long";
  1645. }
  1646. if (string.Compare(baseType, "System.UInt16", StringComparison.OrdinalIgnoreCase) == 0)
  1647. {
  1648. return "UShort";
  1649. }
  1650. if (string.Compare(baseType, "System.UInt32", StringComparison.OrdinalIgnoreCase) == 0)
  1651. {
  1652. return "UInteger";
  1653. }
  1654. if (string.Compare(baseType, "System.UInt64", StringComparison.OrdinalIgnoreCase) == 0)
  1655. {
  1656. return "ULong";
  1657. }
  1658. if (string.Compare(baseType, "System.String", StringComparison.OrdinalIgnoreCase) == 0)
  1659. {
  1660. return "String";
  1661. }
  1662. if (string.Compare(baseType, "System.DateTime", StringComparison.OrdinalIgnoreCase) == 0)
  1663. {
  1664. return "Date";
  1665. }
  1666. if (string.Compare(baseType, "System.Decimal", StringComparison.OrdinalIgnoreCase) == 0)
  1667. {
  1668. return "Decimal";
  1669. }
  1670. if (string.Compare(baseType, "System.Single", StringComparison.OrdinalIgnoreCase) == 0)
  1671. {
  1672. return "Single";
  1673. }
  1674. if (string.Compare(baseType, "System.Double", StringComparison.OrdinalIgnoreCase) == 0)
  1675. {
  1676. return "Double";
  1677. }
  1678. if (string.Compare(baseType, "System.Boolean", StringComparison.OrdinalIgnoreCase) == 0)
  1679. {
  1680. return "Boolean";
  1681. }
  1682. if (string.Compare(baseType, "System.Char", StringComparison.OrdinalIgnoreCase) == 0)
  1683. {
  1684. return "Char";
  1685. }
  1686. if (string.Compare(baseType, "System.Object", StringComparison.OrdinalIgnoreCase) == 0)
  1687. {
  1688. return "Object";
  1689. }
  1690. StringBuilder sb = new StringBuilder(baseType.Length + 10);
  1691. if ((typeRef.Options & CodeTypeReferenceOptions.GlobalReference) != 0)
  1692. {
  1693. sb.Append("Global.");
  1694. }
  1695. int startIndex = 0;
  1696. int start = 0;
  1697. for (int i = 0; i < baseType.Length; i++)
  1698. {
  1699. switch (baseType[i])
  1700. {
  1701. case '+':
  1702. case '.':
  1703. sb.Append(this.CreateEscapedIdentifier(baseType.Substring(startIndex, i - startIndex)));
  1704. sb.Append('.');
  1705. i++;
  1706. startIndex = i;
  1707. break;
  1708. case '`':
  1709. {
  1710. sb.Append(this.CreateEscapedIdentifier(baseType.Substring(startIndex, i - startIndex)));
  1711. i++;
  1712. int length = 0;
  1713. while (((i < baseType.Length) && (baseType[i] >= '0')) && (baseType[i] <= '9'))
  1714. {
  1715. length = (length * 10) + (baseType[i] - '0');
  1716. i++;
  1717. }
  1718. this.GetTypeArgumentsOutput(typeRef.TypeArguments, start, length, sb);
  1719. start += length;
  1720. if ((i < baseType.Length) && ((baseType[i] == '+') || (baseType[i] == '.')))
  1721. {
  1722. sb.Append('.');
  1723. i++;
  1724. }
  1725. startIndex = i;
  1726. break;
  1727. }
  1728. }
  1729. }
  1730. if (startIndex < baseType.Length)
  1731. {
  1732. sb.Append(this.CreateEscapedIdentifier(baseType.Substring(startIndex)));
  1733. }
  1734. return sb.ToString();
  1735. }
  1736. protected override string GetResponseFileCmdArgs(CompilerParameters options, string cmdArgs)
  1737. {
  1738. return ("/noconfig " + base.GetResponseFileCmdArgs(options, cmdArgs));
  1739. }
  1740. private string GetTypeArgumentsOutput(CodeTypeReferenceCollection typeArguments)
  1741. {
  1742. StringBuilder sb = new StringBuilder(128);
  1743. this.GetTypeArgumentsOutput(typeArguments, 0, typeArguments.Count, sb);
  1744. return sb.ToString();
  1745. }
  1746. private void GetTypeArgumentsOutput(CodeTypeReferenceCollection typeArguments, int start, int length, StringBuilder sb)
  1747. {
  1748. sb.Append("(Of ");
  1749. bool flag = true;
  1750. for (int i = start; i < (start + length); i++)
  1751. {
  1752. if (flag)
  1753. {
  1754. flag = false;
  1755. }
  1756. else
  1757. {
  1758. sb.Append(", ");
  1759. }
  1760. if (i < typeArguments.Count)
  1761. {
  1762. sb.Append(this.GetTypeOutput(typeArguments[i]));
  1763. }
  1764. }
  1765. sb.Append(')');
  1766. }
  1767. protected override string GetTypeOutput(CodeTypeReference typeRef)
  1768. {
  1769. string str = string.Empty + this.GetTypeOutputWithoutArrayPostFix(typeRef);
  1770. if (typeRef.ArrayRank > 0)
  1771. {
  1772. str = str + this.GetArrayPostfix(typeRef);
  1773. }
  1774. return str;
  1775. }
  1776. private string GetTypeOutputWithoutArrayPostFix(CodeTypeReference typeRef)
  1777. {
  1778. StringBuilder builder = new StringBuilder();
  1779. while (typeRef.ArrayElementType != null)
  1780. {
  1781. typeRef = typeRef.ArrayElementType;
  1782. }
  1783. builder.Append(this.GetBaseTypeOutput(typeRef));
  1784. return builder.ToString();
  1785. }
  1786. private bool GetUserData(CodeObject e, string property, bool defaultValue)
  1787. {
  1788. object obj2 = e.UserData[property];
  1789. if ((obj2 != null) && (obj2 is bool))
  1790. {
  1791. return (bool)obj2;
  1792. }
  1793. return defaultValue;
  1794. }
  1795. private bool IsDocComment(CodeCommentStatement comment)
  1796. {
  1797. return (((comment != null) && (comment.Comment != null)) && comment.Comment.DocComment);
  1798. }
  1799. private bool IsGeneratingStatements()
  1800. {
  1801. return (this.statementDepth > 0);
  1802. }
  1803. public static bool IsKeyword(string value)
  1804. {
  1805. return FixedStringLookup.Contains(keywords, value, true);
  1806. }
  1807. protected override bool IsValidIdentifier(string value)
  1808. {
  1809. if ((value == null) || (value.Length == 0))
  1810. {
  1811. return false;
  1812. }
  1813. if (value.Length > 1023)
  1814. {
  1815. return false;
  1816. }
  1817. if ((value[0] != '[') || (value[value.Length - 1] != ']'))
  1818. {
  1819. if (IsKeyword(value))
  1820. {
  1821. return false;
  1822. }
  1823. }
  1824. else
  1825. {
  1826. value = value.Substring(1, value.Length - 2);
  1827. }
  1828. if ((value.Length == 1) && (value[0] == '_'))
  1829. {
  1830. return false;
  1831. }
  1832. return CodeGenerator.IsValidLanguageIndependentIdentifier(value);
  1833. }
  1834. private bool MethodIsOverloaded(CodeMemberMethod e, CodeTypeDeclaration c)
  1835. {
  1836. if ((e.Attributes & MemberAttributes.Overloaded) != ((MemberAttributes)0))
  1837. {
  1838. return true;
  1839. }
  1840. IEnumerator enumerator = c.Members.GetEnumerator();
  1841. while (enumerator.MoveNext())
  1842. {
  1843. if (enumerator.Current is CodeMemberMethod)
  1844. {
  1845. CodeMemberMethod current = (CodeMemberMethod)enumerator.Current;
  1846. if (((!(enumerator.Current is CodeTypeConstructor) && !(enumerator.Current is CodeConstructor)) && ((current != e) && current.Name.Equals(e.Name, StringComparison.OrdinalIgnoreCase))) && (current.PrivateImplementationType == null))
  1847. {
  1848. return true;
  1849. }
  1850. }
  1851. }
  1852. return false;
  1853. }
  1854. private void OutputArrayPostfix(CodeTypeReference typeRef)
  1855. {
  1856. if (typeRef.ArrayRank > 0)
  1857. {
  1858. base.Output.Write(this.GetArrayPostfix(typeRef));
  1859. }
  1860. }
  1861. protected override void OutputAttributeArgument(CodeAttributeArgument arg)
  1862. {
  1863. if ((arg.Name != null) && (arg.Name.Length > 0))
  1864. {
  1865. this.OutputIdentifier(arg.Name);
  1866. base.Output.Write(":=");
  1867. }
  1868. ((ICodeGenerator)this).GenerateCodeFromExpression(arg.Value, ((IndentedTextWriter)base.Output).InnerWriter, base.Options);
  1869. }
  1870. private void OutputAttributes(CodeAttributeDeclarationCollection attributes, bool inLine)
  1871. {
  1872. this.OutputAttributes(attributes, inLine, null, false);
  1873. }
  1874. private void OutputAttributes(CodeAttributeDeclarationCollection attributes, bool inLine, string prefix, bool closingLine)
  1875. {
  1876. if (attributes.Count != 0)
  1877. {
  1878. IEnumerator enumerator = attributes.GetEnumerator();
  1879. bool flag = true;
  1880. this.GenerateAttributeDeclarationsStart(attributes);
  1881. while (enumerator.MoveNext())
  1882. {
  1883. if (flag)
  1884. {
  1885. flag = false;
  1886. }
  1887. else
  1888. {
  1889. base.Output.Write(", ");
  1890. if (!inLine)
  1891. {
  1892. this.ContinueOnNewLine("");
  1893. base.Output.Write(" ");
  1894. }
  1895. }
  1896. if ((prefix != null) && (prefix.Length > 0))
  1897. {
  1898. base.Output.Write(prefix);
  1899. }
  1900. CodeAttributeDeclaration current = (CodeAttributeDeclaration)enumerator.Current;
  1901. if (current.AttributeType != null)
  1902. {
  1903. base.Output.Write(this.GetTypeOutput(current.AttributeType));
  1904. }
  1905. base.Output.Write("(");
  1906. bool flag2 = true;
  1907. foreach (CodeAttributeArgument argument in current.Arguments)
  1908. {
  1909. if (flag2)
  1910. {
  1911. flag2 = false;
  1912. }
  1913. else
  1914. {
  1915. base.Output.Write(", ");
  1916. }
  1917. this.OutputAttributeArgument(argument);
  1918. }
  1919. base.Output.Write(")");
  1920. }
  1921. this.GenerateAttributeDeclarationsEnd(attributes);
  1922. base.Output.Write(" ");
  1923. if (!inLine)
  1924. {
  1925. if (closingLine)
  1926. {
  1927. base.Output.WriteLine();
  1928. }
  1929. else
  1930. {
  1931. this.ContinueOnNewLine("");
  1932. }
  1933. }
  1934. }
  1935. }
  1936. protected override void OutputDirection(FieldDirection dir)
  1937. {
  1938. switch (dir)
  1939. {
  1940. case FieldDirection.In:
  1941. base.Output.Write("ByVal ");
  1942. return;
  1943. case FieldDirection.Out:
  1944. case FieldDirection.Ref:
  1945. base.Output.Write("ByRef ");
  1946. return;
  1947. }
  1948. }
  1949. protected override void OutputFieldScopeModifier(MemberAttributes attributes)
  1950. {
  1951. switch ((attributes & MemberAttributes.ScopeMask))
  1952. {
  1953. case MemberAttributes.Final:
  1954. base.Output.Write("");
  1955. return;
  1956. case MemberAttributes.Static:
  1957. if (!this.IsCurrentModule)
  1958. {
  1959. base.Output.Write("Shared ");
  1960. }
  1961. return;
  1962. case MemberAttributes.Const:
  1963. base.Output.Write("Const ");
  1964. return;
  1965. }
  1966. base.Output.Write("");
  1967. }
  1968. protected override void OutputIdentifier(string ident)
  1969. {
  1970. base.Output.Write(this.CreateEscapedIdentifier(ident));
  1971. }
  1972. protected override void OutputMemberAccessModifier(MemberAttributes attributes)
  1973. {
  1974. MemberAttributes attributes2 = attributes & MemberAttributes.AccessMask;
  1975. if (attributes2 <= MemberAttributes.Family)
  1976. {
  1977. if (attributes2 != MemberAttributes.Assembly)
  1978. {
  1979. if (attributes2 != MemberAttributes.FamilyAndAssembly)
  1980. {
  1981. if (attributes2 == MemberAttributes.Family)
  1982. {
  1983. base.Output.Write("Protected ");
  1984. }
  1985. return;
  1986. }
  1987. base.Output.Write("Friend ");
  1988. return;
  1989. }
  1990. }
  1991. else
  1992. {
  1993. switch (attributes2)
  1994. {
  1995. case MemberAttributes.FamilyOrAssembly:
  1996. base.Output.Write("Protected Friend ");
  1997. return;
  1998. case MemberAttributes.Private:
  1999. base.Output.Write("Private ");
  2000. return;
  2001. case MemberAttributes.Public:
  2002. base.Output.Write("Public ");
  2003. return;
  2004. }
  2005. return;
  2006. }
  2007. base.Output.Write("Friend ");
  2008. }
  2009. protected override void OutputMemberScopeModifier(MemberAttributes attributes)
  2010. {
  2011. switch ((attributes & MemberAttributes.ScopeMask))
  2012. {
  2013. case MemberAttributes.Abstract:
  2014. base.Output.Write("MustOverride ");
  2015. return;
  2016. case MemberAttributes.Final:
  2017. base.Output.Write("");
  2018. return;
  2019. case MemberAttributes.Static:
  2020. if (this.IsCurrentModule)
  2021. {
  2022. break;
  2023. }
  2024. base.Output.Write("Shared ");
  2025. return;
  2026. case MemberAttributes.Override:
  2027. base.Output.Write("Overrides ");
  2028. return;
  2029. case MemberAttributes.Private:
  2030. base.Output.Write("Private ");
  2031. return;
  2032. default:
  2033. {
  2034. MemberAttributes attributes3 = attributes & MemberAttributes.AccessMask;
  2035. if (((attributes3 != MemberAttributes.Assembly) && (attributes3 != MemberAttributes.Family)) && (attributes3 != MemberAttributes.Public))
  2036. {
  2037. return;
  2038. }
  2039. base.Output.Write("Overridable ");
  2040. break;
  2041. }
  2042. }
  2043. }
  2044. protected override void OutputOperator(CodeBinaryOperatorType op)
  2045. {
  2046. switch (op)
  2047. {
  2048. case CodeBinaryOperatorType.Modulus:
  2049. base.Output.Write("Mod");
  2050. return;
  2051. case CodeBinaryOperatorType.IdentityInequality:
  2052. base.Output.Write("<>");
  2053. return;
  2054. case CodeBinaryOperatorType.IdentityEquality:
  2055. base.Output.Write("Is");
  2056. return;
  2057. case CodeBinaryOperatorType.ValueEquality:
  2058. base.Output.Write("=");
  2059. return;
  2060. case CodeBinaryOperatorType.BitwiseOr:
  2061. base.Output.Write("Or");
  2062. return;
  2063. case CodeBinaryOperatorType.BitwiseAnd:
  2064. base.Output.Write("And");
  2065. return;
  2066. case CodeBinaryOperatorType.BooleanOr:
  2067. base.Output.Write("OrElse");
  2068. return;
  2069. case CodeBinaryOperatorType.BooleanAnd:
  2070. base.Output.Write("AndAlso");
  2071. return;
  2072. }
  2073. base.OutputOperator(op);
  2074. }
  2075. protected override void OutputType(CodeTypeReference typeRef)
  2076. {
  2077. base.Output.Write(this.GetTypeOutputWithoutArrayPostFix(typeRef));
  2078. }
  2079. private void OutputTypeAttributes(CodeTypeDeclaration e)
  2080. {
  2081. if ((e.Attributes & MemberAttributes.New) != ((MemberAttributes)0))
  2082. {
  2083. base.Output.Write("Shadows ");
  2084. }
  2085. TypeAttributes typeAttributes = e.TypeAttributes;
  2086. if (e.IsPartial)
  2087. {
  2088. base.Output.Write("Partial ");
  2089. }
  2090. switch ((typeAttributes & TypeAttributes.NestedFamORAssem))
  2091. {
  2092. case TypeAttributes.NotPublic:
  2093. case TypeAttributes.NestedAssembly:
  2094. case TypeAttributes.NestedFamANDAssem:
  2095. base.Output.Write("Friend ");
  2096. break;
  2097. case TypeAttributes.Public:
  2098. case TypeAttributes.NestedPublic:
  2099. base.Output.Write("Public ");
  2100. break;
  2101. case TypeAttributes.NestedPrivate:
  2102. base.Output.Write("Private ");
  2103. break;
  2104. case TypeAttributes.NestedFamily:
  2105. base.Output.Write("Protected ");
  2106. break;
  2107. case TypeAttributes.NestedFamORAssem:
  2108. base.Output.Write("Protected Friend ");
  2109. break;
  2110. }
  2111. if (e.IsStruct)
  2112. {
  2113. base.Output.Write("Structure ");
  2114. }
  2115. else if (e.IsEnum)
  2116. {
  2117. base.Output.Write("Enum ");
  2118. }
  2119. else
  2120. {
  2121. TypeAttributes attributes3 = typeAttributes & TypeAttributes.Interface;
  2122. if (attributes3 != TypeAttributes.NotPublic)
  2123. {
  2124. if (attributes3 != TypeAttributes.Interface)
  2125. {
  2126. return;
  2127. }
  2128. }
  2129. else
  2130. {
  2131. if (this.IsCurrentModule)
  2132. {
  2133. base.Output.Write("Module ");
  2134. return;
  2135. }
  2136. if ((typeAttributes & TypeAttributes.Sealed) == TypeAttributes.Sealed)
  2137. {
  2138. base.Output.Write("NotInheritable ");
  2139. }
  2140. if ((typeAttributes & TypeAttributes.Abstract) == TypeAttributes.Abstract)
  2141. {
  2142. base.Output.Write("MustInherit ");
  2143. }
  2144. base.Output.Write("Class ");
  2145. return;
  2146. }
  2147. base.Output.Write("Interface ");
  2148. }
  2149. }
  2150. protected override void OutputTypeNamePair(CodeTypeReference typeRef, string name)
  2151. {
  2152. if (string.IsNullOrEmpty(name))
  2153. {
  2154. name = "__exception";
  2155. }
  2156. this.OutputIdentifier(name);
  2157. this.OutputArrayPostfix(typeRef);
  2158. base.Output.Write(" As ");
  2159. this.OutputType(typeRef);
  2160. }
  2161. private void OutputTypeParameterConstraints(CodeTypeParameter typeParameter)
  2162. {
  2163. CodeTypeReferenceCollection constraints = typeParameter.Constraints;
  2164. int count = constraints.Count;
  2165. if (typeParameter.HasConstructorConstraint)
  2166. {
  2167. count++;
  2168. }
  2169. if (count != 0)
  2170. {
  2171. base.Output.Write(" As ");
  2172. if (count > 1)
  2173. {
  2174. base.Output.Write(" {");
  2175. }
  2176. bool flag = true;
  2177. foreach (CodeTypeReference reference in constraints)
  2178. {
  2179. if (flag)
  2180. {
  2181. flag = false;
  2182. }
  2183. else
  2184. {
  2185. base.Output.Write(", ");
  2186. }
  2187. base.Output.Write(this.GetTypeOutput(reference));
  2188. }
  2189. if (typeParameter.HasConstructorConstraint)
  2190. {
  2191. if (!flag)
  2192. {
  2193. base.Output.Write(", ");
  2194. }
  2195. base.Output.Write("New");
  2196. }
  2197. if (count > 1)
  2198. {
  2199. base.Output.Write('}');
  2200. }
  2201. }
  2202. }
  2203. private void OutputTypeParameters(CodeTypeParameterCollection typeParameters)
  2204. {
  2205. if (typeParameters.Count != 0)
  2206. {
  2207. base.Output.Write("(Of ");
  2208. bool flag = true;
  2209. for (int i = 0; i < typeParameters.Count; i++)
  2210. {
  2211. if (flag)
  2212. {
  2213. flag = false;
  2214. }
  2215. else
  2216. {
  2217. base.Output.Write(", ");
  2218. }
  2219. base.Output.Write(typeParameters[i].Name);
  2220. this.OutputTypeParameterConstraints(typeParameters[i]);
  2221. }
  2222. base.Output.Write(')');
  2223. }
  2224. }
  2225. private void OutputVTableModifier(MemberAttributes attributes)
  2226. {
  2227. MemberAttributes attributes2 = attributes & MemberAttributes.VTableMask;
  2228. if (attributes2 == MemberAttributes.New)
  2229. {
  2230. base.Output.Write("Shadows ");
  2231. }
  2232. }
  2233. protected override void ProcessCompilerOutputLine(CompilerResults results, string line)
  2234. {
  2235. if (outputReg == null)
  2236. {
  2237. outputReg = new Regex(@"^([^(]*)\(?([0-9]*)\)? ?:? ?(error|warning) ([A-Z]+[0-9]+) ?: ((.|\n)*)");
  2238. }
  2239. Match match = outputReg.Match(line);
  2240. if (match.Success)
  2241. {
  2242. CompilerError error = new CompilerError();
  2243. error.FileName = match.Groups[1].Value;
  2244. string s = match.Groups[2].Value;
  2245. if ((s != null) && (s.Length > 0))
  2246. {
  2247. error.Line = int.Parse(s, CultureInfo.InvariantCulture);
  2248. }
  2249. if (string.Compare(match.Groups[3].Value, "warning", StringComparison.OrdinalIgnoreCase) == 0)
  2250. {
  2251. error.IsWarning = true;
  2252. }
  2253. error.ErrorNumber = match.Groups[4].Value;
  2254. error.ErrorText = match.Groups[5].Value;
  2255. results.Errors.Add(error);
  2256. }
  2257. }
  2258. private bool PropertyIsOverloaded(CodeMemberProperty e, CodeTypeDeclaration c)
  2259. {
  2260. if ((e.Attributes & MemberAttributes.Overloaded) != ((MemberAttributes)0))
  2261. {
  2262. return true;
  2263. }
  2264. IEnumerator enumerator = c.Members.GetEnumerator();
  2265. while (enumerator.MoveNext())
  2266. {
  2267. if (enumerator.Current is CodeMemberProperty)
  2268. {
  2269. CodeMemberProperty current = (CodeMemberProperty)enumerator.Current;
  2270. if (((current != e) && current.Name.Equals(e.Name, StringComparison.OrdinalIgnoreCase)) && (current.PrivateImplementationType == null))
  2271. {
  2272. return true;
  2273. }
  2274. }
  2275. }
  2276. return false;
  2277. }
  2278. protected override string QuoteSnippetString(string value)
  2279. {
  2280. StringBuilder b = new StringBuilder(value.Length + 5);
  2281. bool fInDoubleQuotes = true;
  2282. Indentation indentation = new Indentation((IndentedTextWriter)base.Output, base.Indent + 1);
  2283. b.Append("\"");
  2284. for (int i = 0; i < value.Length; i++)
  2285. {
  2286. char ch = value[i];
  2287. switch (ch)
  2288. {
  2289. case '\t':
  2290. this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
  2291. b.Append("&Global.Microsoft.VisualBasic.ChrW(9)");
  2292. goto Label_0186;
  2293. case '\n':
  2294. this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
  2295. b.Append("&Global.Microsoft.VisualBasic.ChrW(10)");
  2296. goto Label_0186;
  2297. case '\r':
  2298. this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
  2299. if ((i >= (value.Length - 1)) || (value[i + 1] != '\n'))
  2300. {
  2301. break;
  2302. }
  2303. b.Append("&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)");
  2304. i++;
  2305. goto Label_0186;
  2306. case '"':
  2307. case '“':
  2308. case '”':
  2309. case 65282:
  2310. this.EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
  2311. b.Append(ch);
  2312. b.Append(ch);
  2313. goto Label_0186;
  2314. case '\0':
  2315. this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
  2316. b.Append("&Global.Microsoft.VisualBasic.ChrW(0)");
  2317. goto Label_0186;
  2318. case '\u2028':
  2319. case '\u2029':
  2320. this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
  2321. AppendEscapedChar(b, ch);
  2322. goto Label_0186;
  2323. default:
  2324. this.EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
  2325. b.Append(value[i]);
  2326. goto Label_0186;
  2327. }
  2328. b.Append("&Global.Microsoft.VisualBasic.ChrW(13)");
  2329. Label_0186:
  2330. if ((i > 0) && ((i % 80) == 0))
  2331. {
  2332. if ((char.IsHighSurrogate(value[i]) && (i < (value.Length - 1))) && char.IsLowSurrogate(value[i + 1]))
  2333. {
  2334. b.Append(value[++i]);
  2335. }
  2336. if (fInDoubleQuotes)
  2337. {
  2338. b.Append("\"");
  2339. }
  2340. fInDoubleQuotes = true;
  2341. b.Append("& _ ");
  2342. b.Append(Environment.NewLine);
  2343. b.Append(indentation.IndentationString);
  2344. b.Append('"');
  2345. }
  2346. }
  2347. if (fInDoubleQuotes)
  2348. {
  2349. b.Append("\"");
  2350. }
  2351. return b.ToString();
  2352. }
  2353. private static byte[] ReadAllBytes(string file, FileShare share)
  2354. {
  2355. byte[] buffer;
  2356. using (FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, share))
  2357. {
  2358. int offset = 0;
  2359. long length = stream.Length;
  2360. if (length > 2147483647L)
  2361. {
  2362. throw new ArgumentOutOfRangeException("file");
  2363. }
  2364. int count = (int)length;
  2365. buffer = new byte[count];
  2366. while (count > 0)
  2367. {
  2368. int num4 = stream.Read(buffer, offset, count);
  2369. if (num4 == 0)
  2370. {
  2371. throw new EndOfStreamException();
  2372. }
  2373. offset += num4;
  2374. count -= num4;
  2375. }
  2376. }
  2377. return buffer;
  2378. }
  2379. protected bool RequireVariableDeclaration(CodeCompileUnit e)
  2380. {
  2381. object obj2 = e.UserData["RequireVariableDeclaration"];
  2382. if ((obj2 != null) && (obj2 is bool))
  2383. {
  2384. return (bool)obj2;
  2385. }
  2386. return true;
  2387. }
  2388. protected override bool Supports(GeneratorSupport support)
  2389. {
  2390. return ((support & (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)) == support);
  2391. }
  2392. // Properties
  2393. protected override string CompilerName
  2394. {
  2395. get
  2396. {
  2397. return "vbc.exe";
  2398. }
  2399. }
  2400. protected override string FileExtension
  2401. {
  2402. get
  2403. {
  2404. return ".vb";
  2405. }
  2406. }
  2407. private bool IsCurrentModule
  2408. {
  2409. get
  2410. {
  2411. return (base.IsCurrentClass && this.GetUserData(base.CurrentClass, "Module", false));
  2412. }
  2413. }
  2414. protected override string NullToken
  2415. {
  2416. get
  2417. {
  2418. return "Nothing";
  2419. }
  2420. }
  2421. }
  2422. }