c# - Issue finding custom attributes -


i trying find methods in assembly have custom attribute. have tried other solutions posted on here, cant seem results on methods have attribute type looking for. can point out doing wrong.

[attributeusage(attributetargets.all)] public class rpcattributetype : attribute {     private string _name;     private double _version;      public double version     {         { return _version; }         set { _version = value; }     }      public string name     {         { return _name; }         set { _name = value; }     }      public rpcattributetype(string name)     {         name = name;         version = 1.0;     } }       public rpcmodule()     {         try         {                assembly assembly = assembly.reflectiononlyload("parser");               var results = customattributedata.getcustomattributes(assembly);              showattributedata(results);           }         catch(exception ex)         {             console.writeline(ex.message);          }      }      [rpcattributetype("select")]     public datarow[] select(string expression)     {         return messagedatatable.select(expression);     } 

you can fetch list of methods using rpcattributetype

var results = assembly.gettypes().selectmany(t => t.getmethods()) .where(m => m.getcustomattributes(typeof(rpcattributetype), true).count() > 0).tolist(); 

edit: based on comment

when assigning assembly use

var assembly = assembly.getexecutingassembly(); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -