2012-09-25 30 views
-1

我只需要知道lambda表达式C#如何将vb.net。在vb.net中表达的这个lambda表达式

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 

不知这个表达式将是正确的,感谢

+1

你真的需要反射来比较对象吗? –

+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