Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is, but ultimately it's going to be a roundabout way, since you will get the <code>Type</code> instance from calling <code>GetType</code> on your instance that exposes the property, and then work on that(more often than not).</p> <p>In this specific case, your extension method isn't going to be able to get the attribute information because all you are passing to it is a string.</p> <p>Ultimately, what you need is something to get the <code>PropertyInfo</code> for the property from. Other answers are referring to the <code>Type</code>, what they lack is, this is not the only way to get the attribute information at the <code>PropertyInfo</code> which you want. </p> <p>You can do that by passing a <code>Type</code> instance with a string, presumably, with the property name, so you can call <code>GetProperty</code> on the <code>Type</code>. </p> <p>Another way of doing this since C# 3.0 has been to have a method that takes an <code>Expression&lt;T&gt;</code> and then use the parts of the <code>Expression</code> to get at the <code>PropertyInfo</code>. In this case, you would take an <code>Expression&lt;Func&lt;string&gt;&gt;</code> or something where <code>TResult</code> is string. </p> <p>Once you have the <code>PropertyInfo</code>, you can call <code>GetCustomAttributes</code> on it, and look for your attribute.</p> <p>The advantage to the expression approach is that <code>Expression&lt;T&gt;</code> derives from <code>LambdaExpression</code>, which you can call <code>Compile</code> on, and then call to get the actual value, if you need it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload