Last change
on this file since 17283 was
17280,
checked in by dpiringe, 5 years ago
|
#3026
- renamed CustomWriter to CustomJsonWriter and extracted it into a separate file
- removed property ParameterizedItems from Component
- added helper methods for path generation in Component
- reverted the single parameter array idea back to the FreeParameters and StaticParameters idea
- now there hidden parameters are also handled
|
File size:
1.2 KB
|
Line | |
---|
1 | using System.IO;
|
---|
2 | using Newtonsoft.Json;
|
---|
3 | using Newtonsoft.Json.Linq;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Manufacture {
|
---|
6 | internal class CustomJsonWriter : JsonTextWriter {
|
---|
7 | private bool isRangeArray = false;
|
---|
8 | public override void WriteStartArray() {
|
---|
9 |
|
---|
10 | if (isRangeArray) base.Formatting = Formatting.None;
|
---|
11 | base.WriteStartArray();
|
---|
12 | }
|
---|
13 |
|
---|
14 | public override void WritePropertyName(string name) {
|
---|
15 | base.Formatting = Formatting.Indented;
|
---|
16 | base.WritePropertyName(name);
|
---|
17 | isRangeArray = name == "Range" || name == "Default";
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override void WriteStartObject() {
|
---|
21 | base.Formatting = Formatting.Indented;
|
---|
22 | base.WriteStartObject();
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override void WriteEndObject() {
|
---|
26 | base.Formatting = Formatting.Indented;
|
---|
27 | base.WriteEndObject();
|
---|
28 | }
|
---|
29 |
|
---|
30 | public CustomJsonWriter(TextWriter writer) : base(writer) { }
|
---|
31 |
|
---|
32 | public static string Serialize(JToken token) {
|
---|
33 | JsonSerializer serializer = new JsonSerializer();
|
---|
34 | StringWriter sw = new StringWriter();
|
---|
35 | CustomJsonWriter writer = new CustomJsonWriter(sw);
|
---|
36 | writer.Formatting = Formatting.Indented;
|
---|
37 | serializer.Serialize(writer, token);
|
---|
38 | return sw.ToString();
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.