public static ValidationResult <Agreement> Create(string value, string type, string pmode) { var valueResult = EbmsString.Create(value); var typeResult = EbmsString.Create(type).ToMaybe(); var pmodeResult = EbmsString.Create(pmode).ToMaybe(); return(valueResult.Select(v => new Agreement(v, typeResult, pmodeResult))); }
public void Test1 <T>() { // Specification before the actual check of the base-uri. Spec <Uri> spec = Spec.Of <Uri>("uri") .NotNull("uri should not be 'null'") .Equal(uri => uri.Scheme, Uri.UriSchemeHttps, "@scheme should be 'https' scheme"); ValidationResult <Uri> validationResult = spec.Validate(new Uri("http://localhost", UriKind.Relative)); // Demonstration purposes, generic type could be anything. IObservable <T> obs = null; // Access controlled function with validation, revocation, limited amount of evaluations and time-based availability. Access <Uri, Uri> access = Access.OnlyUriFromBase(new Uri("https://localhost:9090/")) .Satisfy(spec) .Once() .DuringHours(9, 17) .RevokedWhen(obs); // Somewhere else... AccessResult <Uri> result = access.Eval(new Uri("http://localhost:9090/path")); if (result.TryGetValue(out Uri output)) { // use the now correct 'output' } int unknown = 5; Untrust <int> untrusted = unknown; ValidationResult <NonZeroInt> nonZeroIntValidationResult = Spec.Of <int>() .GreaterThan(0, "should not be zero") .CreateModel(untrusted, i => new NonZeroInt(i)); Outcome <EbmsString, IDictionary <string, string[]> > ebmsStringResult = EbmsString.Create("mycustomid"); var int100 = Valid <int> .Create(9, x => x > 0 && x < 100, "should be between 1-100"); Outcome <EbmsString, Exception> deserialize = Json.Deserialize <EbmsString>(new Valid <JObject>()); deserialize.Do(ex => throw ex); var nonEmptyResult = NonEmptyEnumerable <string> .Create(new[] { "test1", "test2", "test3" }); var uniqueResult = UniqueEnumerable <int> .Create(new[] { 1, 2, 3 }); }