예제 #1
0
 public static void WriteBool(this IPv2ServerParamsInterface src, Pv2ParamType param, bool value)
 {
     if (param is not Pv2BoolParamType type)
     {
         throw new Exception($"Wrong type: want {nameof(Pv2BoolParamType)}. Got {param.GetType().Name}");
     }
     src.Write(param, (_, v) => type.SetValue(v, value));
 }
예제 #2
0
        public static bool ReadBool(this IPv2ClientParamsInterface src, Pv2ParamType param)
        {
            if (param is not Pv2BoolParamType type)
            {
                throw new Exception($"Wrong type: want {nameof(Pv2BoolParamType)}. Got {param.GetType().Name}");
            }
            var item = src.Read(param);

            return(type.GetValue(item));
        }
예제 #3
0
        public static async Task <bool> WriteBool(this IPv2ClientParamsInterface src, Pv2ParamType param, bool value,
                                                  CancellationToken cancel = default)
        {
            if (param is not Pv2BoolParamType type)
            {
                throw new Exception($"Wrong type: want {nameof(Pv2BoolParamType)}. Got {param.GetType().Name}");
            }
            var result = await src.Write(param, (_, val) => type.SetValue(val, value), cancel).ConfigureAwait(false);

            return(type.GetValue(result));
        }