S
Simon Harvey
Hi all,
I hope someone can help me with the following:
I have a number of usercontrols that I've made which provides certain audit
functions for any data inserted into it. Each audit control is a descendant
of BaseAuditControl. Descedants include AuditableTextControl and
AuditableBoolControl.
The problem I'm having is determining which control I'm actually dealing
with at any one time. I often need to treat them generically for most of a
method and then need to implemement some logic that is specific to the
particlar type of audit control.
An example:
To update the main ui element of my audit control I make a method in my base
control. I need to be able to get the type of the current instance that I'm
dealing with, via the 'this' keyword, and then compare it to the various
types of AuditControl that I have made. Something like this:
if((this.GetType()) == (typeof(AuditableTextControl)){
//Do one thing
return false;
}
if((this.GetType()) == (typeof(AuditableBoolControl)){
//Do another
return false;
}
The problem I'm getting is that the Types returned from each of the two
expressions are different.
this.GetType() returns something like ASP.AuditableTextControl_ascx
typeof(AuditableTextControl) returns
<mynamespace>.controls.AuditableTextControl
I don't understand whats going on behind the scenes, but it seems to me that
when you get the type of an actual object instance, it is different from
trying to get the type using just the class definition.
If anyone can help me figure out how to get a successful comparison between
them. I've tried to make a fake instance of an AuditableTextControl and then
tried to get the type of that, but that doesnt work either. Seems a bit
messy as well. I'm sure that there is a really easy way to day this
Thanks to anyone who can help with this.
Take care
Simon
I hope someone can help me with the following:
I have a number of usercontrols that I've made which provides certain audit
functions for any data inserted into it. Each audit control is a descendant
of BaseAuditControl. Descedants include AuditableTextControl and
AuditableBoolControl.
The problem I'm having is determining which control I'm actually dealing
with at any one time. I often need to treat them generically for most of a
method and then need to implemement some logic that is specific to the
particlar type of audit control.
An example:
To update the main ui element of my audit control I make a method in my base
control. I need to be able to get the type of the current instance that I'm
dealing with, via the 'this' keyword, and then compare it to the various
types of AuditControl that I have made. Something like this:
if((this.GetType()) == (typeof(AuditableTextControl)){
//Do one thing
return false;
}
if((this.GetType()) == (typeof(AuditableBoolControl)){
//Do another
return false;
}
The problem I'm getting is that the Types returned from each of the two
expressions are different.
this.GetType() returns something like ASP.AuditableTextControl_ascx
typeof(AuditableTextControl) returns
<mynamespace>.controls.AuditableTextControl
I don't understand whats going on behind the scenes, but it seems to me that
when you get the type of an actual object instance, it is different from
trying to get the type using just the class definition.
If anyone can help me figure out how to get a successful comparison between
them. I've tried to make a fake instance of an AuditableTextControl and then
tried to get the type of that, but that doesnt work either. Seems a bit
messy as well. I'm sure that there is a really easy way to day this
Thanks to anyone who can help with this.
Take care
Simon