/// <summary> /// 長方形の大きさを表す型'<see cref="System.Drawing.Rectangle"/>'をヱンコンのセクションに変換します。 /// </summary> /// <param name="rect">変換前の長方形です。</param> /// <param name="name">変換後のセクションの名前です。</param> /// <returns>変換後のヱンコンのセクションを表す新しいインスタンスです。</returns> public static YSection ToYSection(this Rectangle rect, string name = "_rect") { var section = new YSection() { Name = name }; section.Add(new YNumber() { Name = "x", SInt64Value = rect.X }); section.Add(new YNumber() { Name = "y", SInt64Value = rect.Y }); section.Add(new YNumber() { Name = "w", SInt64Value = rect.Width }); section.Add(new YNumber() { Name = "h", SInt64Value = rect.Height }); return(section); }
public static void Set(YSection section, string type, string name, string value) { #if RELEASE try { #endif switch (type) { case "str": var str = new YString(); str.Name = name; str.Text = value; section.Add(str); break; case "num": var num = new YNumber(); num.Name = name; if (ulong.TryParse(value, out var val1)) { num.UInt64Value = val1; } section.Add(num); break; case "flg": var flg = new YBoolean(); flg.Name = name; if (value.TryToBoolean(out var val2)) { flg.Flag = val2; } section.Add(flg); break; default: // case "nul" var nul = new YNullOrEmpty(); nul.Name = name; section.Add(nul); break; } #if RELEASE } catch (Exception e) { Program.ShowError(e); } #endif }
public static void Adds(YSection section, string name) { section.Add(new YSection() { Name = name }); }
private static T GetKey <T>(YSection inix, YSection cfg, string keyName, Func <T> defaultValueFactory) where T : YNode { var result = inix.GetNode(keyName) as T ?? cfg.GetNode(keyName) as T; if (result == null) { result = defaultValueFactory(); result.Name = keyName; cfg.Add(result); } return(result); }
/// <summary> /// <paramref name="section"/>に論理値を設定します。 /// </summary> /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param> /// <param name="keyname">設定する論理値キーの名前です。</param> /// <param name="value">設定する論理値です。</param> public static void SetNodeAsBoolean(this YSection section, string keyname, bool value) { var node = section.GetNode(keyname); if (node is YBoolean flgKey) { flgKey.Flag = value; } else { section.Add(new YBoolean() { Name = keyname, Flag = value }); } }
/// <summary> /// <paramref name="section"/>に数値を設定します。 /// </summary> /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param> /// <param name="keyname">設定する数値キーの名前です。</param> /// <param name="value">設定する数値です。</param> public static void SetNodeAsNumber(this YSection section, string keyname, long value) { var node = section.GetNode(keyname); if (node is YNumber numKey) { numKey.SInt64Value = value; } else { section.Add(new YNumber() { Name = keyname, SInt64Value = value }); } }
/// <summary> /// <paramref name="section"/>に文字列値を設定します。 /// </summary> /// <param name="section">設定先の<see cref="Yencon.YSection"/>です。</param> /// <param name="keyname">設定する文字列キーの名前です。</param> /// <param name="value">設定する文字列です。</param> public static void SetNodeAsString(this YSection section, string keyname, string value) { var node = section.GetNode(keyname); if (node is YString strKey) { strKey.Text = value; } else { section.Add(new YString() { Name = keyname, Text = value }); } }