Thanks, I see we were inspired by the same soure :)
Thanks a lot!
On Fri, Nov 21, 2008 at 8:57 AM, Germán Schuager <[EMAIL PROTECTED]> wrote:
> Hi Jan,
>
> I have something like this working:
>
> public class CreditCardCompanyUserType : CreditCardCompany, IUserType
> {
> public bool Equals(object x, object y)
> {
> if (ReferenceEquals(x, y)) return true;
> if (x == null || y == null) return false;
> return x.Equals(y);
> }
>
> public int GetHashCode(object x)
> {
> return x == null ? typeof(bool).GetHashCode() + 473 :
> x.GetHashCode();
> }
>
> public object NullSafeGet(IDataReader rs, string[] names, object
> owner)
> {
> var obj = NHibernateUtil.String.NullSafeGet(rs, names[0]);
> if (obj == null) return null;
> var name = (string)obj;
> return
> CreditCardCompanyRepository.GetCreditCardCompanyByName(name); ;
> }
>
> public void NullSafeSet(IDbCommand cmd, object value, int index)
> {
> if (value == null)
> {
> ((IDataParameter)cmd.Parameters[index]).Value =
> DBNull.Value;
> }
> else
> {
> var c = (CreditCardCompany)value;
> ((IDataParameter) cmd.Parameters[index]).Value = c.Name;
> }
> }
>
> public object DeepCopy(object value)
> {
> return value;
> }
>
> public object Replace(object original, object target, object owner)
> {
> return original;
> }
>
> public object Assemble(object cached, object owner)
> {
> return cached;
> }
>
> public object Disassemble(object value)
> {
> return value;
> }
>
> public SqlType[] SqlTypes
> {
> get { return new[] {NHibernateUtil.String.SqlType}; }
> }
>
> public Type ReturnedType
> {
> get { return typeof(CreditCardCompany); }
> }
>
> public bool IsMutable
> {
> get { return false; }
> }
> }
>
>
> With this approach, besides the IUserType you will need a static
> CreditCardCompanyRepository that aggregates all the credit card companies
> available... something like this:
>
> public class CreditCardCompanyRepository
> {
> private static readonly Dictionary<string, CreditCardCompany>
> allCreditCardCompanies = new Dictionary<string, CreditCardCompany>();
>
> static CreditCardCompanyRepository ()
> {
> // use reflection to initialize allCreditCardCompanies
> }
>
> ....
>
> public static ClaseComprobante GetCreditCardCompanyByName(string
> name)
> {
> return allClases[name];
> }
> }
>
> (Some of my requirements justify this static repository, but you should be
> fine if you decide not to use it)
>
> Regards,
>
> Germán.
>
>
>
> On Thu, Nov 20, 2008 at 8:21 PM, Jan Limpens <[EMAIL PROTECTED]> wrote:
>>
>> Unable to cast object of type 'System.Runtime.Remoting.ObjectHandle'
>> to type 'xxx.CreditCardCompany'.
>>
>> seems I've got more work ahead :)
>>
>>
>> On Thu, Nov 20, 2008 at 8:43 PM, Tuna Toksöz <[EMAIL PROTECTED]> wrote:
>> >
>> > public Type ReturnedType
>> > {
>> > get { return typeof(object); }
>> > }
>> >
>> > this may be a problem, don't know. go ahead and try. This is not
>> > something i
>> > like but would work.
>> >
>> > On Fri, Nov 21, 2008 at 12:39 AM, Jan Limpens <[EMAIL PROTECTED]>
>> > wrote:
>> >>
>> >> public Type ReturnedType
>> >> {
>> >> get { return typeof(object); }
>> >> }
>> >
>> >
>> > --
>> > Tuna Toksöz
>> > http://www.tunatoksoz.com
>> >
>> > Typos included to enhance the readers attention!
>> >
>> >
>> > >
>> >
>>
>>
>>
>> --
>> Jan
>> ___________________
>> [EMAIL PROTECTED]
>> www.limpens.com
>> +55 (11) 3082-1087
>> +55 (11) 3097-8339
>>
>>
>
>
> >
>
--
Jan
___________________
[EMAIL PROTECTED]
www.limpens.com
+55 (11) 3082-1087
+55 (11) 3097-8339
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---