|
-
Nov 27th, 2009, 01:16 PM
#1
Thread Starter
Frenzied Member
Using HttpHandler and Reflection
I have another ongoing thread regarding this topic, but I think it was getting a little messy and lost, so I thought I start another one focusing more on the remaining issues.
I have created a custom HttpHandler which handles processing of web requests. This will be utilized by end user developers. They will include my handler dll in their ASP.NET project. The structure would look something like:
Code:
Solution 'WebApp1'
WebApp1
App_Code
Class1.vb
bin
HttpHandler.dll
"Class1.vb" is the developer's own class, and "HttpHandler.dll" is my class that they are referencing.
My HttpHandler class contains an attribute called "CustomAttribute". The user's Class1 needs to decorate any subs/functions they want exposed to my HttpHandler class with CustomAttribute.
This is where I'm a little lost. I need to make use of Reflection to get a list of all subs/functions in the user's Class1 and determine if they are decorated with "CustomAttribute". There is some debate as to whether or not I the user has to inherit from my class. I need to be able to call this line of code on the user's Class1:
Code:
Dim methods As MethodInfo() = Me.GetType.GetMethods
BUT, I will obviously not know what name the user gave their class. So I need to somehow replace the "me" in the above code with, their class name. But how can I do this without knowing their class name? They can also have many classes so I need to somehow find all of their class and iterate over all their methods.
Any help would be greatly appreciated.
-
Nov 27th, 2009, 02:30 PM
#2
Re: Using HttpHandler and Reflection
Hey,
If I am not mistaken, I think this will cover it:
http://www.codeproject.com/KB/aspnet...alization.aspx
Also, if you are finished in your other thread, you really should mark it resolved, and specify that the discussion has moved to here.
Gary
-
Nov 27th, 2009, 02:42 PM
#3
Thread Starter
Frenzied Member
Re: Using HttpHandler and Reflection
Thanks gep13. I have marked my other post as Resolved with a link back to this one. I will take a look at the link you provided and let you know how it goes.
-
Nov 27th, 2009, 02:46 PM
#4
Re: Using HttpHandler and Reflection
Hey,
Sounds like a plan! Hopefully it will have what you are looking for 
Gary
-
Nov 27th, 2009, 03:53 PM
#5
Re: Using HttpHandler and Reflection
Since the methods can be anywhere, you start by enumerating all of the classes in the assembly. You then loop through the methods in each class. You can use Assembly.Load for this. However, you need to know which assembly you're going to be looking at, so you need to either:
1) get the developers to tell you this.
2) Forget Assembly.Load and use Assembly.GetExecutingAssembly instead which also gives you a reference to the assembly.
Once you have the assembly, find its classes. To do this, loop through its Assembly.GetTypes. This is where your code finally comes in.
vb Code:
Dim methods As MethodInfo() = t.GetMethods()
Where t is the iterator in your GetTypes loop.
Then look for your methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|