I can quite understand the intitial reaction to this: why in the hell do you want to do that..
Its tempting for me to say "trust me" but for anyone with 2 minutes of patience let me explain, maybe I have this back to front:
I have a db and a LINQ to SQL DataContext
My datacontext objects supply a more complex object model.
LINQ to SQL only supports mapping to certain types and does not support Many to many relationships and leaves me having to hard code the mapping.
I use reflection to populate "real world" object Properties from DataContext objects.
The real world object has more complex types such a TimeStamp (DateTime with extended functionality). So during this stage I have to convert a L2SQL generated System.DateTime object to my TimeStamp object.
Still following??
Ok so the problem is in 95% of cases the method correctly converts L2SQL types to the correct destination type e.g numeric(3,0) => (LINQ) System.Decimal => Int (real world object).
But I have properties that are wrappers for DateTime with extra functionality, clearly the raw value is a DateTime so when I save to the database a DateTime is sufficient. But when it comes back from the database I cannot get that sql datetime into my TimeStamp object...
I am now resigned to writing code along the lines you suggested:
if LINQ type == DateTime and destination == TimeStamp then .....
but I thought there must be a nice way to convert DateTime to some other type..
Maybe not.