How to inherit three data contract objects and create it in a single object?

Posted by Varaprasadm.84 under C# on 11/27/2012 | Points: 10 | Views : 992 | Status : [Member] | Replies : 3
I have a data contract class like this

[Serializable]
[DataContract]
public class Address:Email
{
[DataMember]
public long AddressId { get; set; }
}

another data contract class like

[Serializable]
[DataContract]
public class Email:someother class
{
[DataMember]
public long EmailId { get; set; }
}

another data contract class like

[Serializable]
[DataContract]
public class Phone
{
[DataMember]
public long PhoneId { get; set; }
}

Now i want to use the AddressId, EmailId, PhoneId in the same method.

I want to use all the three in a single instance.

for example:
Address obj=new Address();
obj.AddressId="1";

and now i want to get
obj.EmailId="3";
and
obj.PhoneId=4;

How it is possible??

Vara Prasad.M


Responses

Posted by: Saratvaddilli on: 11/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi Vara Prasad . M ,
just create an object on the class
public <return type> <method name>(Address objAddress , Email  objEmail ,Phone ,objPhone )

{
//your code here
}


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Varaprasadm.84, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Deepraj on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
I hope this will help you.

These are your classes

[Serializable]

[DataContract]
public class Address
{
[DataMember]
public long AddressId { get; set; }
}


[Serializable]
[DataContract]
public class Email
{
[DataMember]
public long EmailId { get; set; }
}


[Serializable]
[DataContract]
public class Phone
{
[DataMember]
public long PhoneId { get; set; }
}


Take another class,say WholeClass as follows define your properties again in it.

public class WholeClass

{


private long addId;
Address addObj = new Address();
public long addressId
{
get
{
return addObj.AddressId;
}
set
{
addObj.AddressId = addId;
}
}

private long emId;
Email emObj = new Email();
public long emailId
{

get
{
return emObj.EmailId;
}
set
{
emObj.EmailId = emId;
}
}

private long phId;
Phone phObj = new Phone();
public long addressId
{
get
{
return phObj.PhoneId;
}
set
{
phObj.PhoneId = phId;
}
}

}


So you can access the properties addressId,EmailId,PhoneId by accessing WholeClass's properties.

Thanks & Regards
DEEPRAJ

Varaprasadm.84, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varaprasadm.84 on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
I think creating an object again is not a good solution

Vara Prasad.M

Varaprasadm.84, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response