サンプル
Public Class SampleClass
Private Shared class1Array As Class1()
Private Shared singletonInstance As SampleClass
' コンストラクタです。(外部からのアクセス不可)
Private Sub New()
Me.LoadXmlFile()
End Sub
Public Shared Function GetInstance() As SampleClass
If singletonInstance Is Nothing Then
singletonInstance = New SampleClass()
End If
Return singletonInstance
End Function
Private Sub LoadXmlFile()
' 現在のコードを実行しているAssemblyを取得
Dim assembly As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly()
'ファイルを開く
Dim fs As System.IO.FileStream = _
assembly.GetManifestResourceStream("XMLFile1.xml")
'XmlSerializerオブジェクトの作成
Dim serializer As _
New System.Xml.Serialization.XmlSerializer(GetType(Class1))
'XMLファイルから読み込み、逆シリアル化する
class1Array = DirectCast(serializer.Deserialize(fs), Class1())
'閉じる
fs.Close()
End Sub
参考文献
http://hccweb1.bai.ne.jp/tsune-1/VisualBasic/singleton.htmlhttp://www.bnote.net/vb/singleton.shtml