如何创建if语句来检查已删除案例的文档,或检查是否存在文档以及是否存在? 如果没有找到文档或列表为空,我想返回一个空的文档列表,如果返回不是列表,则不返回任何内容。
我的情景:
我有一个方法 GetDocuments ,在尝试获取已删除的案例事件或没有文档的文档时,可能会抛出对象引用错误。
我想修改我的方法
我是否需要添加if语句来检查文档是否存在或是否返回了文档列表?我不知道该怎么做
Imports System.Xml
Imports System.Text
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
''' <summary>
''' Retrieve all documents associated to the spcified case event.
''' </summary>
''' <param name="aintCaseEventIntegrationID">The integration id value that identifies the case.</param>
''' <returns>An array of Document objects.</returns>
''' <remarks></remarks>
<System.EnterpriseServices.AutoComplete()> _
Shared Function GetDocuments(ByVal aintCaseEventIntegrationID As Integer, Optional ByVal ablnUsePrimaryDatastoreOnly As Boolean = False) As List(Of Document)
Dim objDocumentsArray() As Document = Msc.Integration.Mncis.Library.v4.Document.GetForEntity(aintCaseEventIntegrationID, udtDocumentAttachedEntityType.CaseEvent, ablnUsePrimaryDatastoreOnly)
Dim objDocumentsList As New List(Of Document)
Dim objDocument As Document
For Each objDocument In objDocumentsArray
objDocumentsList.Add(objDocument)
Next
Return objDocumentsList
End Function
答案 0 :(得分:0)
目前还不清楚你的问题是什么。我只能假设它是objDocumentsArray。
Shared Function GetDocuments(ByVal aintCaseEventIntegrationID As Integer, Optional ByVal ablnUsePrimaryDatastoreOnly As Boolean = False) As List(Of Document)
Dim objDocumentsArray() As Document = Msc.Integration.Mncis.Library.v4.Document.GetForEntity(aintCaseEventIntegrationID, udtDocumentAttachedEntityType.CaseEvent, ablnUsePrimaryDatastoreOnly)
Dim objDocumentsList As New List(Of Document)
If objDocumentsArray IsNot Nothing Then
objDocumentsList.AddRange(objDocumentsArray)
End If
Return objDocumentsList
End Function
不要在变量前加上vb.net中的类型。而不是aintCaseEventIntegrationID只有caseEventIntegrationID。