-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: UserType to return generic instance?
PostPosted: Mon Jan 15, 2007 7:55 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.