# Adding / controlling code snippets

**URL:** https://forum.alternetsoft.com/t/adding-controlling-code-snippets/77
**Category:** AlterNET Studio Support
**Tags:** editor
**Created:** [May 28, 2020, 12:00am UTC](https://forum.alternetsoft.com/t/adding-controlling-code-snippets/77 "2020-05-28T00:00:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![andrew.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/andrew.medvedev/32/28_2.png) [@andrew.medvedev](https://forum.alternetsoft.com/u/andrew.medvedev)
#### Post date: [May 28, 2020, 12:00am UTC](https://forum.alternetsoft.com/t/adding-controlling-code-snippets/77/2 "2020-05-28T00:00:00Z")

</div>

Hi,  
There are two ways to customize code snippets.  
1. Add code snippet from code like this:  
 CodeSnippet snippet = new Alternet.Syntax.CodeCompletion.CodeSnippet();  
 snippet.Code = new CodeSnippetCode();  
 snippet.Header = new CodeSnippetHeader();  
 snippet.Header.Author = "Your";  
 snippet.Header.Description = "My custom class snippet";  
 snippet.Header.Title = "my custom class";  
 ICodeSnippetType type1 = new CodeSnippetType();  
 type1.SnippetType = SnippetType.Expansion;  
 snippet.Header.Types.Add(type1);  
 ICodeSnippetType type2 = new CodeSnippetType();  
 type2.SnippetType = SnippetType.SurroundsWith;  
 snippet.Header.Types.Add(type2);  
 snippet.ImageIndex = 64;  
 ICodeSnippetDeclaration decl = new CodeSnippetDeclaration();  
 ICodeSnippetLiteral literal = new CodeSnippetLiteral();  
 literal.ID = "name";  
 literal.ToolTip = "Class name";  
 literal.Default = "MyCustomClass";  
 decl.Literals.Add(literal);  
 snippet.Declarations.Add(decl);  
 snippet.Code.Delimiter = "$";  
 snippet.Code.Code = @"class $name$  
{  
 private int customField;  
$selected$$end$  
}";  
 csParser1.CodeSnippets.Add(snippet);  
2. Load code snippets from xml file like this:  
 csParser1.CodeSnippets.LoadFile(@"C:\Test\CSharpSnippets.xml");  
I've uploaded CSharpSnippets.xml here:  
[https://drive.google.com/file/d/1fZgOQ-fmIy77zJCJrqRPgwL-vJYUJwi-/view?usp=sharing](https://drive.google.com/file/d/1fZgOQ-fmIy77zJCJrqRPgwL-vJYUJwi-/view?usp=sharing)  
Kind regards,  
Andrew Medvedev

---

_[View the full topic](https://forum.alternetsoft.com/t/adding-controlling-code-snippets/77)._
