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

查看:37
本文介绍了在 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天全站免登陆