我只需要知道lambda表达式如何将C#转换为vb.net。
if ((object)publicProperties != null && publicProperties.Any())
{
return publicProperties.All(p =>
{
var left = p.GetValue(this, null);
var right = p.GetValue(other, null);
if (typeof(TValueObject).IsAssignableFrom(left.GetType()))
{
//check not self-references...
return Object.ReferenceEquals(left, right);
}
else
return left.Equals(right);
});
}
在vb中,表达式如下:
Dim left = Nothing
Dim Right = Nothing
If DirectCast(publicProperties, Object) IsNot Nothing AndAlso publicProperties.Any() Then
Return publicProperties.All(Function(p) (left() = p.GetValue(Me, Nothing))(Right() = p.GetValue(other, Nothing)))
If GetType(TValueObject).IsAssignableFrom(left.[GetType]()) Then
'check not self-references...
Return [Object].ReferenceEquals(left, Right)
Else
Return left.Equals(Right)
End If
Else
Return True
End If
我想知道这个表达是否正确,谢谢
答案 0 :(得分:0)
您的VB版本看起来并不健康。 试试这个:
If CObj(publicProperties) IsNot Nothing AndAlso publicProperties.Any() Then
Return publicProperties.All(Function(p)
'check not self-references...
Dim left = p.GetValue(Me, Nothing)
Dim right = p.GetValue(other, Nothing)
If GetType(TValueObject).IsAssignableFrom(left.GetType()) Then
Return Object.ReferenceEquals(left, right)
Else
Return left.Equals(right)
End If
End Function)
End If