Skip to content

Commit 9c9fc1a

Browse files
author
Mohamed Ali
committed
serializable class code in form2 - nested types
1 parent 1ee398b commit 9c9fc1a

File tree

10 files changed

+381
-29
lines changed

10 files changed

+381
-29
lines changed

DartClassGenerator.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Selim.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace JsonToDart
9+
{
10+
public class DartClassGenerator
11+
{
12+
public static Queue<JsonObject> innerObjects = new Queue<JsonObject>();
13+
14+
15+
public string generateDartClass(JsonObject jsonObject, string className)
16+
{
17+
innerObjects.Clear();
18+
jsonObject.setClassName(className);
19+
var sb = new StringBuilder();
20+
//
21+
jsonObject.createDartClass(sb);
22+
//
23+
while(innerObjects.Count > 0)
24+
{
25+
var obj = innerObjects.Dequeue();
26+
obj.createDartClass(sb);
27+
}
28+
//
29+
return sb.ToString();
30+
}
31+
32+
}
33+
}

Form1.Designer.cs

Lines changed: 44 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form1.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Form1()
2020

2121
private void Form1_Load(object sender, EventArgs e)
2222
{
23-
23+
2424
}
2525

2626
private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
@@ -42,19 +42,35 @@ private void convertBtn_Click(object sender, EventArgs e)
4242
{
4343
if (String.IsNullOrWhiteSpace(jsonTextBox.Text)) return;
4444
//
45-
var jp = new JsonParser();
46-
var json = jp.Parse(jsonTextBox.Text);
45+
try
46+
{
47+
var jp = new JsonParser();
48+
var json = jp.Parse(jsonTextBox.Text);
49+
50+
if (!(json is JsonObject))
51+
{
52+
MessageBox.Show(this, "must be json object");
53+
return;
54+
}
55+
//
56+
var jsonObject = json as JsonObject;
57+
58+
var className = string.IsNullOrWhiteSpace(classNameTextBox.Text) ? "RootClass"
59+
: classNameTextBox.Text;
4760

48-
if (!(json is JsonObject))
61+
var generator = new DartClassGenerator();
62+
63+
dartTextBox.Text = generator.generateDartClass(jsonObject, className);
64+
}
65+
catch (Exception ex)
4966
{
50-
//ShowDialog()
51-
return;
67+
MessageBox.Show(this, ex.Message);
5268
}
53-
//
54-
var jObject = json as JsonObject;
69+
}
5570

56-
jObject.setClassName(string.IsNullOrWhiteSpace(classNameTextBox.Text)? "RootClass" : classNameTextBox.Text);
57-
dartTextBox.Text = jObject.createDartClass(new StringBuilder());
71+
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
72+
{
73+
new Form2().ShowDialog(this);
5874
}
5975
}
6076
}

Form2.Designer.cs

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form2.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace JsonToDart
12+
{
13+
public partial class Form2 : Form
14+
{
15+
public Form2()
16+
{
17+
InitializeComponent();
18+
}
19+
20+
private void button1_Click(object sender, EventArgs e)
21+
{
22+
try
23+
{
24+
Clipboard.SetText(dartTextBox.Text);
25+
}
26+
catch { }
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)