By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

reflection

P: n/a
hi,
I have an assembly with many classes in it.
and some of the methods in those classes have this attribute StoredProcedure
before them, which takes different values . (i basically use it to store
storedprocedure names that this function calls.)

[MyCompany1.Data.StoredProcedure("spGetCustomers")]
[MyCompany1.Data.StoredProcedure("spGetSales")]
public void GetCustomers()
{
....
}
[MyCompany1.Data.StoredProcedure("spGetTotalSales")]
public void GetTotalSales()
{
....
}

etc.
what i want to do is iterate all those methods that have this attribute
StoredProcedure
and find out the value (eg: spGetCustomers and spGetSales in the first
case.)

how do i do this.

I havent figured out how do iterate all the classes
and
how do i find out if a method uses that attribute.
//This simply lists all the methods.
Type type = (typeof(MyCompany1.Dal.DataAccessClass1));
MethodInfo[] methodInfo = type.GetMethods();
for(int i =0;i< methodInfo.Length; i++)
{
Console.WriteLine("Name = " + methodInfo[i].ToString());

}

am i on the right track?
thnx

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
frazer <ic***@hotmail.com> wrote:
I have an assembly with many classes in it.
and some of the methods in those classes have this attribute StoredProcedure
before them, which takes different values . (i basically use it to store
storedprocedure names that this function calls.)


<snip>

Use the MemberInfo.GetCustomAttributes or MemberInfo.IsDefined methods.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.