mygenerator.vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 633 行 · 第 1/3 页

VB
633
字号
        ProjectCode.AppendLine("        End Property")        Return result    End Function    Function GenerateMyUser() As Boolean        Dim result As Boolean = True        Dim _MyUserDefine As Define        Dim _MyUser As String        _MyUserDefine = Compiler.CommandLine.Define("_MYUSERTYPE")        If _MyUserDefine Is Nothing Then            Select Case m_MyType                Case MyTypes.Console, MyTypes.WindowsFormsWithCustomSubMain, MyTypes.Windows, MyTypes.WindowsForms                    _MyUser = "Windows"                Case MyTypes.Web, MyTypes.WebControl                    _MyUser = "Web"                Case Else                    _MyUser = String.Empty            End Select        Else            _MyUser = _MyUserDefine.Value        End If        Dim baseClass As String        Select Case _MyUser            Case "Web"                baseClass = "Global.Microsoft.VisualBasic.ApplicationServices.WebUser"            Case "Windows"                baseClass = "Global.Microsoft.VisualBasic.ApplicationServices.User"            Case Else                Return True        End Select        ProjectCode.AppendLine("        Private Shared ReadOnly m_UserObjectProvider As ThreadSafeObjectProvider(Of Z) = New ThreadSafeObjectProvider(Of Z)".Replace("Z", baseClass))        ProjectCode.AppendLine("        <Global.System.ComponentModel.Design.HelpKeyword(""My.User"")> _")        ProjectCode.Append("        Friend Shared ReadOnly Property User As ") : ProjectCode.AppendLine(baseClass)        ProjectCode.AppendLine("            <Global.System.Diagnostics.DebuggerHidden()> _")        ProjectCode.AppendLine("            Get")        ProjectCode.AppendLine("                Return m_UserObjectProvider.GetInstance")        ProjectCode.AppendLine("            End Get")        ProjectCode.AppendLine("        End Property")        Return result    End Function    Function GenerateMyForms() As Boolean        Dim result As Boolean = True        Dim _MyFormsDefine As Define        Dim _MyForms As Boolean        _MyFormsDefine = Compiler.CommandLine.Define("_MYFORMS")        If _MyFormsDefine Is Nothing Then            Select Case m_MyType                Case MyTypes.WindowsFormsWithCustomSubMain, MyTypes.WindowsForms                    _MyForms = True                Case Else                    _MyForms = False            End Select        Else            _MyForms = CBool(_MyFormsDefine.Value)        End If        If Not _MyForms Then Return True        Compiler.CommandLine.References.Add("System.Windows.Forms.dll")        Dim code As String = VB.vbNewLine & _       "        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "        <Global.Microsoft.VisualBasic.MyGroupCollection(""System.Windows.Forms.Form"", ""Create__Instance__"", ""Dispose__Instance__"", ""My.MyProject.Forms"")> _" & VB.vbNewLine & _       "        Friend NotInheritable Class MyForms" & VB.vbNewLine & _       "            <Global.System.ThreadStatic> _" & VB.vbNewLine & _       "            Private Shared m_FormBeingCreated As Global.System.Collections.Hashtable" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Public Sub New()" & VB.vbNewLine & _       "            End Sub" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Private Shared Function Create__Instance__(Of T As {Global.System.Windows.Forms.Form, New})(ByVal Instance As T) As T" & VB.vbNewLine & _       "                If Instance IsNot Nothing AndAlso Instance.IsDisposed = False" & VB.vbNewLine & _       "                    Return Instance" & VB.vbNewLine & _       "                End If" & VB.vbNewLine & _       "                " & VB.vbNewLine & _       "                Dim TType As Type = GetType(T)" & VB.vbNewLine & _       "                If m_FormBeingCreated Is Nothing Then" & VB.vbNewLine & _       "                    m_FormBeingCreated = New Global.System.Collections.Hashtable()" & VB.vbNewLine & _       "                ElseIf m_FormBeingCreated.ContainsKey(TType) Then" & VB.vbNewLine & _       "                    Throw New InvalidOperationException(""There is a reference to a default instance from the constructor of a form, which leads to infinite recursion. Please refer to the form itself using 'Me' from within the constructor."")" & VB.vbNewLine & _       "                End If" & VB.vbNewLine & _       "                " & VB.vbNewLine & _       "                m_FormBeingCreated.Add(TType, Nothing)" & VB.vbNewLine & _       "                Try" & VB.vbNewLine & _       "                    Return Global.System.Activator.CreateInstance(Of T)()" & VB.vbNewLine & _       "                Catch ex As Global.System.Reflection.TargetInvocationException" & VB.vbNewLine & _       "                    Throw New Global.System.InvalidOperationException(""See inner exception"", ex.InnerException)" & VB.vbNewLine & _       "                Finally" & VB.vbNewLine & _       "                    m_FormBeingCreated.Remove(TType)" & VB.vbNewLine & _       "                End Try" & VB.vbNewLine & _       "                Return Nothing" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Private Sub Dispose__Instance__(Of T As Global.System.Windows.Forms.Form)(ByRef instance As T)" & VB.vbNewLine & _       "                instance.Dispose()" & VB.vbNewLine & _       "                instance = CType(Nothing, T)" & VB.vbNewLine & _       "            End Sub" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function Equals(ByVal o As Object) As Boolean" & VB.vbNewLine & _       "                Return MyBase.Equals(Global.System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(o))" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function GetHashCode() As Integer" & VB.vbNewLine & _       "             Return MyBase.GetHashCode" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Friend Function [GetType]() As Type" & VB.vbNewLine & _       "                Return GetType(MyForms)" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function ToString() As String" & VB.vbNewLine & _       "                Return MyBase.ToString" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "        End Class" & VB.vbNewLine & _       ""        ProjectCode.Append(code)        ProjectCode.AppendLine("        Private Shared ReadOnly m_MyFormsObjectProvider As ThreadSafeObjectProvider(Of MyForms) = New ThreadSafeObjectProvider(Of MyForms)")        ProjectCode.AppendLine("        <Global.System.ComponentModel.Design.HelpKeyword(""My.Forms"")> _")        ProjectCode.AppendLine("        Friend Shared ReadOnly Property Forms As MyForms")        ProjectCode.AppendLine("            <Global.System.Diagnostics.DebuggerHidden()> _")        ProjectCode.AppendLine("            Get")        ProjectCode.AppendLine("                Return m_MyFormsObjectProvider.GetInstance")        ProjectCode.AppendLine("            End Get")        ProjectCode.AppendLine("        End Property")        Return result    End Function    Function GenerateMyWebServices() As Boolean        Dim result As Boolean = True        Dim _MyWebServicesDefine As Define        Dim _MyWebServices As Boolean        _MyWebServicesDefine = Compiler.CommandLine.Define("_MYWEBSERVICES")        If _MyWebServicesDefine Is Nothing Then            Select Case m_MyType                Case MyTypes.Console, MyTypes.WindowsFormsWithCustomSubMain, MyTypes.Windows, MyTypes.WindowsForms, MyTypes.WebControl                    _MyWebServices = True                Case Else                    _MyWebServices = False            End Select        Else            _MyWebServices = CBool(_MyWebServicesDefine.Value)        End If        If Not _MyWebServices Then Return True        Dim code As String = VB.vbNewLine & _       "        <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "        <Global.Microsoft.VisualBasic.MyGroupCollection(""System.Web.Services.Protocols.SoapHttpClientProtocol"", ""Create__Instance__"", ""Dispose__Instance__"", """")> _" & VB.vbNewLine & _       "        Friend NotInheritable Class MyWebServices" & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Public Sub New()" & VB.vbNewLine & _       "            End Sub" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Private Shared Function Create__Instance__(Of T As New)(ByVal instance As T) As T" & VB.vbNewLine & _       "                If (instance Is Nothing) Then" & VB.vbNewLine & _       "                    Return Global.System.Activator.CreateInstance(Of T)" & VB.vbNewLine & _       "                End If" & VB.vbNewLine & _       "                Return instance" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            Private Sub Dispose__Instance__(Of T)(ByRef instance As T)" & VB.vbNewLine & _       "                instance = CType(Nothing, T)" & VB.vbNewLine & _       "            End Sub" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function Equals(ByVal o As Object) As Boolean" & VB.vbNewLine & _       "                Return MyBase.Equals(Global.System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(o))" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function GetHashCode() As Integer" & VB.vbNewLine & _       "             Return MyBase.GetHashCode" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Friend Function [GetType]() As Type" & VB.vbNewLine & _       "                Return GetType(MyWebServices)" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "            " & VB.vbNewLine & _       "            <Global.System.Diagnostics.DebuggerHidden> _" & VB.vbNewLine & _       "            <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> _" & VB.vbNewLine & _       "            Public Overrides Function ToString() As String" & VB.vbNewLine & _       "                Return MyBase.ToString" & VB.vbNewLine & _       "            End Function" & VB.vbNewLine & _       "        End Class" & VB.vbNewLine & _       ""        ProjectCode.Append(code)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?