MyWpfExtension.vb 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #If _MyType <> "Empty" Then
  2. Namespace My
  3. ''' <summary>
  4. ''' 用于定义“我的 WPF 命名空间”中的可用属性的模块
  5. ''' </summary>
  6. ''' <remarks></remarks>
  7. <Global.Microsoft.VisualBasic.HideModuleName()> _
  8. Module MyWpfExtension
  9. Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Devices.Computer)
  10. Private s_User As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.ApplicationServices.User)
  11. Private s_Windows As New ThreadSafeObjectProvider(Of MyWindows)
  12. Private s_Log As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Logging.Log)
  13. ''' <summary>
  14. ''' 返回正在运行的应用程序的应用程序对象
  15. ''' </summary>
  16. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>
  17. Friend ReadOnly Property Application() As Application
  18. Get
  19. Return CType(Global.System.Windows.Application.Current, Application)
  20. End Get
  21. End Property
  22. ''' <summary>
  23. ''' 返回有关主机计算机的信息。
  24. ''' </summary>
  25. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>
  26. Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.Computer
  27. Get
  28. Return s_Computer.GetInstance()
  29. End Get
  30. End Property
  31. ''' <summary>
  32. ''' 返回当前用户的信息。 如果希望使用当前的
  33. ''' Windows 用户凭据来运行应用程序,请调用 My.User.InitializeWithWindowsUser()。
  34. ''' </summary>
  35. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>
  36. Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.User
  37. Get
  38. Return s_User.GetInstance()
  39. End Get
  40. End Property
  41. ''' <summary>
  42. ''' 返回应用程序日志。可以使用应用程序的配置文件配置侦听器。
  43. ''' </summary>
  44. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>
  45. Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.Log
  46. Get
  47. Return s_Log.GetInstance()
  48. End Get
  49. End Property
  50. ''' <summary>
  51. ''' 返回项目中定义的 Windows 集合。
  52. ''' </summary>
  53. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>
  54. Friend ReadOnly Property Windows() As MyWindows
  55. <Global.System.Diagnostics.DebuggerHidden()>
  56. Get
  57. Return s_Windows.GetInstance()
  58. End Get
  59. End Property
  60. <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Never)>
  61. <Global.Microsoft.VisualBasic.MyGroupCollection("System.Windows.Window", "Create__Instance__", "Dispose__Instance__", "My.MyWpfExtenstionModule.Windows")>
  62. Friend NotInheritable Class MyWindows
  63. <Global.System.Diagnostics.DebuggerHidden()>
  64. Private Shared Function Create__Instance__(Of T As {New, Global.System.Windows.Window})(Instance As T) As T
  65. If Instance Is Nothing Then
  66. If s_WindowBeingCreated IsNot Nothing Then
  67. If s_WindowBeingCreated.ContainsKey(GetType(T)) = True Then
  68. Throw New Global.System.InvalidOperationException("The window cannot be accessed via My.Windows from the Window constructor.")
  69. End If
  70. Else
  71. s_WindowBeingCreated = New Global.System.Collections.Hashtable()
  72. End If
  73. s_WindowBeingCreated.Add(GetType(T), Nothing)
  74. Return New T()
  75. s_WindowBeingCreated.Remove(GetType(T))
  76. Else
  77. Return Instance
  78. End If
  79. End Function
  80. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1822:MarkMembersAsStatic")>
  81. <Global.System.Diagnostics.DebuggerHidden()>
  82. Private Sub Dispose__Instance__(Of T As Global.System.Windows.Window)(ByRef instance As T)
  83. instance = Nothing
  84. End Sub
  85. <Global.System.Diagnostics.DebuggerHidden()>
  86. <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Never)>
  87. Public Sub New()
  88. MyBase.New()
  89. End Sub
  90. <Global.System.ThreadStatic()> Private Shared s_WindowBeingCreated As Global.System.Collections.Hashtable
  91. <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> Public Overrides Function Equals(o As Object) As Boolean
  92. Return MyBase.Equals(o)
  93. End Function
  94. <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> Public Overrides Function GetHashCode() As Integer
  95. Return MyBase.GetHashCode
  96. End Function
  97. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1822:MarkMembersAsStatic")>
  98. <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)>
  99. Friend Overloads Function [GetType]() As Global.System.Type
  100. Return GetType(MyWindows)
  101. End Function
  102. <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Never)> Public Overrides Function ToString() As String
  103. Return MyBase.ToString
  104. End Function
  105. End Class
  106. End Module
  107. End Namespace
  108. Partial Class Application
  109. Inherits Global.System.Windows.Application
  110. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
  111. <Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1822:MarkMembersAsStatic")> _
  112. Friend ReadOnly Property Info() As Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo
  113. <Global.System.Diagnostics.DebuggerHidden()> _
  114. Get
  115. Return New Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo(Global.System.Reflection.Assembly.GetExecutingAssembly())
  116. End Get
  117. End Property
  118. End Class
  119. #End If