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

  • SEARCH
  • Home
  • 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 7608939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:02:52+00:00 2026-05-31T01:02:52+00:00

I have two instances in an application where I need to implement functionality to

  • 0

I have two instances in an application where I need to implement functionality to convert an object from one type to another. One to go from a domain object to another domain object, another to go from a domain object an XmlDocument.

The way I have initially set it up is to include a ToXml() and ToMyOtherDO() within DomainObject1 and DomainObject2 respectively.

The functionality in ToXml isn’t really specific to the implementation of DomainObject1 and could probably live anywhere. ToMyOtherDO() has functionality very specific to the type it lives in. Both perform type conversions but are quite different.

My question is, have I placed this functionality in the correct place? Would this functionality be better placed in a helper class? Or some place else – perhaps overriding the explicit casting operator?

  • 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. Editorial Team
    Editorial Team
    2026-05-31T01:02:54+00:00Added an answer on May 31, 2026 at 1:02 am

    I usually like to put this kind of functionality in extension methods.

    EDIT: Explanation
    I generally prefer to put this kind of functionality in extension methods because I don’t feel that the class that needs to be “converted” really needs to know how to do the conversion. This provides some decoupling. You can easily change the format of your XML without changing the object that you are converting to XML (especially useful when the object to be converted is in a seperate assembly).

    You will eventually run into a situation where you want to convert your domain object to something that it does not really need to know about. For example, maybe you want to convert your domain object to a Json.NET JObject. The assembly containing your domain object wouldn’t need a reference to the Json.NET library if you used extension methods to handle the conversion in a separate assembly.

    The extension methods are great especially when dealing with the Entity Framework. The code for the entity classes are auto-generated, so you can’t just add a ToXML() or ToJObject() to the class.

    These are just my preferences, and I don’t always use extension methods to handle this kind of functionality. It’s just another great tool to have in your arsenal, for solving these kinds of problems.

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

Sidebar

Related Questions

I have an application hosted on an Amazon server with two instances, one for
Is it possible for two instances of Object to have the same hashCode() ?
I have an odd need to open two separate instances of excel and having
I have the need for an object to object mapper in my application. I've
I have two SQL 2005 instances that reside on different networks. I need to
i need to implement this scenario Brief about that is have two java based
I have two web applications running in the same Tomcat Instance. In one of
I have two instances running of same Windows Service. They check the health of
I have two instances of an Address.ascx control in an ASP.NET MVC page. <h1>Shipping
I have two named instances of SQL Server 2008 and am trying to set

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.