-1

我只需要知道如何将 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

我想知道这个表达是否正确,谢谢

4

1 回答 1

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
于 2012-09-25T16:12:59.787 回答