要素が存在するかどうかを確認しようとしている xml アリがあり、存在する場合は値
xml の例がある場合:
<Attributes Version="1.0.2012">
<OpenAtStart>True</OpenAtStart>
<RefreshTime>60</RefreshTime>
</Attributes>
OpenAtStart が存在するかどうかを確認してから、値があるかどうかを確認したいので、以下の関数を作成しました。
Private Function existsOrEmpty(ByVal type As Type, ByVal node As XmlNode, ByVal defaultValue As Object) As Object
Dim myObj As Object = Nothing
Try
Cursor.Current = Cursors.WaitCursor
If node IsNot Nothing Then
Select Case type
Case GetType(Integer)
If Integer.TryParse(node.InnerText, myObj) = False Then
myObj = defaultValue
End If
Case GetType(Double)
If Double.TryParse(node.InnerText, myObj) = False Then
myObj = defaultValue
End If
Case GetType(Boolean)
If Boolean.TryParse(node.InnerText, myObj) = False Then
myObj = defaultValue
End If
Case Else
myObj = node.InnerText
End Select
Else
myObj = defaultValue
End If
Catch ex As Exception
gError.GetAppEx(ex, CLASS_NAME & ".existsOrEmpty")
Finally
Cursor.Current = Cursors.Default
End Try
Return myObj
End Function
これは良い方法ですか、それともより良い/より速い方法がありますか?
ありがとう