Bạn có thể gần như thực hiện việc này bằng đoạn mã Visual Studio (tức là mà không cần ReSharper).
Lưu phần sau dưới dạng tệp có phần mở rộng là .snippet
.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>string format</Title>
<Author>Matthew Strawbridge</Author>
<Description>Wraps the selected text with string.Format</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>variable</ID>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[string.Format($selected$, $variable$);]]>
</Code>
</Snippet>
</CodeSnippet>
Sau đó, bạn có thể tải nó qua Công cụ | Mã Snippets Manager | Nhập.
Khi đoạn mã có sẵn, bạn có thể gõ
var message = "Hello {0}"
nhưng bạn phải chọn chuỗi và sau đó nhấn Ctrl KCtrlS và chọn tên đoạn tới áp dụng nó. Điều này sẽ tạo ra
var message = string.Format("Hello {0}", value);
với phần value
được chọn để chỉnh sửa.
Chỉnh sửa: Ngoài ra còn có Snippet Designer extension giúp làm việc với đoạn mã dễ dàng hơn.
Nguồn
2011-12-30 01:01:37
Thay vì nhập '{0}', chỉ cần sử dụng 'alt + enter' và chọn tùy chọn R # của' Thêm mục định dạng mới và đối số thích hợp'. –