c# - C# 问题实例化作为隐含数组的类
问题描述
我希望你能帮忙。我正在与英国的 Land Registry Business Gateway 合作。我有一个来自他们的 reference.cs 文件,其中包含从 Web 服务参考中添加的代码。我设法引用了模块的所有部分,除了一个。我在实例化对象时遇到问题,因为它是一个隐含的数组,并且在调用结束时不会采用 () 但需要 [2] (其中 2 是数组中的元素数。模块中的代码在这里:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/eReg-Final/2011/RequestTitleKnownOfficialCopyV2_1")]
public partial class Q1ContactType : object, System.ComponentModel.INotifyPropertyChanged {
private Q3TextType nameField;
private Q1CommunicationType communicationField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public Q3TextType Name {
get {
return this.nameField;
}
set {
this.nameField = value;
this.RaisePropertyChanged("Name");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public Q1CommunicationType Communication {
get {
return this.communicationField;
}
set {
this.communicationField = value;
this.RaisePropertyChanged("Communication");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
我的代码在这里:
request.Product.Contact = new Q1ContactType[2];
request.Product.Contact[0].Name = new LROfficialCopyTitleKnownV2_1.Q3TextType();
request.Product.Contact[0].Name.Value = "Allen Jones";
如果我在 Q1ContactType 之后使用 (),它会抛出一个错误,说它需要 []。如果我把 [] 没有数字,它会抛出一个错误,说必须初始化数组。如果我按照上面显示的方式运行它,我会收到错误 Object reference not set to an instance of an object 因为该对象尚未实例化。request.Product 指的是 xml 文档的第一部分。
解决方案
推荐阅读
- html - 如何将任何宽高比的图像放入全屏弹出 div 中?
- regex - Apache 用查询重写规则
- c++ - 是否可以在内存中获取内存地址?
- mulesoft - 如何为使用通用 HTTP 请求连接器调用系统层的 5 个不同资源的集成编写 Munit 测试用例?
- git - 如何使用 Jenkins 管道将文件从 Github 克隆到 VM?
- ios - 设置标签换行模式、文本对齐和文本颜色时 iOS 14 崩溃
- visual-studio - Visual Studio:在即时窗口中抑制输出
- c# - 对 API 控制器的 HttpDelete 调用返回状态代码 200 但未删除任何内容
- jmeter - JMeter - 在 bin 目录中找不到根证书
- jira - 从 Jira 更新谷歌聊天中的消息