Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need help on C# calculator program Pin
DaveyM698-Sep-08 9:33
professionalDaveyM698-Sep-08 9:33 
AnswerRe: Need help on C# calculator program Pin
Christian Graus8-Sep-08 11:18
protectorChristian Graus8-Sep-08 11:18 
JokePile on! Pin
carbon_golem8-Sep-08 15:59
carbon_golem8-Sep-08 15:59 
QuestionListView item highlighting Pin
Cyrilix8-Sep-08 7:41
Cyrilix8-Sep-08 7:41 
AnswerRe: ListView item highlighting Pin
Wendelius8-Sep-08 8:17
mentorWendelius8-Sep-08 8:17 
AnswerRe: ListView item highlighting Pin
Mycroft Holmes8-Sep-08 15:21
professionalMycroft Holmes8-Sep-08 15:21 
GeneralRe: ListView item highlighting Pin
Cyrilix8-Sep-08 19:21
Cyrilix8-Sep-08 19:21 
QuestionNeed help converting between similar types Pin
Erik Westermann8-Sep-08 7:28
professionalErik Westermann8-Sep-08 7:28 
I have two type of objects - Person and PersonEx.

The difference between Person and PersonEx is that PersonEx contains an array of strings, whereas Person does not.

Here's a sample:

class Person
{
   public string FirstName;
   public string LastName;
   public string City;
}

class Details
{
    public string attribute1;
    public string attribute2;
}

class PersonEx
{
   public string FirstName;
   public string LastName;
   public string City;
   public Details[] theDetails;
}

I need to convert from Person to PersonEx and from PersonEx to Person. I don't mind loosing the information in PersonEx.theDetails when converting to Person and leaving PersonEx.theDetails null when converting from a Person is ok.

So far, I have been writing helper methods that do a member-by-member copy of each field (InstanceOfPerson.FirstName = InstanceOfPersonEx.FirstName;). This is not ideal since there are a lot of fields.

I'd like to walk over each type in the source and copy the value to the target so I could write something like this... public TO_TYPE Convert< FROM_TYPE, TO_TYPE >(instanceOfFromType).

I looked into reflection, but that can be painful. I had a similar problem when converting between two types that are identical except that the type names are different - I solved that problem through serialization, but this problem is quite different.

One option is, I suppose, to continue to use serialization, and then 'fix' the resulting XML to more closely align with the type to which I am converting so that I end up with a working instance on deserialization.

The types I'm converting between don't change often - they just have a lot of fields and I am looking for a more reliable means of copying common information that is better and less error prone than member-by-member copying.

Any advice?

Erik Westermann - wWorkflow.net - BizTalk Consulting Services

SOA * ESB * BPI * SaaS ... forget the alphabet soup - get the main course with our consulting services!

wWorkflow.net or +1 416-809-1453



AnswerRe: Need help converting between similar types Pin
Wendelius8-Sep-08 7:39
mentorWendelius8-Sep-08 7:39 
GeneralRe: Need help converting between similar types Pin
Erik Westermann8-Sep-08 7:55
professionalErik Westermann8-Sep-08 7:55 
GeneralRe: Need help converting between similar types Pin
Wendelius8-Sep-08 8:03
mentorWendelius8-Sep-08 8:03 
AnswerRe: Need help converting between similar types [modified] Pin
Paw Jershauge8-Sep-08 8:35
Paw Jershauge8-Sep-08 8:35 
GeneralRe: Need help converting between similar types Pin
Pete O'Hanlon8-Sep-08 8:48
mvePete O'Hanlon8-Sep-08 8:48 
GeneralRe: Need help converting between similar types Pin
Paw Jershauge8-Sep-08 9:49
Paw Jershauge8-Sep-08 9:49 
GeneralRe: Need help converting between similar types Pin
Pete O'Hanlon8-Sep-08 9:51
mvePete O'Hanlon8-Sep-08 9:51 
GeneralRe: Need help converting between similar types Pin
Paw Jershauge8-Sep-08 9:53
Paw Jershauge8-Sep-08 9:53 
GeneralRe: Need help converting between similar types Pin
Pete O'Hanlon8-Sep-08 10:05
mvePete O'Hanlon8-Sep-08 10:05 
GeneralRe: Need help converting between similar types Pin
Erik Westermann9-Sep-08 8:05
professionalErik Westermann9-Sep-08 8:05 
AnswerRe: Need help converting between similar types Pin
carbon_golem8-Sep-08 15:36
carbon_golem8-Sep-08 15:36 
GeneralRe: Need help converting between similar types Pin
Erik Westermann9-Sep-08 8:12
professionalErik Westermann9-Sep-08 8:12 
QuestionSecure page with C#.NET Pin
mghiassi8-Sep-08 6:37
mghiassi8-Sep-08 6:37 
AnswerRe: Secure page with C#.NET Pin
Dave Sexton8-Sep-08 7:14
Dave Sexton8-Sep-08 7:14 
Question[Message Deleted] Pin
mghiassi8-Sep-08 6:32
mghiassi8-Sep-08 6:32 
AnswerRe: Secure page with C#.NET Pin
Anthony Mushrow8-Sep-08 6:43
professionalAnthony Mushrow8-Sep-08 6:43 
QuestionJavascript for checkboxes which are in repeater Pin
AtulRane8-Sep-08 5:30
AtulRane8-Sep-08 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.