Serialization of a custom collection



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 appreciate any help,

Leszek


.



Relevant Pages

  • Re: Accelerating rocket/light beam question
    ... There is a string connecting the two cars. ... Think, for a moment, about a system consisting of two rockets B and C ... F be the frame of your cars. ...
    (sci.physics.research)
  • Re: Serialization of a custom collection
    ... it seems I'll have to create a "wrapper" ... public class CarCollection: List ... public string Model; ... CarCollection cars = GetCars; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Serialization of a custom collection
    ... public class CarCollection: List ... public string Model; ... CarCollection cars = GetCars; ... How to properly enhance my custom collection? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.
    ... Those that say there isn't a problem, and that it is the programmer's fault perhaps have forgotten that seat belts were introduced into cars to protect people if an accident happens. ... And it is precisely because drivers do cause accidents, we have safer cars. ... And for those people that suggest that C does have a string type, I would suggest that it doesn't, compared with Pascal, PL/I, COBOL or even Assembler. ...
    (comp.lang.c)
  • Re: session variable issue?
    ... You are never assigning Sessionto anything. ... You are setting the string "cars" to 'Y', but since never assign the Session ...
    (microsoft.public.dotnet.framework.aspnet)