C# 部分 class returns 空

C# partial class returns null

我正在尝试创建填充信息路径模板并将其上传到共享点。我一直在遵循这些说明 https://www.codeproject.com/Articles/33228/Programmatically-create-a-browser-enabled-InfoPath

这是我生成的代码示例

public 部分 class 我的字段:

...
public partial class myFields
{ 
    private General_Information general_InformationField;
    ...
    public General_Information General_Information
    {
        get
        {
            return this.general_InformationField;
        }
        set
        {
            this.general_InformationField = value;
        }
    }
    ...
}
...

public部分classGeneral_Information

public partial class General_Information
{

    private string wellField;
    ...

    public string Well
    {
        get
        {
            return this.wellField;
        }
        set
        {
            this.wellField = value;
        }
    }
    ...

指令填充数据如下:

myFields fields = new myFields();
fields.Name = "Joe";
fields.Surname = "Blogs";

当我尝试按照网站中的示例进行操作时:

myFields fields = new myFields();
fields.General_Information.Well = "name";

我收到一条错误消息 myFields.General_Information。**get** 返回 null。

执行此操作的正确方法是什么?

fields.General_Information.Well = "name"; 应该在下面。您忘记实例化 General_Information 类型,因此它为空。此外,不确定将它们设为 partial class 有什么必要。实际上不应该。

fields.General_Information gi = new General_Information();
gi.Well = "name";