mercredi 20 mai 2015

GetMethods with GetCustomAttributes

Situation: Currently I am reading all available functions and methods from specific class with reflection. All the functions in the class does have an attribute section like this

[ImportFunctionAttribute("myFunction1", 1, ImportAttribute.SourceType.Type1)]
public ImportStatusDetails myFunction1()
{
}

[ImportFunctionAttribute("myFunction2", 2, ImportAttribute.SourceType.Type2)]
public ImportStatusDetails myFunction2()
{
}

To get all the methods in the given class I use this code

// get the public methods out of import class order by class name
var importMethods = (typeof (Import)).GetMethods(
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

Problem: Using the GetMethods-Method will give me both functions - but I only want to get the method of type ImportAttribute.SourceType.Type2.

Question: Is it possible to limit the results of the GetMethods-Method for given CustomAttributes like for example with GetMethods(...).Where() ?? What should I do to resolve this problem?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire