|
-
November 14th, 2011, 02:44 PM
#1
typeof(this) for a custom class
Hi, I have a few custom classes and forms, and a Debug form that recieves reports from all the other classes about what is they are doing. Messages are added to a listview chronologically as they are reported and to a tree-view to sort them into categories, thus allowing to focus on one type of message (user activity, SQL queries, etc)
My MainGUI creates the Debug form and reports to it, and every other Class/Form MainGUI creates reports to the MainGUI which then passes the report on.
For each Class/Form, I have an event:
Code:
public event CodeFlowHandler CodeFlowInfo;
private CodeFlowEventArgs codeFlowData = new CodeFlowEventArgs();
public delegate void CodeFlowHandler(UsersManager sender, CodeFlowEventArgs e);
// 'UsersManager' is the name of the class the eventHandler is being defined in
and a method to report:
Code:
private void Report(string msg, CodeFlowEventArgs.Categorias tipo, bool supress)
{
codeFlowData.Mensaje = msg;
codeFlowData.Categoria = tipo;
codeFlowData.SupressLast = supress; // useful for countdowns
if (CodeFlowInfo != null) CodeFlowInfo(this, codeFlowData);
}
What I'd like to do is just define a new 'Reporter' Class, so that I can just define that and have the event and the reporting encapsulated in it. The first problem I found so far is that the definition for the eventHandler includes the class type of the sender. What I would need to do is replace the "sender's" type for a generic declaration that will adapt to the class/form I instance the Reporter in.
That means the definition for the eventHandler would have to look something like:
Code:
public delegate void CodeFlowHandler(typeof(this) sender, CodeFlowEventArgs e);
But (obviously) that doesn't work!
I tried:
typeof(this) and typeof(base)
Type.GetType(this) and Type.GetType(base)
with no luck. Does anyone know how to get the type of a class? Thanks for the help!
Tags for this Thread
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
|