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

Decorating a partial class with a custom attribute

P: n/a
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;
}

Jul 17 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
there is little voodoo. every page is complied to a dll (if batching is
on, several pages may endup in the same dll). if your site is not
precompiled then the page dll's are created on first reference.

note: asp.net site run from temp folders were all the dll's are copied
to, and new compiles done. this is so site dll's can be updated (avoid
inuse error with copy).

-- bruce (sqlwork.com)

ha******@hotmail.com wrote:
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;
}
Jul 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.