I'm developi开发者_如何学Gong a website that has modular section. I would like it that when a new aspx (and aspx.cs) file is placed in a subdirectory of the application that I can ask the class some information...
The idea is that when the file is placed in the directory a new menu item is added to the menu. To do that I need to "ask the class" for its name, icon, description, etc.
Is there a way to determine the class that is defined in codebehind file and to instantiate an instance of it?
I know I could look for and parse a config file for each plugin but I would rather not have to go that route.
The "standard" method for this is the config file you mention, in the form of a Sitemap. You'll get a lot of good features out of it by doing it that way, like breadcrumbs and so forth. I know this is exactly the answer you asked not to get, but there it is anyway.
If you insist, though, there's nothing stopping you from using MapPath and actually searching the disk for .aspx files, parsing them to pull out certain info (like class name), and then doing whatever you like.
But SiteMap is better, unless you have some very strange requirement. Note that your sitemap can come from a database or another dynamic source, it doesn't have to be an XML file.
精彩评论