小编fwe*_*aks的帖子

有没有办法将函数标记为只能从静态构造函数调用/可调用?

我的一个类有一个相当大的静态构造函数,并且想要重构它以将初始化的各个部分封装在静态函数中。

One of the things this static constructor does a lot of is initialize the values of static readonly fields. However, when I try to move these parts into functions, obviously the compiler wont let me as these can only be set in the static constructor. This makes sense as it doesn't know that I only intend to call these functions from my static constructor.

Is there any way around this? e.g. is there some sort of attribute I can …

c# static-methods static-constructor readonly-variable

0
推荐指数
1
解决办法
441
查看次数