R
Ralfeus
Hi all.
I have a class, which has some data. I work with list of objects of
this class. The data of each object can have different types. For each
type of data should has its own Value property to be correct. It looks
like this:
public class DataElementInt32 : DataElement
{
public override object Value
{
get
{
try
{
return Convert.ToInt32(ExtractData());
}
catch (Exception)
{
return null;
}
}
}
public DataElementInt32()
: base(typeof(System.Int32))
{
}
}
public class DataElementString : DataElement
{
public override object Value
{
get
{
try
{
return ExtractData().ToString();
}
catch (Exception)
{
return null;
}
}
}
public DataElementString()
: base(typeof(System.String))
{
}
}
I suspect I'll need some more such classes for another types in the
future (may be boolean, float....). So the question: is it possible to
reduce classes number using some template or something like this?
Thanks
I have a class, which has some data. I work with list of objects of
this class. The data of each object can have different types. For each
type of data should has its own Value property to be correct. It looks
like this:
public class DataElementInt32 : DataElement
{
public override object Value
{
get
{
try
{
return Convert.ToInt32(ExtractData());
}
catch (Exception)
{
return null;
}
}
}
public DataElementInt32()
: base(typeof(System.Int32))
{
}
}
public class DataElementString : DataElement
{
public override object Value
{
get
{
try
{
return ExtractData().ToString();
}
catch (Exception)
{
return null;
}
}
}
public DataElementString()
: base(typeof(System.String))
{
}
}
I suspect I'll need some more such classes for another types in the
future (may be boolean, float....). So the question: is it possible to
reduce classes number using some template or something like this?
Thanks