Today, I want to write a class that supports serialization. Therefore, I need to manually write many attributes and fields, instead of using the automatic attributes after C #3.0. Therefore, Visual Studio's propfull code snippets is used, but this code snippets is inconvenient, as shown below:
There are two disadvantages:
- The attribute name and field name must be defined twice. I think the field name can be directly added with a "_" before the attribute name.
- Set does not support modifier addition.
So I defined another code snippet: propfull2
Overcome these shortcomings. The property type is the same as that of propfull. Then, you only need to specify a name. The field name will be automatically prefixed with "_", and then you can specify the access modifier for set (private by default ).
File Download
Note: This is an archive of Microsoft SkyDrive. Please download it directly in your browser. Some download tools may not be available for download.
File Type:. snippet
Or browse the source file:
<? XML version = "1.0" encoding = "UTF-8"?>
<Codesnippets xmlns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Codesnippet format = "1.0.0">
<Header>
<Title> propfull2 </title>
<Shortcut> propfull2 </shortcut>
<Description> more advanced propfull codesnippet </description>
<Author> mgen </author>
<Snippettypes>
<Snippettype> expansion </snippettype>
</Snippettypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID> type </ID>
<Tooltip> attribute type </tooltip>
<Default> int </default>
</Literal>
<Literal>
<ID> property </ID>
<Tooltip> attribute name </tooltip>
<Default> myproperty </default>
</Literal>
<Literal>
<ID> access </ID>
<Tooltip> set's reverse question modifier </tooltip>
<Default> private </default>
</Literal>
</Declarations>
<Code language = "CSHARP">
<! [CDATA [private $ type $ _ $ property $;
Public $ type $ property $
{
Get {return _ $ property $ ;}
$ Access $ set {_$ property $ = value ;}
}
$ End $]>
</Code>
</Snippet>
</Codesnippet>
</Codesnippets>