为了账号安全,请及时绑定邮箱和手机立即绑定

如何在同一方法中访问调用其类的方法的对象?

如何在同一方法中访问调用其类的方法的对象?

C#
守着星空守着你 2021-05-15 13:28:24
    public class Container : XmlElementGenerator{    public string projectcode { get; set; }    public string projectname { get; set; }    public string projectleader { get; set; }    public string barcode { get; set; }    public string sampleartid { get; set; }    public string sampledescription { get; set; }    public string remark { get; set; }    public DateTime samplingdate { get; set; }    public int samplenumber { get; set; }    public XmlElement GenerateXMLElement(XmlDocument xmlDocument)    {        Type containerGenerator = typeof(Container);        XmlElement container = ElementChildrenGenerator(xmlDocument, "container");        foreach (PropertyInfo prop in containerGenerator.GetProperties())        {            container.AppendChild(ElementChildrenGenerator(xmlDocument, prop.Name, prop.GetValue(this).ToString()));        }        return container;    }}此处出现错误prop.GetValue(this)-“ System.NullReferenceException:对象引用未设置为对象的实例”。为什么我不能使用“ this”来访问对象?我不想再添加一个参数。请帮助
查看完整描述

2 回答

?
波斯汪

TA贡献1811条经验 获得超4个赞

找到了解决方案-我只是没有检查输入到属性的空值。做了检查,它起作用了。


查看完整回答
反对 回复 2021-05-21
  • 2 回答
  • 0 关注
  • 112 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信