Идея этого шага показать то что имея структуру очень легко перевести ее на VB. Давайте посмотрим.
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System.IO;
class MainClass
{
public static void Main(string[] args)
{
CodeCompileUnit compileunit = new CodeCompileUnit();
CodeNamespace Samples = new CodeNamespace("Samples");
//CSharpCodeProvider cs = new CSharpCodeProvider();
VBCodeProvider cs = new VBCodeProvider();
CodeGeneratorOptions go = new CodeGeneratorOptions();
ICodeGenerator ic= cs.CreateGenerator();
CodeTypeDeclaration Class1 = new CodeTypeDeclaration("MyClass1");
CodeTypeDeclaration Class2 = new CodeTypeDeclaration("MyClass2");
Samples.Types.Add(Class1);
Samples.Types.Add(Class2);
Stream ss=File.OpenWrite("d:\\test.txt");
StreamWriter s = new StreamWriter(ss);
compileunit.Namespaces.Add(Samples);
ic.GenerateCodeFromCompileUnit(compileunit,s,go);
s.Close();
ss.Close();
}
}
Все заключается всего в одной строке , нужно поменять класс генератор кода , вот мы его и взяли для VB - VBCodeProvider. А остальное осталось как было. Смотрим что получилось.
'------------------------------------------------------------------------------ '' This code was generated by a tool. ' Runtime Version: 1.0.2914.16 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' '------------------------------------------------------------------------------ Option Strict Off Option Explicit On