I have a value object which contains multiple generic lists:
public IList<SomeClass> MyList 开发者_如何学JAVA{ get; set; }
// ...
Now I cant serialize that to make it work with a web service. How could I do that?
Thanks :-)
If you can't change the existing object, then your main option is to use a DTO that looks similar to the existing object, but which has properties / behaviours that the serializer you are using (XmlSerializer for asmx, DataContractSerializer by default for svc) can handle. For example, it would have:
public List<SomeClass> MyList {get;set;}
or even:
public List<SomeClassDto> MyList {get;set;}
You might be able to map between these representations using AutoMapper, or do it by hand.
If you are using WCF, you might also be able to swap the serializer at runtime to support generic interface-based lists like IList<T>
精彩评论