Snippet Manager API enables to work with Visual Studio snippet format.
C#
Clone or download

README.md

Snippet Manager

Introduction

  • Snippet Manager is .NET library that enables to work with Visual Studio snippets.
  • The library is distributed via NuGet.

Supported Frameworks

  • .NET Framework 4.0
  • .NET Standard 1.3
  • Portable Class Library (Profile 259)
    • .NET Framework 4.5
    • Windows 8.0
    • Windows Phone 8.1
    • Windows Phone 8.0
    • .NET Standard 1.0

Usage

Namespaces

using Pihrtsoft.Snippets;
using Pihrtsoft.Snippets.Comparers;
using Pihrtsfot.Snippets.Validations;

Load Snippets from Directory

public static IEnumerable<Snippet> LoadSnippets(string directoryPath)
{
    return SnippetSerializer.DeserializeFiles(directoryPath, SearchOption.AllDirectories)
        .SelectMany(f => f.Snippets));
}

Validate Snippets

public static IEnumerable<SnippetValidationResult> ValidateSnippets(IEnumerable<Snippet> snippets)
{
    SnippetValidator validator = SnippetValidator.CreateDefaultValidator();
    foreach (Snippet snippet in snippets)
    {
        foreach (SnippetValidationResult result in validator.Validate(snippet))
            yield return result;
    }
}

Find Duplicate Shortcuts

public static IEnumerable<IGrouping<string, Snippet>> FindDuplicateShortcuts(IEnumerable<Snippet> snippets)
{
    foreach (IGrouping<string, Snippet> grouping in SnippetUtility.FindDuplicateShortcuts(snippets))
        yield return grouping;
}

Get Changed Snippets

public static IEnumerable<Snippet> GetChangedSnippets(IEnumerable<Snippet> snippets)
{
    var equalityComparer = new SnippetDeepEqualityComparer();

    foreach (Snippet snippet in snippets)
    {
        var clone = (Snippet)snippet.Clone();

        clone.Literals.Sort();
        clone.Keywords.Sort();
        clone.Namespaces.Sort();
        
        // do some other processing

        if (!equalityComparer.Equals(snippet, clone))
            yield return clone;
    }
}