Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cast between different classes 1

Status
Not open for further replies.

serializer

Programmer
May 15, 2006
143
0
0
SE
I have an old object structure I would like to convert between two objects as much as possible. I know I can serialize down and up but I rather use other way if possible. Here are the two objects:

Class 1

using System;
using System.Collections.Generic;
using System.Text;

namespace ConvertObjectTest.VisualCron2
{
public class VisualCron : ICloneable
{
private string strName;

public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}

private int intOldAge;

public int OldAge
{
get
{
return intOldAge;
}

set
{
intOldAge = value;
}
}
}
}

Class 2

using System;
using System.Collections.Generic;
using System.Text;

namespace ConvertObjectTest.VisualCron4
{
public class VisualCron
{
private string strName;

public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}

private int intNewAge;

public int NewAge
{
get
{
return intNewAge;
}

set
{
intNewAge = value;
}
}
}
}

Now, I can afford to lose "OldObject" property and fix that manually to "NewObject" but I want the similar property "Name" to be copied to the object 2.

How can I cast this to make it happen?
 
Thanks. Is there a way to create an interface from existing class - any tool?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top