Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Pass a C# property name as a parameter to an utility class method

$
0
0

Is it possible to pass a property of a class to a method (outside of the class) and then retrieve that property's Description?

For example:

public class Foo
{
  [Description("Tells whether something is true or not.")]
  public bool someFlag;

  public DoSomethingNeat()
  {
    MyUtility.getDescription(someFlag);
  }
}

And then the pseudo-code in a utility class:

public static class MyUtility
{
  public static string getDescription(??? property)
  {
    return property.Description;
  }
}
I suppose it might be necessary additionally to pass the type that the property belongs to.

Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>