开发者

Use a value object which contains generic ILists with a web service?

开发者 https://www.devze.com 2023-02-19 01:55 出处:网络
I have a value object which contains multiple generic lists: public IList<SomeClass> MyList 开发者_如何学JAVA{ get; set; }

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>

0

精彩评论

暂无评论...
验证码 换一张
取 消