如何不按字母顺序实现接口属性 [英] How to implement interface properties NOT in alphabetical order
问题描述
我使用VS2015.
当我创建一个新类并尝试使用快捷键 Ctrl + 来实现接口时.-例如,class StarShip : IStarShip
然后使用 Ctrl + .并选择implement interface
-它按字母顺序实现属性和方法!
是否有一种简单的方法可以使它按照它们在界面中的顺序实现它们,还是必须手动执行?
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?
我没有Resharper,所以这不是一个选择.
I don't have Resharper, so that's not an option.
推荐答案
VS的实现接口"功能显然使用反射来生成代码,并且反射API中没有任何东西可以保证各种返回的成员的顺序.电话.我们无法控制用于实现接口的反射顺序或VS代码生成器,因此我们无法更改其工作方式.
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.
基本上,唯一的选择是使用VS扩展程序(如resharper)来代替机具接口功能.
Basically the only option is to use a VS extension like resharper that replaces the implement interface functionality.
这篇关于如何不按字母顺序实现接口属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!