public static void Match <T>(this IStormContent <T> content, Action <T> onValue, Action <StormError> onError)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (onValue == null)
            {
                throw new ArgumentNullException(nameof(onValue));
            }
            if (onError == null)
            {
                throw new ArgumentNullException(nameof(onError));
            }

            object?OnValue(T v)
            {
                onValue(v);
                return(null);
            }

            object?OnError(StormError e)
            {
                onError(e);
                return(null);
            }

            content.Match(OnValue, OnError);
        }
        public static bool TryGetValue <T>(this IStormContent <T> content, out T value)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var(hasValue, matchValue) = content.Match <(bool, T)>(v => (true, v), e => (false, default));
 public static T GetValueOrThrow <T>(this IStormContent <T> content)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     return(content.Match(v => v, e => throw e));
 }
示例#4
0
        public StormFuncInput(IStormContent <T> content, EStormFuncInputState visitState)
        {
            if (!Enum.IsDefined(typeof(EStormFuncInputState), visitState))
            {
                throw new ArgumentOutOfRangeException(nameof(visitState));
            }

            Content    = content ?? throw new ArgumentNullException(nameof(content));
            VisitState = visitState;
        }
        public static bool TryGetError <T>(this IStormContent <T> content, [NotNullWhen(true)] out StormError?error)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var(hasError, matchError) = content.Match <(bool, StormError?)>(v => (false, null), e => (true, e));

            error = matchError;
            return(hasError);
        }
示例#6
0
 public static string ToString <T>(IStormContent <T> content)
 {
        public string ToString(IStormContent <object> content, EStormFuncInputState state)
        {
            var sut = new StormFuncInput <object>(content, state);

            return(sut.ToString());
        }