-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsharp.json
More file actions
82 lines (82 loc) · 2.95 KB
/
csharp.json
File metadata and controls
82 lines (82 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
"Custom C# Boilerplate with Common Namespaces & Utilities": {
"prefix": "cs-self",
"body": [
"// COMMON USING DIRECTIVES",
"using System;",
"using System.IO;",
"using System.Text;",
"using System.Linq;",
"using System.Collections.Generic;",
"using System.Threading;",
"using System.Threading.Tasks;",
"using System.Diagnostics;",
"using System.Globalization;",
"using System.Net.Http;",
"using System.Net;",
"using System.Text.Json;",
"using System.Text.RegularExpressions;",
"",
"// Optional:",
"// using Newtonsoft.Json; // JSON (external)",
"// using Microsoft.Extensions.Logging; // Logging",
"",
"// TOP-LEVEL PROGRAM (C# 9+)",
"Console.OutputEncoding = Encoding.UTF8;",
"",
"try",
"{",
" ${1:// Your code here}",
"}",
"catch (Exception ex)",
"{",
" Console.WriteLine($\"❌ Error: {ex.Message}\");",
"}",
"",
"// UTILITY FUNCTIONS",
"static void Print<T>(IEnumerable<T> list)",
"{",
" foreach (var item in list) Console.Write(item + \" \");",
" Console.WriteLine();",
"}",
"",
"static int Add(int a, int b) => a + b;",
"",
"static async Task<string> FetchAsync(string url)",
"{",
" using HttpClient client = new HttpClient();",
" return await client.GetStringAsync(url);",
"}",
"",
"// OOP CLASS TEMPLATE",
"class Person",
"{",
" public string Name { get; set; }",
" public int Age { get; set; }",
"",
" public Person(string name, int age)",
" {",
" Name = name;",
" Age = age;",
" }",
"",
" public void Introduce()",
" {",
" Console.WriteLine($\"Hi, I'm {Name} and I'm {Age} years old.\");",
" }",
"}",
"",
"// OPTIONAL FULL MAIN METHOD (instead of top-level)",
"${2:// public class Program",
"// {",
"// public static async Task Main(string[] args)",
"// {",
"// Console.WriteLine(\"Hello from Main()\");",
"// if (args.Length > 0) Console.WriteLine($\"First arg: {args[0]}\");",
"// }",
"// }"
]
,
"description": "Custom C# boilerplate with namespaces, utilities, OOP, async, and robust structure"
}
}