A more user-friendly Visual Studio propfull attribute field code snippets

Source: Internet
Author: User

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:

  1. 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.
  2. 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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.