c#中生成的代理类中的列表与数组

我有一个WCF服务,当我用svcutil生成客户端代理类时,它将我的列表属性更改为数组。 有没有一个选项可以确保我在不修改C#生成的类的情况下维护列表?

//The object in the service… [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://brax.com/data/Query")] public partial class PayloadType { private List personBasedQueryField; private List locationBasedQueryField; //Generated class... [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://brax.com/data/Query")] public partial class PayloadType { private PersonType[] personBasedQueryField; private LocationType[] locationBasedQueryField; 

是的,Visual Studio中的服务参考中有选项。 您可以选择将集合生成为List。

更新:如果您使用的是svcutil.exe ,则可以使用此选项:

 /collectionType: 

通过从Visual Studio中添加服务引用来创建客户端代理时,您可以稍后编辑该配置。 在该编辑对话框中,您可以指定是否要包含数组,列表,ObservableCollections(我认为还有更多选项)。

在此处输入图像描述

使用svcutil我不知道是否可以更改该选项。

右键单击ServiceReference,选择“配置服务引用”。 并将Collection类型更改为System.Collections.Generic.List。