This is a multi-part message in MIME format.
------=_NextPart_000_0006_01C89660.C1AA00F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I do not know if what I am trying to do is impossible, however since I =
cannot work out how to do it I thought I would post it here in the hope =
of some assistance.
Consider the following code ...
using System;
public class Parameter<T> {
private T value;
public Parameter() {
}
public Parameter(T value)
: this() {
this.value =3D value;
}
public T Value {
get { return this.value; }
set { this.value =3D value; }
}
}
public class BooleanParameter : Parameter<Boolean> {
}
public class ByteParameter : Parameter<Byte> {
}
public class WordParameter : Parameter<UInt16> {
}
As you can see, this is a simple example where I am creating generic =
types that will all expose a 'Value' property, but each of the 'Value' =
properties will have a different data type.
If I want to create collections for these types, again this is fairly =
basic ...
using System.Collections.ObjectModel;
public class BooleanParameterCollection : =
Collection<BooleanParameter> {
}
public class ByteParameterCollection : Collection<ByteParameter> {
}
public class WordParameterCollection : Collection<WordParameter> {
}
However, what I actually want is to create a collection of Parameter<?> =
objects; that is, a single typed collection that can contain =
BooleanParameter, ByteParameter or WordParameter objects intermingled =
with each other and then determine which of the objects I am working =
with at run time.
I have tried various combinations of interfaces and base classes, but =
all to no avail. Is this possible, if so, can anybody help me see the =
light?
Thanks in advance.
Martin.
------=_NextPart_000_0006_01C89660.C1AA00F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I do not know if what I am trying to do =
is
impossible, however since I cannot work out how to do it I thought I =
would post
it here in the hope of some assistance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Consider the following code =
....</FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><FONT face=3DArial
size=3D2></FONT></FONT></FONT> </DIV><FONT face=3DArial =
size=3D2><FONT size=3D1>
<DIV></FONT><FONT color=3D#0000ff> using</FONT><FONT
size=3D1><FONT size=3D2> System;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT color=3D#0000ff> public</FONT> <FONT
color=3D#0000ff>class</FONT> <FONT color=3D#2b91af>Parameter</FONT><FONT =
size=3D1><FONT size=3D2><T> {</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT color=3D#0000ff>
private</FONT><FONT size=3D1><FONT size=3D2> T value;</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT color=3D#0000ff>
public</FONT><FONT size=3D1><FONT size=3D2> Parameter() {</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff>
public</FONT><FONT size=3D1><FONT size=3D2> Parameter(T =
value)</FONT></DIV>
<DIV></FONT><FONT size=3D2>
: <FONT color=3D#0000ff>this</FONT>() {</FONT><FONT
size=3D1></DIV>
<DIV></FONT><FONT color=3D#0000ff>
this</FONT><FONT size=3D1><FONT size=3D2>.value =3D
value;</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff>
public</FONT><FONT size=3D1><FONT size=3D2> T Value {</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>
get</FONT> { <FONT color=3D#0000ff>return</FONT> =
<FONT
color=3D#0000ff>this</FONT><FONT size=3D1><FONT size=3D2>.value; =
}</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff>
set</FONT> { <FONT color=3D#0000ff>this</FONT>.value =
=3D <FONT
color=3D#0000ff>value</FONT><FONT size=3D1><FONT size=3D2>; =
}</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV></FONT><FONT color=3D#0000ff></FONT> </DIV>
<DIV><FONT color=3D#0000ff> public</FONT> <FONT
color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>BooleanParameter</FONT> : <FONT
color=3D#2b91af>Parameter</FONT><<FONT =
color=3D#2b91af>Boolean</FONT><FONT
size=3D1><FONT size=3D2>> {</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff> public</FONT> <FONT =
color=3D#0000ff>class</FONT> <FONT color=3D#2b91af>ByteParameter</FONT> =
: <FONT
color=3D#2b91af>Parameter</FONT><<FONT =
color=3D#2b91af>Byte</FONT><FONT
size=3D1><FONT size=3D2>> {</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff> public</FONT> <FONT =
color=3D#0000ff>class</FONT> <FONT color=3D#2b91af>WordParameter</FONT> =
: <FONT
color=3D#2b91af>Parameter</FONT><<FONT =
color=3D#2b91af>UInt16</FONT><FONT
size=3D1><FONT size=3D2>> {</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>As you can see, this is a simple =
example where I am
creating generic types that will all expose a 'Value' property, but each =
of the
'Value' properties will have a different data type.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If I want to create collections for =
these types,
again this is fairly basic ...</FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><FONT face=3DArial
size=3D2></FONT></FONT></FONT> </DIV><FONT face=3DArial =
size=3D2><FONT size=3D1>
<DIV></FONT><FONT color=3D#0000ff> using</FONT><FONT
size=3D1><FONT size=3D2> =
System.Collections.ObjectModel;</FONT></FONT></DIV>
<DIV><FONT size=3D1><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff> public</FONT> <FONT =
color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>BooleanParameterCollection</FONT>
: <FONT color=3D#2b91af>Collection</FONT><<FONT
color=3D#2b91af>BooleanParameter</FONT><FONT size=3D1><FONT =
size=3D2>>
{</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff> public</FONT> <FONT =
color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>ByteParameterCollection</FONT> :
<FONT color=3D#2b91af>Collection</FONT><<FONT
color=3D#2b91af>ByteParameter</FONT><FONT size=3D1><FONT size=3D2>> =
{</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></FONT><FONT color=3D#0000ff> public</FONT> <FONT =
color=3D#0000ff>class</FONT> <FONT =
color=3D#2b91af>WordParameterCollection</FONT> :
<FONT color=3D#2b91af>Collection</FONT><<FONT
color=3D#2b91af>WordParameter</FONT><FONT size=3D1><FONT size=3D2>> =
{</FONT></DIV>
<DIV><FONT size=3D2> }</FONT></DIV></FONT></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>However, what I actually want is to =
create a
collection of <FONT color=3D#2b91af>Parameter</FONT><FONT size=3D1><FONT =
size=3D2><?> objects; that is, a single typed collection that can
contain <FONT color=3D#2b91af>BooleanParameter</FONT>, <FONT
color=3D#2b91af>ByteParameter</FONT> or <FONT
color=3D#2b91af>WordParameter</FONT> objects intermingled with each =
other and then
determine which of the objects I am working with at run
time.</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have tried various combinations of =
interfaces and
base classes, but all to no avail. Is this possible, if so, can anybody =
help me
see the light?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks in advance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Martin.</FONT></DIV></BODY></HTML>
------=_NextPart_000_0006_01C89660.C1AA00F0--
