System.Runtime.Serialization.InvalidDataContractException:没有设置属性的方法 [英] System.Runtime.Serialization.InvalidDataContractException: No set method for property

查看:96
本文介绍了System.Runtime.Serialization.InvalidDataContractException:没有设置属性的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如错误所示,我没有财产的二传手,但我不希望二传手只是一个只读的..任何想法?

会很感激的

谢谢

Hi,

As the error shows I don''t have setter for my property, but I don''t want setter its just a readonly..any Ideas??

Will really appreciate it

Thanks

推荐答案

对设置器进行保护(IIRC私有将不起作用,因为序列化不会调用私有设置器...这是我们如何使它起作用. .;)
Make the setter protected (IIRC private won''t work because the serialization will not call private setters...This how we can make it work... ;)


添加不执行任何操作的私有或受保护的setter.也可能是内部的.

add a private or protected setter that does nothing. also it could be internal as well.

public int SomeProp
{
  get { return 0; }
  private set { ; }
}




or

public int SomeProp
{
  get { return 0; }
  protected set { ; }
}




or

public int SomeProp
{
  get { return 0; }
  internal set { ; }
}


这篇关于System.Runtime.Serialization.InvalidDataContractException:没有设置属性的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆