Problem with Method Reflection Linq Query

E

eric

I've created a class that is comprised mostly of functions. Some of the
functions in the class have a custom attribute class defined. The
constructor of this attribute class takes a single argument unique to each
function. I'm trying to create a Linq query that will 1) only look at the
functions with this custom attribute defined and 2) return the function that
is defined with custom attribute class that contains a value I'm looking for

var qry = from method in type.GetMethods()
where method.MethodAttributes

The above is what I've started with but I'm not sure where to take it from
here.

TIA
..
 
J

Jon Skeet [C# MVP]

eric said:
I've created a class that is comprised mostly of functions. Some of the
functions in the class have a custom attribute class defined. The
constructor of this attribute class takes a single argument unique to each
function. I'm trying to create a Linq query that will 1) only look at the
functions with this custom attribute defined and 2) return the function that
is defined with custom attribute class that contains a value I'm looking for

var qry = from method in type.GetMethods()
where method.MethodAttributes

The above is what I've started with but I'm not sure where to take it from
here.

var query = from method in type.GetMethod()
from MyAttribute attr in
method.GetCustomAttributes(typeof(MyAttribute), false)
where attr.Whatever == "My value"
select method;

Untested, but it should work :)
 
E

eric

Thank you much.


Jon Skeet said:
var query = from method in type.GetMethod()
from MyAttribute attr in
method.GetCustomAttributes(typeof(MyAttribute), false)
where attr.Whatever == "My value"
select method;

Untested, but it should work :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top