public static Task SaveSnippets(string directory, CancellationToken ct) { var groups = GuardFunctionAttribute.GetMethods(Assembly.GetAssembly(typeof(Guard))) .Where(p => p.Value.Shortcut != null) .GroupBy(p => p.Value.Shortcut) .ToList(); return(SaveVisualStudioSnippets("guard-cs.vs.snippet")); async Task SaveVisualStudioSnippets(string name) { var snippets = groups.SelectMany(g => g.SelectMany(p => VisualStudioSnippet.CreateSnippets(p.Key, p.Value))); var document = VisualStudioSnippet.CreateDocument(snippets); using (var file = File.Create(Path.Combine(directory, name))) using (var writer = new StreamWriter(file, Encoding)) { await document.SaveAsync(writer, SaveOptions.None, ct).ConfigureAwait(false); Console.WriteLine($"Created \"{file.Name}\""); } } }
private static IEnumerable <KeyValuePair <MethodInfo, GuardFunctionAttribute> > GetMarkedMethods() => GuardFunctionAttribute.GetMethods(Assembly.GetAssembly(typeof(Guard)));