Linq使用VB.Net获取属性名称 [英] Linq Get Property Name using VB.Net
本文介绍了Linq使用VB.Net获取属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直无法将其从C转换为VB-有人可以协助吗?
致电:
I''m stuck translating this from C into VB - Can anyone assist?
Call:
if (e.PropertyName == GetPropertyName(() => Customer.FirstName))
{
//Do Something
}
功能:
Function:
(Expression<func><t>> expression)
{
MemberExpression memberExpression=(MemberExpression)expression.Body;
return memberExpression.Member.Name;
}</t></func>
如此处所述:使用LINQ获取属性名称 [
As described here: Getting Property Name using LINQ [^]
推荐答案
您可以尝试此
You could try this
If e.PropertyName = GetPropertyName(Function() Customer.FirstName) Then
End If
功能:-
Function:-
Public Function GetPropertyName(Of T)(ByVal expression As Expressions.Expression(Of Func(Of T))) As String
Dim memberExpression As Expressions.MemberExpression = DirectCast(expression.Body, Expressions.MemberExpression)
Return memberExpression.Member.Name
End Function
让我知道这是否有效,因为它不在我的脑海!
Let me know if this works, as this is off the top of my head!
这篇关于Linq使用VB.Net获取属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文