?
Solved

Use Reflection to determine if a property is System.Nullable<System.DateTime>

Posted on 2010-01-12
2
Medium Priority
?
485 Views
Last Modified: 2013-12-17
Hi,

I'm trying to use reflection to copy some Request.QueryString[] values into a Linq2SQL object. This I do by iterating through the properties of the Linq Object and then checking if there is a QueryString available for that property.

However, these properties have different kind of types and I need to convert the QueryString data to the appropriate type before I can store it in the properties of the Linq Object.

This seems to work well:
Type propertyType = propertyInfo.GetType();
if (propertyType == typeof(Int32))
{
 // do some intelligent stuff here
}

But the following one does not work if the column is marked as Nullable:

if (propertyType == typeof(System.Nullable<System.DateTime>))
{
 // do some intelligent stuff here
}

Any suggestions as to how to fix this?
Taco
0
Comment
Question by:tacojoosterkamp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 26295150
if(propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 26295227
even if u declare datetime as nullable either
Nullable<DateTime> val = DateTime.Now;
or
DateTime ? val = DateTime.Now;

and check its type u get "DateTime"
check this code snippet:

Nullable<DateTime> val = DateTime.Now;
            Type t = val.GetType();
            bool equal = (t == typeof(DateTime));

equal is always true...
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question