forked from hippiehunter/SnooSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThing.cs
More file actions
76 lines (69 loc) · 1.56 KB
/
Copy pathThing.cs
File metadata and controls
76 lines (69 loc) · 1.56 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
using SnooSharp.Converters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace SnooSharp
{
public interface IThingData
{
}
[DataContract]
public class ThingData : IThingData
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
[DataContract]
[JsonConverter(typeof(ThingDataConverter))]
public class Thing
{
[JsonProperty("kind")]
public string Kind { get; set; }
[JsonProperty("data")]
public IThingData Data { get; set; }
}
[DataContract]
[JsonConverter(typeof(TypedThingDataConverter))]
public class TypedThing<T> : Thing where T : class ,IThingData
{
public TypedThing(Thing thing)
{
if (thing == null || !(thing.Data is T))
throw new ArgumentException("thing null or incorrect data type");
Kind = thing.Kind;
base.Data = thing.Data;
}
[JsonProperty("data")]
public new T Data
{
get
{
return base.Data as T;
}
set
{
base.Data = value;
}
}
// XAML friendly data wrapper
public T TypedData
{
get
{
return Data;
}
}
//[JsonConstructor()]
public TypedThing(string kind, T data)
{
base.Kind = kind;
base.Data = data;
}
}
}