在Visual Studio中实例化对象的快捷方式 [英] Shortcut to instantiate an object in Visual Studio

查看:391
本文介绍了在Visual Studio中实例化对象的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有8个以上属性的类,我经常想用某种方法实例化它,但是必须逐个编写属性以为其分配值是很麻烦的。



有什么方法可以使用键盘快捷键插入某种代码片段,它允许我插入类的实例,而我只是修改值要添加?



我不想使用构造函数,因为我希望实例对于我的代码读取者而言是可读的,并且因为构造函数在LinQ to SQL中不起作用。



我使用Visual Studio 2015,C#,Resharper。



非常感谢。

解决方案

我创建了


I have a class with more than 8 properties, and I often want to instantiate it in some method, but it is super tedious to have to write the properties one by one to assign them the value.

Is there any way to insert a kind of "code fragment" with a keyboard shortcut, which allows me to insert the instance of the class, and I just modify the values ​​to add?.

I do not want to use constructors because I want the instance to be readable for the reader of my code and because the constructors do not work in LinQ to SQL.

I Use Visual Studio 2015, C#, Resharper.

Thank you very much.

解决方案

I've created the Generate an initializer for a new object with names of public properties and fields command for the Visual Commander extension. Call it after entering the class name and it will generate an initializer:

这篇关于在Visual Studio中实例化对象的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆