&tag(VisualStudio2010/コードスニペット); *目次 [#e544063b] #contents *参考情報 [#t2745c72] -[[Create a Snippet in Visual Studio 2010 | Visual Studio Tutor:http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/]] -[[Visual Studio 2008 Tip: Resolving Namespaces and Removing Unused Using Statements:http://davidhayden.com/blog/dave/archive/2008/01/29/VisualStudio2008ResolvingNamespacesRemovingUnusedUsingStatementsTip.aspx]] *基本 [#q3dbfff3] -「マイドキュメント\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets」フォルダ以下に 「xxx.snippet」ファイルを置く(C#用の場合)。 -Visual Studioを起動し直すと自動で読み込まれる。 -読み込まれたかどうかは、[ツール]→[コードスニペットマネージャー」→言語で[Visual C#]を選択し、My Code SnippetsがあればOK。 *C#用 [#qee058d1] *C#用/WPF [#qee058d1] -以下を読み込ませておき、vsのエディタでpropnchを入力後タブを押すとコードが展開される。変数の型など自動で連動してかわるので便利。 #pre{{ <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>propnch</Title> <Shortcut>propnch</Shortcut> <Description>Code snippet for property and backing field and ensure that it invokes INotifyPropertyChanigng and INotifyPropertyChanged</Description> <Author>Abhishek</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>type</ID> <ToolTip>Property type</ToolTip> <Default>int</Default> </Literal> <Literal> <ID>property</ID> <ToolTip>Property name</ToolTip> <Default>MyProperty</Default> </Literal> <Literal> <ID>field</ID> <ToolTip>The variable backing this property</ToolTip> <Default>myVar</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ private $type$ $field$; public $type$ $property$ { get { return $field$; } set { if ($field$ != value) { $field$ = value; NotifyPropertyChanged("$property$"); } } } $end$]]> </Code> </Snippet> </CodeSnippet> <CodeSnippet Format="1.0.0"> <Header> <Title>notifypc</Title> <Shortcut>notifypc</Shortcut> <Description>Code snippet for NotifyPropertyChanged</Description> <Author>mt</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Code Language="csharp"> <![CDATA[ public void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } $end$]]> </Code> </Snippet> </CodeSnippet> <CodeSnippet Format="1.0.0"> <Header> <Title>obs</Title> <Shortcut>obs</Shortcut> <Description>ObservableCollection</Description> <Author>mt</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>type</ID> <ToolTip>Property type</ToolTip> <Default>string</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ObservableCollection<$type$>$end$]]> </Code> </Snippet> </CodeSnippet> <CodeSnippet Format="1.0.0"> <Header> <Title>propobs</Title> <Shortcut>propobs</Shortcut> <Description>ObservableCollection Property</Description> <Author>mt</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>type</ID> <ToolTip>Property type</ToolTip> <Default>string</Default> </Literal> <Literal> <ID>field</ID> <ToolTip>The variable backing this property</ToolTip> <Default>myVar</Default> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[ public ObservableCollection<$type$> $field$ {get; set; } $end$]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> }}