Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming you meant <code>searchMethod</code> to be a variable of type <code>Func&lt;TSearch, TReturn&gt;</code> and <code>mySearchSpec</code> as some implementation of <code>ISearchSpecification&lt;TSearch&gt;</code>, then you are basically asking how to get attributes on a class.</p> <p>For this, use something like:</p> <pre><code>object[] attrs = typeof(mySearchSpec).GetCustomAttributes(false); </code></pre> <p>Assuming that the <code>mySearchSpec</code> type is public, otherwise you may need a different overload for <code>GetCustomAttributes</code></p> <p><strong>Addendum</strong>:<br> Based on your revised question, to get the attributes on a method on the actual type of <code>spec</code> used:</p> <pre><code>Type t = spec.GetType(); MethodInfo m = t.GetMethod("nameOfMethodToBeCalledHere"); object[] attrs = m.GetCustomAttributes(false); </code></pre> <p>Again, note that you may need overloads for <code>GetMethod</code> or <code>GetCustomAttributes</code> depending on the implementation of the actual class.</p> <p><strong>Note:</strong><br> It does seem however like you might be asking for the method called in <code>return searchMethod(spec);</code>, but that is <code>searchMethod</code> and not some method on <code>spec</code> at all.</p> <p>If you want attributes on <code>searchMethod</code> (nothing to do with <code>spec</code>):</p> <pre><code>MethodInfo m = searchMethod.Method; object[] attrs = m.GetCustomAttributes(false); </code></pre> <p>I think that now covers all permutations of meaning...</p>
 

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