How to pass the PropertyInfo of a property as parameter in a attribute?

You can't, I'm afraid. It may be possible in IL - I'm not sure - but you can't do it in C The closest you could come would be: SortBefore(typeof(A), "Name") and get the attribute to find the property at execution time. And yes, this is very brittle - if you do this, I'd add a unit test which finds all the attributes in an assembly and checks they're all valid.

You can't, I'm afraid. It may be possible in IL - I'm not sure - but you can't do it in C#. The closest you could come would be: SortBefore(typeof(A), "Name") and get the attribute to find the property at execution time.

And yes, this is very brittle - if you do this, I'd add a unit test which finds all the attributes in an assembly and checks they're all valid.

Even the C# typeof operator is implemented by the compiler as a ldtoken followed by a call to Type. GetTypeFromHandle(). The PropertyInfo is a particularly interesting case because the ldtoken IL instruction can't take a Property metadata token as an argument, and there is no RuntimePropertyHandle type.

However, the getter and/or setter methods can be obtained in IL via (this is not valid IL but shows the instructions). Unfortunately there is no direct way in C# to produce this code with the level of type safety that the typeof() operator provides. Ldtoken call MethodBase.

GetMethodFromHandle The answer to this earlier question shows how to get the PropertyInfo from the MethodInfo. Jon's answer is correct about the solution you'll probably have to use.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions