public override void WriteJson(JsonWriter writer, ClearableValue <T> clearable, JsonSerializer serializer)
        {
            writer.WriteStartObject();

            string state = clearable.Match(
                set: _ => Constants.Clearable_SetState,
                clear: () => Constants.Clearable_ClearState,
                noAction: () => Constants.Clearable_NoActionState);

            writer.WritePropertyName(Constants.StatePropertyName);
            writer.WriteValue(state);

            var(isSet, value) = clearable.Match(
                set: e => (true, e),
                clear: () => (false, default(T)),
                noAction: () => (false, default(T)));
            if (isSet)
            {
                writer.WritePropertyName(Constants.ValuePropertyName);
                serializer.Serialize(writer, value);
            }

            writer.WriteEndObject();
        }
示例#2
0
 public static void Act <T>(this ClearableValue <T> value, Action <T> set, Action clear, Action noAction = null) =>
 value.Match(
     set: set.ToVoidFunc(),
     clear: clear.ToVoidFunc(),
     noAction: noAction.ToVoidFuncOrEmpty());
示例#3
0
 public static T?ReduceOrNull <T>(this ClearableValue <T> value, T?clear = null, T?noAction = null) where T : struct =>
 value.Match(
     set : Functions.NullableId,
     clear : () => clear,
     noAction : () => noAction);
示例#4
0
 public static T Reduce <T>(this ClearableValue <T> value, T clear = default(T), T noAction = default(T)) =>
 value.Match(
     set: Functions.Id,
     clear: () => clear,
     noAction: () => noAction);
示例#5
0
 public static T ReduceWith <T>(this ClearableValue <T> value, Func <T> clear, Func <T> noAction) =>
 value.Match(
     set: Functions.Id,
     clear: clear,
     noAction: noAction);
示例#6
0
 public static bool IsNoAction <T>(this ClearableValue <T> value) =>
 value.Match(
     set: _ => true,
     clear: () => false,
     noAction: () => false);