PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Doctor/My Project/MyExtensions/MyWpfExtension.vb

#
Visual Basic | 121 lines | 99 code | 2 blank | 20 comment | 0 complexity | e0e3e176186fc47c4b834cd01ed4e050 MD5 | raw file
Possible License(s): GPL-2.0
  1. #If _MyType <> "Empty" Then
  2. Namespace My
  3. ''' <summary>
  4. ''' Module used to define the properties that are available in the My Namespace for 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. ''' Returns the application object for the running application
  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. ''' Returns information about the host computer.
  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. ''' Returns information for the current user. If you wish to run the application with the current
  33. ''' Windows user credentials, call 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. ''' Returns the application log. The listeners can be configured by the application's configuration file.
  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. ''' Returns the collection of Windows defined in the project.
  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})(ByVal 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(ByVal 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