forked from Inumedia/SlackAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavascriptBotsToArray.cs
63 lines (53 loc) · 1.95 KB
/
JavascriptBotsToArray.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlackAPI
{
public class JavascriptBotsToArray : Newtonsoft.Json.JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
List<Bot> bots = new List<Bot>();
int d = reader.Depth;
while (reader.Read() && reader.Depth > d)
{
Bot current = new Bot();
int depth = reader.Depth;
current.name = reader.Value.ToString();
reader.Read();
while (reader.Read() && reader.Depth > depth)
{
if (reader.Value == null) break;
switch (reader.Value.ToString())
{
case "image_48":
reader.Read();
current.image_48 = reader.Value.ToString();
break;
case "image_64":
reader.Read();
current.image_48 = reader.Value.ToString();
break;
case "emoji":
reader.Read();
current.emoji = reader.Value.ToString();
break;
}
}
bots.Add(current);
}
return bots.ToArray();
}
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
{
//Not sure if this is correct :D
throw new NotSupportedException("Too hackish for this shi.");
}
}
}