C# PowerShell Shell
Latest commit 19d4a76 Feb 12, 2017 @k94ll13nn3 Remove Cake.Git
Permalink
Failed to load latest commit information.
docs
src/Strinken Add code coverage to build (#32) Feb 10, 2017
test
tools
.gitattributes
.gitignore
.travis.yml Simplify Travis build (#33) Feb 11, 2017
CHANGELOG.md
GitVersion.yml Bump version Feb 3, 2017
LICENSE
README.md Add code coverage to build (#32) Feb 10, 2017
Strinken.sln
appveyor.yml
build-travis.cake
build.cake
build.ps1
build.sh Simplify Travis build (#33) Feb 11, 2017
global.json
logo_64x64.png Reupload of package icon in the root folder Oct 27, 2016
strinken.ruleset
stylecop.json

README.md

Strinken

NuGet GitHub release GitHub license Coverage Status

Build server Platform Status
AppVeyor Windows AppVeyor
Travis Linux Travis

A parametrized string library !

Installation

Nuget Install-Package Strinken

Parser usage

Create a tag:

public class ExampleTag : ITag<ExampleClass>
{
    public string Description => "Example";
    public string Name => "Example";
    public string Resolve(ExampleClass value) => value.Name;
}

Create a parameter tag:

public class DateParameterTag : IParameterTag
{
    public string Description => "Date";
    public string Name => "Date";
    public string Resolve() => DateTime.Now.ToString();
}

Create a filter (example taken from the base filters):

public class LowerFilter : IFilter
{
    public string Description => "Converts a string to lowercase.";
    public string Name => "Lower";
    public string Usage => "{tag:Lower}";
    public string Resolve(string value, string[] arguments) => value.ToLowerInvariant();
    public bool Validate(string[] arguments) => arguments == null || arguments.Length == 0;
}

Create a parser:

var parser = new Parser<ExampleClass>()
                .WithTag(new ExampleTag())
                .WithFilter(new LowerFilter()) // for the example, but the LowerFilter is a base filter.
                .WithParameterTag(new DateParameterTag());

Validate a string:

parser.Validate("My name is {Example:Lower}.")
// returns a ValidationResult with IsValid = true
parser.Validate("My name is {Example:Lower+arg}.")
// returns a ValidationResult with IsValid = false and Message = "Lower does not have valid arguments."

Parse a string:

var result = parser.Resolve("My name is {Example:Lower}.", new ExampleClass { Name = "Lorem" })
// returns "My name is lorem."