How to implement interface properties NOT in alphabetical order

喜你入骨 提交于 2019-12-01 14:04:22

问题


I use VS 2015.
When I create a new class and try to implement an interface with the shortcut Ctrl + . -- For example, class StarShip : IStarShip and then I use Ctrl + . and select implement interface -- It implements the properties and methods but in an alphabetical order! Is there an easy way to make it implement them in the order in which they are in the interface, or must I do it manually?

I don't have Resharper, so that's not an option.


回答1:


The VS 'implement interface' functionality obviously uses reflection to generate the code, and there is nothing in the reflection APIs that guarantees the order of members returned by the various calls. We do not have control over either the reflection order or the VS code generator used to implement interfaces, so we can't change the way it works.

Basically the only option is to use a VS extension like resharper that replaces the implement interface functionality.




回答2:


In VS2019 you can change this in the options.

Tools -> Options -> C# -> Advanced -> Implement interface or Abstract class -> Set to "at the end".

This seems to add the functions in the same order as in the interface.



来源:https://stackoverflow.com/questions/34103956/how-to-implement-interface-properties-not-in-alphabetical-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!