[英]Castle Windsor Visual Studio Code Snippet for ILogger
In Visual Studio you can use code snippets eg when your are editing a class you can type ctor
and the default constructor will automaticly be added to your class. 在Visual Studio中,您可以使用代码段,例如,在编辑类时,可以键入
ctor
,默认构造函数将自动添加到您的类中。 Is it possible to create a code snippet in Visual Studio, that does the following: 是否可以在Visual Studio中创建代码段,以执行以下操作:
Logger
property where the cursor is. Logger
属性。 using Castle.Core.Logging
using Castle.Core.Logging
添加 private ILogger _logger = NullLogger.Instance;
private ILogger _logger = NullLogger.Instance;
. public class Person
{
private string name;
private int age;
public Person()
{
}
// cursor is here and you type "logger"
}
After you type logger
visual Studio adds the following code: 键入
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; }
}
}
There is two great tutorials here How to: Create a Basic Code Snippet & How to: Manage Code Snippets 这里有两个很棒的教程:如何:创建基本代码片段以及如何:管理代码片段
The summary is as follows, 总结如下,
Happy to throw together an example if you'd like. 如果愿意,可以举一个例子。
As I've created the snippet to test this, you'll want something as follows. 在创建代码段进行测试时,您将需要以下内容。 Self evident what you need to edit to suit your needs.
不言而喻的是,您需要根据自己的需要进行编辑。
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.