using System; using System.Collections.Generic; namespace AnP.Utils{ public class Options{ public const int OVERWRITING = 0; public static readonly int OVERWRITE = 1 * (int)Math.Pow(3, OVERWRITING); public static readonly int NO_OVERWRITE = 2 * (int)Math.Pow(3, OVERWRITING); public const int NULLISH = 1; public static readonly int ALLOW_NULLS = 1 * (int)Math.Pow(3, NULLISH); public static readonly int NO_NULLS = 2 * (int)Math.Pow(3, NULLISH); public static readonly Options DEFAULT = new Options(NO_OVERWRITE + ALLOW_NULLS); public static bool? get(int value, int option){ int ternary = value / (int)Math.Pow(3, option) % 3; return ( ternary == 1 ? true : ternary == 2 ? false : null); } public bool? overwrite = null; public bool? allow_null = null; public Options(int value = 0, Options? _default = null){ if(_default == null) _default = DEFAULT; overwrite = get(value, OVERWRITING) ?? _default?.overwrite; allow_null = get(value, NULLISH) ?? _default?.allow_null; } public int get(){ int code = 0; foreach(KeyValuePair pair in new Dictionary{ {OVERWRITING, overwrite}, {NULLISH, allow_null} }) code += ( pair.Value == true ? 1 : pair.Value == false ? 2 : 0) * (int)Math.Pow(3, pair.Key); return code; } } }