Can design by contract allow me to enforce private

2019-09-17 07:25发布

I can't do this with language How to enforce private method since interface methods are only public?

so can I use design by contract instead ?

1条回答
倾城 Initia
2楼-- · 2019-09-17 07:45

If you are interested in enforcing a particular coding style, naming conventions, or things like that you are better off implementing custom rules for tools like FxCop or StyleCop. There really aren't any features in either the C# language or the .NET environment to help you enforce such things.

However, before you go to such lengths, you should really ask yourself whether the automated enforcement of such standards are sufficiently valuable to warrant the expense and difficulty of a solution. Are you dealing with a large team (dozens of developers) or a small one? Could simpler alternatives like code reviews be a sufficient means to enforce this? How will this kind of enforcement affect the over quality of the code vs. productivity/happiness of your team? What are the consequences of these standards aren't enforced?

These are important questions to consider before implementing such enforcement.

查看更多
登录 后发表回答