Create Code Snippet Using C#
Merhaba Arkadaşlar defalarca aynı kodları oluşturmaktan sıkıldım diyorsanız.
örnek for yazıp tab tab dediğiniz de
for (int i = 0; i < length; i++)
{
}
bu şekilde bir yapı çıkıyor bizde SqlIn yada PgIns değimizde bu gibi şeyleri yapmak istersek eğer örnek bir şablon elinizin altında her daim bulunması gerekiyor.
Visual studio penceresinde Tools menüsünde Code Snippets Manager tıklayarak bu örnek snippet ‘ sizlerde ekliye bilirsiniz.
Kodlar :
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <Header> <Title>PgInsert</Title> <Author>Orhan Türk</Author> <Shortcut>PgIns</Shortcut> <Description>Npgsql Connection</Description> <SnippetTypes> <SnippetType>SurroundsWith</SnippetType> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>message</ID> <Default>my function</Default> </Literal> </Declarations> <Code Language="CSharp"> <![CDATA[ NpgsqlConnection con = new NpgsqlConnection(Degiskenler.SqlStr); try { con.Open(); NpgsqlCommand cmd = con.CreateCommand(); cmd.CommandText = ""; cmd.Parameters.AddWithValue("", ""); cmd.Parameters.AddWithValue("", ""); cmd.Parameters.AddWithValue("", ""); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); }]]> </Code> </Snippet> </CodeSnippet>
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <Header> <Title>SqlInsert</Title> <Author>Orhan Türk</Author> <Shortcut>SqlIns</Shortcut> <Description>Sql Connection</Description> <SnippetTypes> <SnippetType>SurroundsWith</SnippetType> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>message</ID> <Default>my function</Default> </Literal> </Declarations> <Code Language="CSharp"> <![CDATA[ SqlConnection con = new SqlConnection(Degiskenler.SqlStr); try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = ""; cmd.Parameters.AddWithValue("", ""); cmd.Parameters.AddWithValue("", ""); cmd.Parameters.AddWithValue("", ""); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); }]]> </Code> </Snippet> </CodeSnippet>