0
我有一个类,其中字段中的一个是枚举类型数组:回路通过与枚举阵列的类
Public Enum InvalidEmailType
Unkown
TrailingSpace
InnerSpace
TrailingPeriod
MissingAtSign
MultipleAtSigns
FakeEmail
PhoneExtension
End Enum
Public Class CustomerClass
Public CustomerName As String
Public LDCCode As Integer
Public LDCName As String
Public LDCAccountNo As String
Public Commodity As String
Public Email As String
Public ValidEmail As Boolean
Public Suggestion As String
Public Errortype = [Enum].GetValues(GetType(InvalidEmailType))
Public ErrorDescription As String
End Class
正如我将值添加到ERRORTYPE阵列,我需要编写为一个单一ErrorDescription中用户可以轻松阅读。 ErrorDescription字段的作用类似于1个字中所有潜在错误的摘要。
但首先我需要确定有多少InvalidEmailType.Unkown实例在那里。
为此我写了一个函数来计算未知数的数量。
我的问题是如何通过类中的数组你循环和匹配,以枚举?
这是我试过到目前为止:
Public Shared Function ErroTypeMessage(customer As CustomerClass) As String
Dim Instances As Integer = 0
For Each value In customer.Errortype
If value. <> InvalidEmailType.Unkown Then 'here is the problem
End If
Next
End Function
更新。这是新的功能。我仍然无法得到精确的匹配
Public Shared Function ErroTypeMessage(customer As CustomerClass) As String
Dim Instances As Integer = 0
ErroTypeMessage = Nothing
For Each value In customer.Errortype
If value <> InvalidEmailType.Unkown Then 'does not match properly
Instances = +1
Else
ErroTypeMessage = value.ToString
End If
Next
If Instances > 1 Then
ErroTypeMessage = "Multiple"
ElseIf Instances = 1 Then
'do nothing
Else
ErroTypeMessage = "Unkown"
End If
End Function
我已经解决了这个问题。
Public Shared Function ErroTypeMessage(customer As CustomerClass) As String
Dim Instances As Integer = 0
ErroTypeMessage = Nothing
Dim temp As String
For Each value In customer.Errortype
temp = DirectCast([Enum].Parse(GetType(InvalidEmailType), value.ToString), InvalidEmailType)
If temp <> InvalidEmailType.Unkown Then
ErroTypeMessage = temp
Instances += 1
End If
Next
If Instances > 1 Then
ErroTypeMessage = "Multiple"
ElseIf Instances = 1 Then
ErroTypeMessage = CType(ErroTypeMessage, InvalidEmailType).ToString()
ElseIf Instances = 0 Then
ErroTypeMessage = "Unkown"
End If
End Function
问题是什么?发布错误,如果有的话。 –
错误类型是否可以多次出现? –
大部分时间ErrorType将是未知的。 这个数组目前持有大约10个值,其中90%将是未知的。但其中一些会有2个值不是未知的,为此我需要编写一个汇总错误描述 –