Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm stuck translating this from C into VB - Can anyone assist?

Call:
C#
if (e.PropertyName == GetPropertyName(() => Customer.FirstName))
{
  //Do Something
}


Function:
C#
(Expression<func><t>> expression)
{
   MemberExpression memberExpression=(MemberExpression)expression.Body;
   return memberExpression.Member.Name;
}</t></func>


As described here: Getting Property Name using LINQ [^]
Posted
Updated 12-Sep-11 23:18pm
v3

1 solution

You could try this

VB
If e.PropertyName = GetPropertyName(Function() Customer.FirstName) Then
End If


Function:-
VB
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!
 
Share this answer
 
v2
Comments
a_rikah 13-Sep-11 9:00am    
That's exactly what was needed!
Shimmy Weitzhandler 9-Jun-12 20:05pm    
Doesn't work. It returns a compiler generated name "$VB$Local_NewProperty".
Member 9673374 26-Jan-13 12:16pm    
Thank You Wayne Gaylard!
This works perfectly for me!
It helped me a lot!

João Araújo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900