gpt4 book ai didi

c# - 如何使属性真正只读?

转载 作者:太空宇宙 更新时间:2023-11-03 17:36:43 25 4
gpt4 key购买 nike

取以下属性:

public string Foo
{
get;
private set;
}

使用反射,我仍然可以从所属类之外设置此属性的值。有没有办法防止这种情况?删除 set 访问器不是一个选项,因为它必须是 WCF 友好的。

最佳答案

乔恩·斯基特 says :

You can't (AFAIK) stop reflection being used in a situation where the caller has "full trust". If they're running with less than full trust then some things about reflection (if not all) are automatically disabled, I believe - however, if this is to stop other people from calling some code, you can't prevent them from running your code with full trust unless you're in control of their box in the first place.

关于c# - 如何使属性真正只读?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1703377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com