-
Notifications
You must be signed in to change notification settings - Fork 6
/
Models.Small.cs
81 lines (79 loc) · 2.39 KB
/
Models.Small.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Runtime.Serialization;
namespace JsonBenchmark.Models.Small
{
[DataContract]
public class Message : IEquatable<Message>
{
[DataMember(Order = 1)]
public string message { get; set; }
[DataMember(Order = 2)]
public int version { get; set; }
public override int GetHashCode() { return version; }
public override bool Equals(object obj) { return base.Equals(obj as Message); }
public bool Equals(Message other)
{
return other != null && other.message == this.message && other.version == this.version;
}
public static T Factory<T>(int i) where T : new()
{
dynamic instance = new T();
instance.message = "some message " + i;
instance.version = i;
return instance;
}
}
[DataContract]
public class Complex : IEquatable<Complex>
{
[DataMember(Order = 1)]
public decimal x { get; set; }
[DataMember(Order = 2)]
public float y { get; set; }
[DataMember(Order = 3)]
public long z { get; set; }
public override int GetHashCode() { return (int)z; }
public override bool Equals(object obj) { return Equals(obj as Complex); }
public bool Equals(Complex other)
{
return other != null && other.x == this.x && other.y == this.y && other.z == this.z;
}
public static T Factory<T>(int i) where T : new()
{
dynamic instance = new T();
instance.x = i / 1000m;
instance.y = -i / 1000f;
instance.z = i;
return instance;
}
}
[DataContract]
public class Post : IEquatable<Post>
{
private static DateTime NOW = DateTime.UtcNow;
[DataMember(Order = 2)]
public Guid ID { get; set; }
[DataMember(Order = 3)]
public string title { get; set; }
[DataMember(Order = 4)]
public bool active { get; set; }
[DataMember(Order = 5)]
public DateTime created { get; set; }
public override int GetHashCode() { return ID.GetHashCode(); }
public override bool Equals(object obj) { return Equals(obj as Post); }
public bool Equals(Post other)
{
return other != null && other.ID == this.ID && other.title == this.title
&& other.active == this.active && other.created == this.created;
}
public static T Factory<T>(int i) where T : new()
{
dynamic instance = new T();
instance.ID = Guid.NewGuid();
instance.title = "some title " + i;
instance.active = i % 2 == 0;
instance.created = NOW.AddMinutes(i).Date;
return instance;
}
}
}