使用Code Snippet简化编码

使用NewtonSoft.Json写实体类时大量格式一致的代码出现 ,这时可以使用Code snippet来加快编码速度

[JsonProperty(PropertyName = "message"]

public string Message { get; set;}

我把这个代码片段叫做jsonp , 要输入这两行代码时输入 jsonp 然后按 Tab就搞定了,还可以继续按Tab修改属性的名字

Snippet文件如下

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>jsonp</Title>
<Shortcut>jsonp</Shortcut>
<Description>Code snippet for JsonProperty</Description>
<Author>x wang</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>type</ID>
<Default>string</Default>
<Function/>
</Literal>
<Literal Editable="true">
<ID>field</ID>
<Default>fieldname</Default>
<Function/>
</Literal>
<Literal Editable="true">
<ID>Property</ID>
<Default>PropertyName</Default>
<Function/>
<Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
[JsonProperty(PropertyName = "$field$")]
public $type$ $Property$ { get; set;}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

参考链接

Visual Studio 的代码片段(Code Snippet)功能

时间: 2024-08-10 02:02:18

使用Code Snippet简化编码的相关文章

C# 使用 Code Snippet 简化 Coding

在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提供的Code Snippet 工具自动帮你生成呢? 神奇之处 你只需要在代码编辑器中输入for,就会看到 Visual Studio 的自动提示框中出现了如下红框框起来的部分,这个时候只需要连按两下 tab 键,便会自动补全 for 循环语句(如图2所示),并且默认选中索引,以便你进行修改. 图 1

使用 Code Snippet 简化 Coding

在开发的项目的时候,你是否经常遇到需要重复编写一些类似的代码,比如是否经常会使用 for.foreach ? 在编写这两个循环语句的时候,你是一个字符一个字符敲还是使用 Visual Studio 提供的Code Snippet 工具自动帮你生成呢? 神奇之处 你只需要在代码编辑器中输入for,就会看到 Visual Studio 的自动提示框中出现了如下红框框起来的部分,这个时候只需要连按两下 tab 键,便会自动补全 for 循环语句(如图2所示),并且默认选中索引,以便你进行修改. 图 1

善用VS中的Code Snippet来提高开发效率

http://www.cnblogs.com/anderslly/archive/2009/02/16/vs2008-code-snippets.html http://www.cnblogs.com/jaic-xiao/archive/2008/10/14/Jie_Shao_Net_Gong_Ju_Code_Snippet_Yu_Sql_Server_2008_Gong_Ju_SSMS_Tools_Pack.html 前言 在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建

Xamarin.Forms XAML的辅助功能Code Snippet

Xamarin.Forms XAML的辅助功能Code Snippet 在Visual Studio中,使用Code Snippet(代码片段)功能可以减少基础代码的编写量,如常见的标签.循环语句等.Xamarin.Forms中使用的XAML语言的标签往往都比较长,可以重复利用Code Snippet功能进行简化.用户可以使用第三方插件Snppetica实现该功能.该插件为C#.VB.C++.XML.XAML.HTML提供了代码片段功能.其中,它为XAML提供了89个代码片段.安装该插件后,用户

介绍 .Net工具Code Snippet 与 Sql Server2008工具SSMS Tools Pack

不久前,某某在微软写了一个很酷的工具:Visual Stuido2008可视化代码片断工具,这个工具可以在http://www.codeplex.com/SnippetDesigner上免费下载,用它可以方便地定制一批代码片段. 如何使用   1.如果要添加一个新文件,“文件”---“新建文件”---“Code Snippet File”   2.如果想要直接导入现有的代码,只需右键点击所选代码,按下“Export as Snippet”    3.编辑Snippet(可以使用$$符号表明占位符

/*程序员面试宝典*/Which of the following statements describe the results of executing the code snippet below in C++?

Which of the following statements describe the results of executing the code snippet below in C++? 1 int i; 2 3 void main() 4 5 { 6 7 int i = i; 8 9 } A. The i within main will have an undefined value. B. The compiler will allow this statement, but t

Code Snippet 插件 使用

使用Code Snippet 插件后可以进行代码高亮,如图: 代码效果: @Controllerpublic class HelloWorld { @RequestMapping("/HelloWorld") public String hello() { System.out.println("Hello World"); return "success"; }} 注意: Code Snippet有一个 silent 功能,点run silen

iOS programming Code Snippet Library

iOS programming? Code Snippet Library? The freebie code comes from the code snippet library. 代码来自code snippet library. Notice that there are a number of code snippets available 有许多code snippets available . Click the Edit button on the code snippet de

使用Code Snippet在Xcode中添加代码段

自定义的code snippet配置文件默认放在~/Library/Developer/Xcode/UserData/CodeSnippets/ 1.打开Code Snippet 2.将写好的代码直接拖入Code Snippet,注意红框内淡淡的字样 3.随即会自动弹出提示框,可以更改对应内容,以便使用 使用Code Snippet在Xcode中添加代码段