I'm pretty sure this is an uncommon usage scenario so I don't really know whether NHibernate supports it, but I'm looking for a little feedback on whether this sort of thing is possible.
I want the consumers of my domain model to be able to create a profile that has a collection Parameter objects. A parameter is structured like this:
Code:
public interface IParameter<T>
{
int Id
{
get;
}
string Name
{
get;
set;
}
System.Type ParameterType
{
get;
}
T DefaultValue
{
get;
}
}
The idea being that I want to be able to create a set of typed parameters that can be used to generate a dynamic user interface where the display element on the interface is based on the type of the Parameter. I'll probably put something into the constructor to ensure that it only accepts value types to keep things simple, but I want to use Generics so I can ensure that the value entered into the DefaultValue property is consistent with the type and not have to create a whole lot of subclasses.
My table is constructed like as follows:
Code:
CREATE TABLE [dbo].[Parameters] (
[Id] [int] IDENTITY (1, 1) NOT NULL ,
[Name] [varchar] (50) NOT NULL ,
[DefaultValue] [varchar] (100) NOT NULL ,
[Type] [tinyint] NOT NULL
)
I'm not really sure how this could be mapped (or even if it's possible) but I'm leaning toward the idea of a UserType to try to interpret the value in the Type column and handle returning the correct Generic type.
Can anyone give me a hint?
Cheers,
Symon.