-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (63 loc) · 2.84 KB
/
Copy pathProgram.cs
File metadata and controls
87 lines (63 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RazorPageGenerator;
public class Program
{
private static async Task Main(string[] args)
{
/* var catClientService = new CatClientService();
var cats = await catClientService.GetAll("https://api.thecatapi.com/v1/images/search");
*/
//https://api.thecatapi.com/v1/images/search
/* string endPoint = args[0];
string ns = args[1];
string typeName = args[2];
*/
string endPoint = "https://api.thecatapi.com/v1/images/search";
string ns = "Cat.Web.Models";
string typeName = "Cat";
HttpClientHelper clientHelper = new HttpClientHelper();
string jsonString = await clientHelper.GetJson(endPoint);
JArray jArray = JArray.Parse(jsonString);
JObject jsonObject = jArray.Children<JObject>().First();
//JObject.Parse
string savePath = Path.Combine(Constants.TargetFolder, "RazorPageGenerator");
using (StreamWriter streamWriter = new StreamWriter(Path.Combine(savePath, $"{typeName}.cs")))
{
streamWriter.WriteLine($"using System;");
streamWriter.WriteLine($"using System.Linq;");
streamWriter.WriteLine();
streamWriter.WriteLine($"namespace {ns};");
streamWriter.WriteLine();
streamWriter.WriteLine($"public class {typeName}");
streamWriter.WriteLine("{");
var propertyBuilder = new PropertyBuilder();
foreach (var property in jsonObject.Properties())
{
var prop = propertyBuilder.GetProperty(property);
streamWriter.WriteLine(prop);
}
streamWriter.WriteLine("}"); ;
}
using (StreamWriter streamWriter = new StreamWriter(Path.Combine(savePath, $"{typeName}ClientService.cs")))
{
streamWriter.WriteLine($"using System;");
streamWriter.WriteLine($"using System.Linq;");
streamWriter.WriteLine($"using {ns}.Services;");
streamWriter.WriteLine();
streamWriter.WriteLine($"namespace {ns};");
streamWriter.WriteLine();
streamWriter.WriteLine($"public class {typeName}ClientService : ClientService<{typeName}>");
streamWriter.WriteLine("{");
streamWriter.WriteLine("}"); ;
}
// http of from file get
// FileReadHelper fileReadHelper = new FileReadHelper();
// await fileReadHelper.GetResponse("Pizza", "/Users/bnd/Desktop/build-in-public/RazorPageGenerator/Pizza.json");
Console.Read();
// json deserialize - jobject
// typeof value --> type
// property name : type --> class
// aspnet-code-generator
}
}