I have numerous resx files in my project for localization for various languages.
I need to use static reflection to be able to get the property name of the resx class when using dot notation. For example:
MyStrings.This_is_a_test_string
I read several posts on static reflection and found the GetProperty method example which I converted from C# to VB using an online converter.
I attempted to use the following code:
Dim strPropertyName As PropertyInfo = GetProperty(DevStrings.This_is_a_test_string)
Public Function GetProperty(Of TEntity)(ByVal expression As Expression(Of Func(Of TEntity, Object))) As PropertyInfo
Dim memberExpression As MemberExpression = TryCast(expression.Body, MemberExpression)
If memberExpression Is Nothing Then Throw New InvalidOperationException("Not a member access.")
Return TryCast(memberExpression.Member, PropertyInfo)
End Function
However, it results in this error:
BC36645: Data type(s) of the type parameter(s) in method 'Public Function GetProperty(Of TEntity)(ByVal expression As Expression(Of Func(Of TEntity, Object))) As PropertyInfo' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
I don't know anything about the reflection classes so I need very specific, step-by-step help.
Can anyone provide me with a working example in VB where I can get the name of the property reflected back to me a string?
In other words when I pass the parameter MyStrings.This_is_a_test to the reflection function I get back the string "This is a test"?
Thanks for the help!
Aucun commentaire:
Enregistrer un commentaire