.NET 開発基盤部会 Wiki

目次

概要

要件

画面初期化

編集画面生成

編集画面生成に使用する。

構造

Bean構造

以下のBeanをリストで保持する(List<Control>)。

コントロールのルート

List<Control>

コントロールのグループ化

List<Control>

コントロール

Control

JSON構造

[
  {
    "Type": 1,
    "Edit": {
      "Caption": "test1",
      "Editable": true
    },
    "Value": {
      "Text": "test1"
    }
  },
  {
    "Type": 2,
    "Edit": {
      "Caption": "img1",
      "Editable": true
    },
    "Value": {
      "ImageId": 100
    }
  },
  {
    "Type": 3,
    "Edit": {
      "Caption": "group1"
    },
    "Value": {
      "Group": [
        {
          "Type": 1,
          "Edit": {
            "Caption": "test2",
            "Editable": true
          },
          "Value": {
            "Text": "test2"
          }
        },
        {
          "Type": 2,
          "Edit": {
            "Caption": "img2",
            "Editable": true
          },
          "Value": {
            "ImageId": 200
          }
        }
      ]
    }
  }
]

サンプル・コード

namespace JSON
{
  public enum EType { Text = 1, Image, Group};
  [JsonObject("Edit")]
  public class CEdit
  {
    [JsonProperty("Caption")]
    public string Caption = "";
    [JsonProperty("Editable")]
    public bool Editable = false;
  }
  [JsonObject("Value")]
  public class CValue
  {
    [JsonProperty("Text")]
    public string Text { get; set; }
    [JsonProperty("ImageId")]
    public int ImageId { get; set; }
    [JsonProperty("Group")]
    public List<Control> Group { get; set; }
  }
  [JsonObject("Ctrl")]
  public class Control
  {
    [JsonProperty("Type")]
    public EType Type = EType.Text;
    [JsonProperty("Edit")]
    public CEdit Edit = new CEdit();
    [JsonProperty("Value")]
    public CValue Value = new CValue();
  }
  public class Program
  {
    static void Main(string[] args)
    {
      JSON.Control ctrl = null;
      List<JSON.Control> lstctrl1 = new List<JSON.Control>();
      List<JSON.Control> lstctrl2 = new List<JSON.Control>();
     
      //---
      ctrl = new JSON.Control();
      ctrl.Type = EType.Text;
      ctrl.Edit.Caption = "test1";
      ctrl.Edit.Editable = true;
      ctrl.Value.Text = "test1";
      lstctrl1.Add(ctrl);
      
      //---
      ctrl = new JSON.Control();
      ctrl.Type = EType.Image;
      ctrl.Edit.Caption = "img1";
      ctrl.Edit.Editable = true;
      ctrl.Value.ImageId = 100;
      lstctrl1.Add(ctrl);
      
      //---
      ctrl = new JSON.Control();
      ctrl.Type = EType.Group;
      ctrl.Edit.Caption = "group1";
      ctrl.Edit.Editable = false;
      ctrl.Value.Group = lstctrl2;
      lstctrl1.Add(ctrl);
      
      //---
      ctrl = new JSON.Control();
      ctrl.Type = EType.Text;
      ctrl.Edit.Caption = "test2";
      ctrl.Edit.Editable = true;
      ctrl.Value.Text = "test2";
      lstctrl2.Add(ctrl);
      
      //---
      ctrl = new JSON.Control();
      ctrl.Type = EType.Image;
      ctrl.Edit.Caption = "img2";
      ctrl.Edit.Editable = true;
      ctrl.Value.ImageId = 200;
      lstctrl2.Add(ctrl);
      
      string json = JsonConvert.SerializeObject(lstctrl1, Formatting.Indented, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore});
      Console.WriteLine(json);
      lstctrl1 = JsonConvert.DeserializeObject<List<JSON.Control>>(json);
    }
  }
}

参考


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS