Re: Serialization of a custom collection
- From: "Leszek" <spam.spam@xxxxxxxxxxx>
- Date: Thu, 29 Jan 2009 15:27:32 -0500
Thanks for your help Pavel. Yeah, it seems I'll have to create a "wrapper"
around my collection. This way I'll be able to provide my additional info
within the wrapper.
Leszek
"Pavel Minaev" <int19h@xxxxxxxxx> wrote in message
news:79038a0a-5cbb-44f2-b6b9-dea88e0c5046@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jan 29, 8:47 am, "TarTar" <spam.s...@xxxxxxxxxxx> wrote:
Hello,
I've created a custom collection:
[XmlRoot("Cars")]
public class CarCollection : List<Car>
{
private string errMsg;
[XmlElement("ErrorMessage")]
public string ErrorMessage { get { return errMsg; } set { errMsg =
value; } }
// some CarCollection-specific methods
// ...
}
[Serializable]
public struct Car
{
public string Model;
public string Make;
public Car(string model, string make)
{
this.Model = model;
this.Make = make;
}
}
... and a Web Service method:
[WebMethod]
public CarCollection SearchCars()
{
CarCollection cars = GetCars();
cars.ErrorMessage = "Testing, testing...";
return cars;
}
When I call the web method it returns a collection of cars, but the
ErrorMessage element is missing.
How to properly enhance my custom collection? I'd like to serialize some
additional information such as ErrorMessage besides the collection itself.
I do not think it is possible to serialize additional info from the
collection object itself, but it is possible to insert an intermediate
object into the chain that would contain the collection itself
(expanded inline), and any additional info. Something like this:
[XmlRoot("Cars")]
public class Cars
{
[XmlElement] // this will expand the collection elements inline
within <Cars> as individual <Car> elements, without any additional
wrapping element such as <CarCollection>
public List<Car> CarCollection;
[XmlElement]
public string ErrorMessage;
...
}
.
- Follow-Ups:
- Re: Serialization of a custom collection
- From: sloan
- Re: Serialization of a custom collection
- References:
- Serialization of a custom collection
- From: TarTar
- Re: Serialization of a custom collection
- From: Pavel Minaev
- Serialization of a custom collection
- Prev by Date: Re: Can't resist... [OT]
- Next by Date: Re: IIS required?
- Previous by thread: Re: Serialization of a custom collection
- Next by thread: Re: Serialization of a custom collection
- Index(es):
Relevant Pages
|
Loading