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;
    }
}