Re: Determing if a Type is a specific Generic



Cheers, will try that tonight, I suspect my main issue when trying to
determine a decent method was not knowing that typeof(Nullable) and
typeof(Nullable<>) where two different types.

"Joanna Carter [TeamB]" wrote:

"Nigel Sampson" <Nigel Sampson@xxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le
message de news: B86D6AAC-8611-4C32-870E-C2954BC76995@xxxxxxxxxxxxxxxx

| I'm in the process of upgrading an Object-Relational mapping library to
..NET
| 2.0 and am wanting to implement support for Nullable typess.
|
| I'm using Reflection to analyise the object that is being mapped and
| building up a schema for the mapping.
|
| This means I need a way to determine if the PropertyInfo.Property Type is
an
| implementation of System.Nullable<>. I've been batting my head against
this
| for a while and only come up with one solution.
|
| private static bool IsNullable(Type type)
| {
| if(!type.IsGenericType)
| return false;
|
| Type[] parameters = new Type[] { type.GetGenericArguments()[0] };
|
| Type constructedType = typeof(Nullable<>).MakeGenericType(parameters);
|
| return type == constructedType;
| }

Try this :

return type.IsGenericType && type.GetGenericTypeDefinition() ==
typeof(Nullable<>);

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer



.



Relevant Pages

  • Re: A Tosca tale
    ... "Sergio da Silva wrote: ... Even if this is true - and I suspect it is, knowing well at least one other ... diva for whom it was an absolute necessity - is it reasonable behaviour ...
    (rec.music.opera)
  • Re: BELI & ANNE PEDIGREE
    ... responses but, knowing that group, I'd suspect they would be negative in ... the extreme and not too polite. ...
    (soc.genealogy.britain)
  • Re: Frequency multiplication required
    ... Stan Pawlukiewicz wrote: ... "I need to multiply a low frequency of aprox one hertz by say 200, so that it would be audible. ... It isn't just not knowing how to do it, it's not knowing what "it" is. ... There's no gain from discussing how to accomplish what we suspect he might want. ...
    (comp.dsp)
  • Re: Ive got a month and a half to burn some fat
    ... Suspect? ... Your job is safe. ... You can't make that judgment without knowing what his job is, ...
    (misc.fitness.weights)
  • Re: canon digital rebel xt vs nikon D40. which is better for first time DSLR buyer? TIA
    ... Without knowing more about what you want to do with ... Frankly I suspect you don't really ... Joseph Meehan ... Dia 's Muire duit ...
    (rec.photo.digital.slr-systems)