我试图在我得到它的值之前测试一个对象是否是什么,但是我得到一个错误"NullReferenceException"
发生在这里的第一行:
If Not ORInvoiceLineRet.InvoiceLineRet.ItemRef.FullName Is Nothing Then
li.FullName = ORInvoiceLineRet.InvoiceLineRet.ItemRef.FullName.GetValue()
End If
Run Code Online (Sandbox Code Playgroud)
System.NullReferenceException {"对象引用未设置为对象的实例."}
如何在不尝试处理try/catch中的错误的情况下测试?
涉及的对象越多越好:
ORInvoiceLineRet 什么都不是ORInvoiceLineRet.InvoiceLineRet 什么都不是ORInvoiceLineRet.InvoiceLineRet.ItemRef 什么都不是ORInvoiceLineRet.InvoiceLineRet.ItemRef.FullName 什么都不是所以这里唯一安全的方法是:
If ORInvoiceLineRet IsNot Nothing _
AndAlso ORInvoiceLineRet.InvoiceLineRet IsNot Nothing _
AndAlso ORInvoiceLineRet.InvoiceLineRet.ItemRef IsNot Nothing _
AndAlso ORInvoiceLineRet.InvoiceLineRet.ItemRef.FullName IsNot Nothing Then
li.FullName = ORInvoiceLineRet.InvoiceLineRet.ItemRef.FullName.GetValue()
End If
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
205 次 |
| 最近记录: |