Это ужасный хак, такой же злой, как C #, но он работает:
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.IO
Module Module1
Sub Main()
Dim unit As New CodeCompileUnit
Dim nspace As New CodeNamespace("SomeNamespace")
Dim vbclass As New CodeTypeDeclaration("SomeClass")
vbclass.IsClass = True
Dim snippet As New CodeSnippetTypeMember("Partial _")
vbclass.Members.Add(snippet)
Dim method As New CodeMemberMethod()
method.Name = "SomeMethod"
method.Attributes = MemberAttributes.Private
vbclass.Members.Add(method)
nspace.Types.Add(vbclass)
unit.Namespaces.Add(nspace)
dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VB")
Dim options As New CodeGeneratorOptions()
options.BlankLinesBetweenMembers = False
dim writer As new StringWriter()
provider.GenerateCodeFromCompileUnit(unit, writer, options)
Console.WriteLine(writer.ToString())
Console.ReadLine()
End Sub
End Module
Обратите внимание, что параметр BlankLinesBetweenMembers крайне важен для взлома. Выход:
Option Strict Off
Option Explicit On
Namespace SomeNamespace
Public Class SomeClass
Partial _
Private Sub SomeMethod()
End Sub
End Class
End Namespace