I have a class that is maps to a field in a database. The class only cares about the name of the field and its related .NET type. The type can be string, int, datetime, etc.
class Foo()
{
string Name { get; set; }
Type FooType { get; set; }
}
I have another class that inherits from Foo that adds a property for a value. Right now I store the value as an object and use a switch statement to box the value based on the base classes FooType.
class FooWithStuff() : Foo
{
object Value { get; set; }
}
Is there way to implement this with generics to give type safety for the values?
Edit: I have made the key requirement bold. When declaring a list say Foo it needs a type. If I were doing this against custom classes I would create and interface and use that. However here I am using int, string, DateTime, etc. Int is a struct, string is an object, so a Foo< object> does not work for both.