/OptionType

Implementation of Option in C#.

Primary LanguageC#MIT LicenseMIT

OptionType & OptionType.Validation

  • NuGet Status

    OptionType OptionType.Validation
    nuget NuGet NuGet
  • Build Status Build Status

OptionType

OptionType implementation in C#

Could be downloaded from NuGet: Install-Package OptionType

usage

  • via Option static method:
var result = Option<string>.Some("on nie wiedzial");

var none = Option<string>.None;
  • via Some extension method:
var anotherResult = "on nie wiedzial".Some();
  • via Some extension method with predicate:
var anotherResult = "on nie wiedzial".Some(x => !string.IsNullOrWhitespace(x));
  • via None extension method with predicate:
var anotherResult = "on nie wiedzial".None(x => !string.IsNullOrWhitespace(x));
  • via implicit cast:
Option<string> anotherAnotherResult = "on nie wiedzial";

How to check what option contains?

  • via IsSome and IsNone properties on a OptionType object.

OptionType.Validation

OptionType.Validation package provides a simple Rule class to defines Rules which should apply to some objects and as a result returns OptionType. Could be downloaded from NuGet: Install-Package OptionType.Validation

example usage looks like this:

var rules = new[]
{
    new Rule(() => "name".StartsWith("n"), "name"),
    new Rule(() => "dd".StartsWith("e"), "dd"),
    new Rule(() => "hh".StartsWith("a"), "hh"),
    new Rule(() => "hehe".StartsWith("h"), "hehe"),
};
var result = rules.Apply();