Subject: How to use my own type in a stanza ?
Hi Alex,
I try to use my own type 'PersonAddress' in a stanza. My Problem is this part of code (you can find it at the end of my listing below):
// !!! Problem: Error "Cannot implicitly convert type 'string' to 'XMPPWebService.Contracts.Elements.PersonPersonAddress"
public PersonAddress Address
{
get { return GetTag<PersonAddress>(); }
set { SetTag("Adresse"); }
}
How should the code look like ?
What I have to to to use my own type ?
Here is my used contract:
namespace XMPPWebService.Contracts.Elements
{
public class Person : XmppXElement
{
public class PersonAddress : XmppXElement
{
public PersonAddress()
: base("Address")
{
this.SetTag("Address");
}
public string Street
{
get { return GetTag("Street"); }
set { SetTag("Street", value); }
}
public int No
{
get { return GetTagInt("No"); }
set { SetTag("No", value); }
}
public PersonAddress(string Street, int No)
: base("Address")
{
this.Street = Street;
this.No = No;
}
}
public Person()
: base("Person")
{
this.SetTag("Person");
}
public string Lastname
{
get { return GetTag("Lastname"); }
set { SetTag("Lastname", value); }
}
public int Age
{
get { return GetTagInt("Age"); }
set { SetTag("Age", value); }
}
// !!! Problem !!!:
// Error "Cannot implicitly convert type 'string' to 'XMPPWebService.Contracts.Elements.PersonPersonAddress"
public PersonAddress Address
{
get { return GetTag<PersonAddress>(); }
set { SetTag("Adresse"); }
}
public Person(string Name, int Age)
: base("Person")
{
this.Name = Name;
this.Age = Age;
}
}
}
I try to use my own type 'PersonAddress' in a stanza. My Problem is this part of code (you can find it at the end of my listing below):
// !!! Problem: Error "Cannot implicitly convert type 'string' to 'XMPPWebService.Contracts.Elements.PersonPersonAddress"
public PersonAddress Address
{
get { return GetTag<PersonAddress>(); }
set { SetTag("Adresse"); }
}
How should the code look like ?
What I have to to to use my own type ?
Here is my used contract:
namespace XMPPWebService.Contracts.Elements
{
public class Person : XmppXElement
{
public class PersonAddress : XmppXElement
{
public PersonAddress()
: base("Address")
{
this.SetTag("Address");
}
public string Street
{
get { return GetTag("Street"); }
set { SetTag("Street", value); }
}
public int No
{
get { return GetTagInt("No"); }
set { SetTag("No", value); }
}
public PersonAddress(string Street, int No)
: base("Address")
{
this.Street = Street;
this.No = No;
}
}
public Person()
: base("Person")
{
this.SetTag("Person");
}
public string Lastname
{
get { return GetTag("Lastname"); }
set { SetTag("Lastname", value); }
}
public int Age
{
get { return GetTagInt("Age"); }
set { SetTag("Age", value); }
}
// !!! Problem !!!:
// Error "Cannot implicitly convert type 'string' to 'XMPPWebService.Contracts.Elements.PersonPersonAddress"
public PersonAddress Address
{
get { return GetTag<PersonAddress>(); }
set { SetTag("Adresse"); }
}
public Person(string Name, int Age)
: base("Person")
{
this.Name = Name;
this.Age = Age;
}
}
}