H
hardieca
Hi!
I decorate my unfinished classes and methods with a custom TODO
attribute (as in things To Do). Using reflection, I am then able to
parse through my classes and output all TODOs to a list I can examine
to figure out what is left to be done in my application.
The attribute is coded thusly:
AttributeUsage((AttributeTargets.Class | AttributeTargets.Method),
AllowMultiple=true)]
public class ToDoAttribute : System.Attribute {
// Private member data
private string _comment;
private string _date;
private string _programmer;
public ToDoAttribute(string programmer, string myDate) {
this._programmer = programmer;
this._date = myDate;
}
public string Comment {
get {
return _comment;
}
set {
_comment = value;
}
}
public string LogDate {
get {
return _date;
}
}
public string Programmer {
get {
return _programmer;
}
}
}
All is well and good until I try to decorate a partial class in the
code-behind of an ASP.Net page like this:
[ToDo("hardie.ca", "2007-07-16", Comment = "Fix recursion!")]
partial class admin_Section : System.Web.UI.Page
The problem is the function that examines all the types in my
application only discovers the TODO decorations if they are decorating
classes or methods that reside in the App_Code folder. I would like to
be able to discover these attributes in webpages that reside outside
of App_Code. I understand that assemblies are generated dynamically
using voodoo I don't fully comprehend, but I would have thought that
by calling AppDomain.currentDomain.GetAssemblies() I would have been
able reference all assemblies.
I am trying to output a webpage that publishes my list of TODOs, is it
possible that the assemblies that contain the pages with the partial
classes I'm decorating have not been created when I try to discover
their attributes? Any help would be very much appreciated!
The page that lists all TODOs has the following method:
protected void Page_Unload(object sender, System.EventArgs e) {
AppDomain currentDomain = AppDomain.CurrentDomain;
Assembly[] assems = currentDomain.GetAssemblies();
string alltypes = "";
Assembly assem;
foreach (assem in assems) {
Type[] types = assem.GetTypes();
foreach (Type t in types) {
MemberInfo inf = t;
object[] attributes;
attributes =
inf.GetCustomAttributes(typeof(ToDoAttribute), false);
foreach (object attribute in attributes) {
ToDoAttribute todo = (ToDoAttribute)attribute;
alltypes = (alltypes + ("<p>" + (t.ToString() +
"<br>")));
alltypes = (alltypes + ("Programmer: "
+ (todo.Programmer + "<br>")));
alltypes = (alltypes + ("Date: "
+ (todo.LogDate + "<br>")));
alltypes = (alltypes + ("Comments: "
+ (todo.Comment + "</p>")));
}
}
}
this.lblLabel.Text = alltypes;
}
I decorate my unfinished classes and methods with a custom TODO
attribute (as in things To Do). Using reflection, I am then able to
parse through my classes and output all TODOs to a list I can examine
to figure out what is left to be done in my application.
The attribute is coded thusly:
AttributeUsage((AttributeTargets.Class | AttributeTargets.Method),
AllowMultiple=true)]
public class ToDoAttribute : System.Attribute {
// Private member data
private string _comment;
private string _date;
private string _programmer;
public ToDoAttribute(string programmer, string myDate) {
this._programmer = programmer;
this._date = myDate;
}
public string Comment {
get {
return _comment;
}
set {
_comment = value;
}
}
public string LogDate {
get {
return _date;
}
}
public string Programmer {
get {
return _programmer;
}
}
}
All is well and good until I try to decorate a partial class in the
code-behind of an ASP.Net page like this:
[ToDo("hardie.ca", "2007-07-16", Comment = "Fix recursion!")]
partial class admin_Section : System.Web.UI.Page
The problem is the function that examines all the types in my
application only discovers the TODO decorations if they are decorating
classes or methods that reside in the App_Code folder. I would like to
be able to discover these attributes in webpages that reside outside
of App_Code. I understand that assemblies are generated dynamically
using voodoo I don't fully comprehend, but I would have thought that
by calling AppDomain.currentDomain.GetAssemblies() I would have been
able reference all assemblies.
I am trying to output a webpage that publishes my list of TODOs, is it
possible that the assemblies that contain the pages with the partial
classes I'm decorating have not been created when I try to discover
their attributes? Any help would be very much appreciated!
The page that lists all TODOs has the following method:
protected void Page_Unload(object sender, System.EventArgs e) {
AppDomain currentDomain = AppDomain.CurrentDomain;
Assembly[] assems = currentDomain.GetAssemblies();
string alltypes = "";
Assembly assem;
foreach (assem in assems) {
Type[] types = assem.GetTypes();
foreach (Type t in types) {
MemberInfo inf = t;
object[] attributes;
attributes =
inf.GetCustomAttributes(typeof(ToDoAttribute), false);
foreach (object attribute in attributes) {
ToDoAttribute todo = (ToDoAttribute)attribute;
alltypes = (alltypes + ("<p>" + (t.ToString() +
"<br>")));
alltypes = (alltypes + ("Programmer: "
+ (todo.Programmer + "<br>")));
alltypes = (alltypes + ("Date: "
+ (todo.LogDate + "<br>")));
alltypes = (alltypes + ("Comments: "
+ (todo.Comment + "</p>")));
}
}
}
this.lblLabel.Text = alltypes;
}