[VS] Hướng Dẫn Tạo Code Snippet Trong Visual Studio - C# Căn Bản
Có thể bạn quan tâm
Sử dụng Code Snippet trong Visual Studio giúp giảm số lần gõ phím, tăng tốc độ coding (giảm thời gian coding) cũng tức là giảm bệnh nghề nghiệp, tăng thêm thời gian để tập trung vào việc hữu ích hơn (so với coding).
Nội dung
Một số Code Snippet C# có sẵn
prop – tạo thuộc tính tự thực hiện (auto-implemented property). propfull – tạo thuộc tính có đủ get set. propg – tạo thuộc tính tự thực hiện chỉ đọc. else, if, do, for, foreach, switch, while – tạo các câu lệnh tương ứng struct, class, enum – khai báo các kiểu try, tryf – tạo khối try, try-finally
Nơi lưu trữ Code Snippet
Nơi lưu trữ Code Snippet có sẵn nằm trong thư mục: “C:Program FilesMicrosoft Visual Studio 12.0VC#Snippets1033Visual C#”
Các Code Snippet do ta tự tạo sẽ nằm trong thư mục “C:UsersTênUserDocumentsVisual Studio 2013Code SnippetsVisual C#My Code Snippets” (Win 8)
Tạo một Code Snippet
Sau đây ta sẽ tự tạo một Code Snippet đối với khối cấu trúc try…catch. Theo đoạn mã như sau.
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>try</Title> <Shortcut>try</Shortcut> <Description>Code snippet for try catch</Description> <Author>Microsoft Corporation</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal> <ID>expression</ID> <ToolTip>Exception type</ToolTip> <Function>SimpleTypeName(global::System.Exception)</Function> </Literal> </Declarations> <Code Language="csharp"><![CDATA[try { $selected$ } catch ($expression$ ex) { MessageBox.Show(ex.ToString()); }]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>Kết quả

ĐĂNG KÝ MUA HÀNG
Email (*) Điện thoại (*) Tên sản phẩm/Dịch vụ:
Lượt xem: 2.701 Chia sẻ Xem thêm [WPF] Hướng dẫn sử dụng Styling cho Button trong wpfĐiều hướng bài viết
[C#,WPF] Tạo ứng dụng chạy với quyền quản trị [WPF] Hướng dẫn tạo splash screen trong WPFTừ khóa » Vs 2019 Custom Snippets
-
Walkthrough: Create A Code Snippet - Visual Studio (Windows)
-
Code Snippets - Visual Studio (Windows) - Microsoft Docs
-
Code Snippet Picker - Visual Studio (Windows) | Microsoft Docs
-
Snippets In Visual Studio Code
-
Code Snippets In Visual Studio 2019 (#197) - YouTube
-
Creating Code Snippets In Visual Studio 2022 - C# Corner
-
How To Automatically Generate C# Code Snippets In Visual Studio
-
Code Snippets - Visual Studio - RIP Tutorial
-
VS 2019 Custom Code Snippet With Literals Not Expanding Correctly
-
Visual Studio Tip: Creating Your Own Code Snippets - Telerik
-
How To Create New Code Snippets From Existing Ones In Visual Studio
-
Type Less Code More With VS Code Custom Snippets
-
Custom Snippets/code Completion In VS Code | By Harry Theo
-
How To Create A Custom VS Code Snippet To Scaffold Your React ...