在Visual Studio中,您可以使用代码段,例如在编辑类时,可以键入ctor
,默认构造函数将自动添加到您的类中。
是否可以在Visual Studio中创建代码片段,执行以下操作:
Logger
属性。using Castle.Core.Logging
private ILogger _logger = NullLogger.Instance;
。public class Person
{
private string name;
private int age;
public Person()
{
}
// cursor is here and you type "logger"
}
键入logger
后,visual Studio会添加以下代码:
using Castle.Core.Logging; // Added by code snippet
public class Person
{
private string name;
private ILogger _logger = NullLogger.Instance; // Added by code snippet
private int age;
public Person()
{
}
// Added by code snippet
public ILogger Logger
{
get { return _logger; }
set { _logger = value; }
}
}
答案 0 :(得分:0)
这里有两个很棒的教程How to: Create a Basic Code Snippet& How to: Manage Code Snippets
摘要如下,
如果你愿意的话,很高兴把一个例子放在一起。
由于我已经创建了要测试它的代码段,因此您需要以下内容。根据您的需要编辑您需要编辑的内容。
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2010/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>
Log4Net instance using Castle.Core.Logging
</Title>
<Shortcut>logger</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>Castle.Core.Logging.dll</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>Castle.Core.Logging</Namespace>
</Import>
</Imports>
<Code Language="CSharp">
<![CDATA[private ILogger _logger = NullLogger.Instance;
public ILogger Logger
{
get { return _logger; }
set { _logger = value; }
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>