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 1013681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:08:28+00:00 2026-05-16T10:08:28+00:00

I want to convert from public class Party { public string Type { get;

  • 0

I want to convert from

 public class Party
 {
        public string Type { get; set; }
        public string Name { get; set; }
        public string Status { get; set;}
 }

and convert to

 public class Contact
 {
        public string Type { get; set; }
        public string Name { get; set; }
        public string Status { get; set;}
        public string Company {get;set;}
        public string Source {get;set;}    
 }

I tried using this extension method

   public static class EnumerableExtensions
    {
        public static IEnumerable<TTo> ConvertTo<TTo, TFrom>(this IEnumerable<TFrom> fromList)
        {
            return ConvertTo<TTo, TFrom>(fromList, TypeDescriptor.GetConverter(typeof(TFrom)));
        }

        public static IEnumerable<TTo> ConvertTo<TTo, TFrom>(this IEnumerable<TFrom> fromList, TypeConverter converter)
        {
            return fromList.Select(t => (TTo)converter.ConvertTo(t, typeof(TTo)));
        }
}

I get this error TypeConverter is unable to convert ‘Party’ to ‘Contact’

    var parties = new List<Party>();
        parties.Add(new Party { Name = "name 1", Status = "status 1" });
        parties.Add(new Party { Name = "name 2", Status = "status 2" });

        var results = parties.ConvertTo<Contact, Party>().ToList();

What am I missing here?

  • 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-16T10:08:29+00:00Added an answer on May 16, 2026 at 10:08 am

    There is no direct conversion between the type Party and the Type contact (polymorphic or inheritance based).

    You need to implement a TypeConverter for your types so that .NET knows how to convert between those two types:

    MSDN – TypeConverter Class

    MSDN – How to Implement a TypeConverter

    Once you create your TypeConverters, you have to decorate your two classes with the TypeConverterAttribute so that the Framework can get an instance of your TypeConverter at Runtime:

    public class PartyTypeConverter : TypeConverter
    {
        // Implementation
    }
    
    [TypeConverter(typeof(PartyTypeConverter)]
    public class Party
    {
        public string Type { get; set; }
        public string Name { get; set; }
        public string Status { get; set; }
    }
    

    You could also attempt to mimic the (what I’m guessing) is the desired behavior using LINQ (even though you’ll lose the generic abilities):

    var contacts = parties.Select(p => new Contact {
        Type = p.Type,
        Name = p.Name,
        Status = p.Status
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TabItem class: public class TabItem { public string Header { get; set;
We at the company want to convert all the sites we are hosting from
I received DateTime String from Fedex in following format 2012-06-22T21:39:48-05:00 I want to convert
consider the following class and struct public class Entity { public IdType Id {get;set;}
I have the following class public class Account { IEnumerable<AccountData> Data { get; set;
Can I convert Class into Dictionary<string, string>? In Dictionary I want my class properties
I want to convert a code from perl to c++, and my problem is
i want to convert flv video(downloaded from you tube) to any other format, i
I want to convert sqlite query to Ormlite query. SELECT * FROM Test where
I'm reading from a binary file and want to convert the bytes to US

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.