Re: Determing if a Type is a specific Generic
- From: Nigel Sampson <NigelSampson@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 26 Mar 2006 15:15:07 -0800
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
- References:
- Re: Determing if a Type is a specific Generic
- From: Joanna Carter [TeamB]
- Re: Determing if a Type is a specific Generic
- Prev by Date: Re: instance control
- Next by Date: Development Cost Comparisons
- Previous by thread: Re: Determing if a Type is a specific Generic
- Next by thread: Filtered view on second DataGridView
- Index(es):
Relevant Pages
|