| 1 | #Region "Microsoft.VisualBasic::905e5cd916322d64cd29028dbf3d0ce8, Microsoft.VisualBasic.Core\ComponentModel\SingletonHolder.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Class SingletonHolder |
| 35 | ' |
| 36 | ' Properties: Instance |
| 37 | ' |
| 38 | ' Constructor: (+1 Overloads) Sub New |
| 39 | ' |
| 40 | ' |
| 41 | ' /********************************************************************************/ |
| 42 | |
| 43 | #End Region |
| 44 | |
| 45 | '! |
| 46 | '@file SingletonHolder.cs |
| 47 | '@author Woong Gyu La a.k.a Chris. <juhgiyo@gmail.com> |
| 48 | ' <http://github.com/juhgiyo/epForceDirectedGraph.cs> |
| 49 | '@date September 27, 2013 |
| 50 | '@brief SingletonHolder Interface |
| 51 | '@version 2.0 |
| 52 | ' '@section LICENSE |
| 53 | ' 'The MIT License (MIT) |
| 54 | ' 'Copyright (c) 2013 Woong Gyu La <juhgiyo@gmail.com> |
| 55 | ' 'Permission is hereby granted, free of charge, to any person obtaining a copy |
| 56 | 'of this software and associated documentation files (the "Software"), to deal |
| 57 | 'in the Software without restriction, including without limitation the rights |
| 58 | 'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 59 | 'copies of the Software, and to permit persons to whom the Software is |
| 60 | 'furnished to do so, subject to the following conditions: |
| 61 | ' 'The above copyright notice and this permission notice shall be included in |
| 62 | 'all copies or substantial portions of the Software. |
| 63 | ' 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 64 | 'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 65 | 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 66 | 'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 67 | 'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 68 | 'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 69 | 'THE SOFTWARE. |
| 70 | ' '@section DESCRIPTION |
| 71 | ' 'An Interface for the SingletonHolder Class. |
| 72 | ' ' |
| 73 | |
| 74 | Imports System.Runtime.CompilerServices |
| 75 | |
| 76 | Namespace ComponentModel |
| 77 | |
| 78 | ''' <summary> |
| 79 | ''' An Interface for the SingletonHolder Class.(存储单体模式的对象实例) |
| 80 | ''' </summary> |
| 81 | ''' <typeparam name="T">泛型T必须是含有一个无参数的构造函数的</typeparam> |
| 82 | Public NotInheritable Class SingletonHolder(Of T As New) |
| 83 | |
| 84 | Shared _instance As T |
| 85 | |
| 86 | Private Sub New() |
| 87 | End Sub |
| 88 | |
| 89 | ''' <summary> |
| 90 | ''' 目标类型的唯一单个实例 |
| 91 | ''' </summary> |
| 92 | ''' <returns></returns> |
| 93 | Public Shared ReadOnly Property Instance() As T |
| 94 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 95 | Get |
| 96 | If _instance Is Nothing Then |
| 97 | _instance = New T() |
| 98 | End If |
| 99 | Return _instance |
| 100 | End Get |
| 101 | End Property |
| 102 | End Class |
| 103 | End Namespace |