I have a generic class that looks like this:
public interface IStationProperty
{
int Id { get; set; }
string Desc { get; set; }
object Value { get; }
Type ValueType { get; }
}
[Serializable]
public class StationProp<T> : IStationProperty
{
public StationProp()
{
}
public StationProp(int id, T val, string desc = "")
{
Id = id;
Desc = desc;
Value = val;
}
public int Id { get; set; }
public string Desc { get; set; }
public T Value { get; set; }
object IStationProperty.Value
{
get { return Value; }
}
public Type ValueType
{
get { return typeof(T); }
}
The property that gets the type is:
public Type ValueType
{
get { return typeof(T); }
}
So in my code, I have a loop pulling values (as string) from the db, here I want to do a type conversion (on the left side) so I can do a reliable value comparison.
I would like something like this:
var correctlyTypedVariable = (prop.ValueType) prop.Value;
I know this kind of thing has to be possible.