आप नोटिस जहाँ आप चाहते हैं (कहने के लिए आप कीवर्ड जो कुछ भी करने के लिए आप चाहते हैं बदल सकते हैं अनावश्यक) सम्मिलित करने के लिए एक नया टुकड़ा और बस प्रकार सीपी + डबल टैब बना सकते हैं।
इसके साथ एकमात्र समस्या है, जो मुझे पता है, स्निपेट समय कार्यों का समर्थन नहीं करते हैं, इसलिए इस तकनीक के साथ आपकी तिथि रेखा के लिए वर्तमान समय प्राप्त करना असंभव लगता है। इसके लिए इतना अच्छा कामकाज नहीं है कि समय फ़ील्ड संपादन योग्य हो (जैसे कि एमबॉक्स स्निपेट कैसे काम करता है) और बस मैन्युअल रूप से समय डालें।
यहां एक उदाहरण है कि स्निपेट कैसा दिखता है। बोले स्निपेट को कक्षा का नाम स्वचालित रूप से प्राप्त होगा और उस स्थान पर कॉपीराइट नोटिस डालें जहां आप 'कॉपीराइट' और डबल टैब टाइप करते हैं।
विधि 1
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Copyright</Title>
<Shortcut>Copyright</Shortcut>
<Description>Code snippet for Copyright notice</Description>
<Author>author name</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[// <copyright file="$classname$" company="My Company Name">
// Copyright (c) 2012 All Rights Reserved
// <author>Leniel Macaferi</author>
// </copyright>
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
विधि 2
इसके अलावा, यहां एक कार्यक्रम आपको बस इतना करना है कि आप के लिए कर सकते हैं का एक उदाहरण है।
List<string> files = new List<string>()
{
"c:\\Form1.cs",
"c:\\Form2.cs",
};
foreach (string file in files)
{
string tempFile = Path.GetFullPath(file) + ".tmp";
using (StreamReader reader = new StreamReader(file))
{
using (StreamWriter writer = new StreamWriter(tempFile))
{
writer.WriteLine(@"// <copyright file=" + Path.GetFileNameWithoutExtension(file) + @" company=My Company Name>
// Copyright (c) 2012 All Rights Reserved
// </copyright>
// <author>Leniel Macaferi</author>
// <date> " + DateTime.Now + @"</date>
// <summary>Class representing a Sample entity</summary>
");
string line = string.Empty;
while ((line = reader.ReadLine()) != null)
{
writer.WriteLine(line);
}
}
}
File.Delete(file);
File.Move(tempFile, file);
}
कुछ त्रुटि पकड़ने की आवश्यकता होगी। लेकिन यह आपको सामान्य विचार देना चाहिए कि इसके आस-पास एक यूआई कैसे बनाया जाए, उन फ़ाइलों को जोड़ें जिन्हें आप संसाधित करना चाहते हैं।
विधि 3
यह भी आम तौर पर के अंतर्गत पाया जा जा सकता है कि अपनी कक्षाओं के लिए टेम्पलेट बदलने के लिए संभव है:
C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE\ItemTemplates\CSharp\1033\
कभी कभी संपादन ItemTemplatesCache भी परिणाम प्रदर्शित करने के लिए आवश्यक है।
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
/* <copyright file=$safeitemrootname$ company="My Company Name">
Copyright (c) 2012 All Rights Reserved
</copyright>
<author>Leniel Macaferi</author>
<date>$time$</date>
<summary>Class representing a Sample entity</summary>*/
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
आप एक पूर्व/पोस्ट का निर्माण कदम है कि एक powershell स्क्रिप्ट यदि प्रत्येक सीएस फ़ाइल किसी दिए गए शीर्ष-लेख है की जाँच करता है कि चलाता है का इस्तेमाल कर सकता है, और यह पहले जोड़ें अगर यह नहीं है – PhonicUK
@PonicUK: यह एक अच्छा विकल्प होगा। मैं बस PowerShell के साथ छिपा नहीं हूँ। :) –
या एक छोटा सी # ऐप लिखें जो इसके बजाए ऐसा करता है और उसे चलाता है? – PhonicUK