//using Newtonsoft.Json; //using Newtonsoft.Json.Linq; //using System.Collections.Generic; //namespace System //{ // /// // /// 利用Json字符串实现的一种 状态码(code) 对应 模型类(value) 动态解析 switch case 模式,数据类似与 // /// // public static class CodeValuePair // { // public const string code = "code"; // public const string value = "value"; // public static string Create(TCode code, object? value) where TCode : struct, IConvertible // { // var result = new Dictionary // { // { CodeValuePair.code, code.ConvertToInt32() }, // { CodeValuePair.value, value } // }; // var jsonStr = JsonConvert.SerializeObject(result); // return jsonStr; // } // public static JObject GetValue(JObject jObject) // { // var value = jObject.Value(CodeValuePair.value); // return value; // } // public static Action Switch(Action action) => jObject => // { // var value = GetValue(jObject).ToObject(); // action?.Invoke(value); // }; // public static TResult? Switch( // string jsonStr, // IReadOnlyDictionary keyValuePairs, // Func @delegate) // where TCode : struct, IConvertible // { // if (!string.IsNullOrWhiteSpace(jsonStr)) // { // var jObject = JObject.Parse(jsonStr); // var key = jObject.Value(code).ConvertToEnum(); // if (keyValuePairs.ContainsKey(key)) // { // var value = keyValuePairs[key]; // return @delegate.Invoke(key, value, jObject); // } // } // return default; // } // public static void Switch( // string jsonStr, // IReadOnlyDictionary> keyValuePairs) // where TCode : struct, IConvertible // { // Switch(jsonStr, keyValuePairs, Invoke); // static object? Invoke(TCode key, Action value, JObject @object) // { // value?.Invoke(@object); // return default; // } // } // } //#if DEBUG // [Obsolete("", true)] // public static partial class Default // { // [Obsolete("use CodeValuePair", true)] // public static class Keys // { // public const string code = CodeValuePair.code; // public const string value = CodeValuePair.value; // public static JObject GetValue(JObject jObject) => CodeValuePair.GetValue(jObject); // public static Action Switch(Action arg) => CodeValuePair.Switch(arg); // } // } //#endif //}