使用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>
参考链接