Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 108431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:54:38+00:00 2026-05-11T01:54:38+00:00

For some reason I need to cast/convert a DateTime into one of many custom

  • 0

For some reason I need to cast/convert a DateTime into one of many custom objects

This proves to be very difficult to do in a nice generic fashion.

I am thinking of implementing an extension method on object or perhaps extending DateTimeConverter.

But then what would be the generic way to handle this, I have an object and a destination type and at the moment I am using System.ConvertTo(..) but this is clearly limited because it only supports converting to .NET types and cant be extended.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:54:39+00:00Added an answer on May 11, 2026 at 1:54 am

    You could add a constructor for your TimeStamp that takes DateTime as a parameter.

    public class TimeStamp {    public TimeStamp(DateTime dateTime, ...)    {     // Your code here to convert from dateTime to TimeStamp    } } 

    Then later …

     DestType Convert<DestType>( Object linqResult )     {   DestType result;   if( linqResult is DateTime && DestType is TimeStamp )   {    DateTime dbTime = linqResult as DateTime;    result = new TimeStamp( dbTime );   }   ...   return result;  } 

    You could probably even extend this with all kinds of reflection and constructors etc. But if you want to base one object off of another (like a time stamp from a date time) a constructor seems natural.

    Hope this helps, TJB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes that, for one reason or another, cannot be or need
can someone please tell me why this isn't working? For some reason I need
So this validation thing I wrote works but for some reason I need to
For some reason I need to check in a couple of files in the
i have a large user Database (13k+), and for some reason i need to
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason I need to fetch emails from /var/mail/username file. It seems like
For some reason,I need to connect to a firewall(based on Linux) and add some
for some reason I need to query 'case-sensitive' in MySql + doctrine 2. Is
For some reason I need to use CentOS 4.8. I installed Java 1.6.26 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.