473,508 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decorating a partial class with a custom attribute

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
1 2126
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
1614
by: nospam | last post by:
Ok, I asked this question before and I also looked at the book "First Look at ASP.NET 2.0" I also read Paul wilson's web page explanation. HOWEVER...... The book and that web page talks about...
43
2566
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
16
2627
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
7
1730
by: Julian Jelfs | last post by:
Hi, I had an aspx pag in .Net 1.1 with a label on it. As such I had a code behind page with a declaration for that label. When I convert to Asp.Net 2.0 the code behind is converted to a...
10
2414
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
0
2102
by: Atul Thombre | last post by:
Hello, I am developing a custom membership provider. For that I built a prototype that uses a SQL Server 2005 database as a backend store. I implemented the class...
5
1966
by: SAL | last post by:
Hello, I would like to be able to set the WHERE clause of a select statement on the fly. I have a DataAccess layer designed using the DataSet designer and a BusinessLogic layer using classes. The...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.