This repository has been archived by the owner on Dec 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlSpec.cs
127 lines (110 loc) · 4.04 KB
/
XmlSpec.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Linq;
namespace LibAtem.XmlState.GenerateMacroOperation
{
public class FieldEntry : IEquatable<FieldEntry>
{
public FieldEntry(string name, string type)
{
Name = name;
Type = type;
}
public string Name { get; }
public string Type { get; }
public bool Equals(FieldEntry other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(Name, other.Name) && string.Equals(Type, other.Type);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((FieldEntry) obj);
}
public override int GetHashCode()
{
unchecked
{
return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Type != null ? Type.GetHashCode() : 0);
}
}
}
public class Field : IEquatable<Field>
{
public Field(string id, string name, string type, bool isEnum, bool enumAsString) :
this(id, new List<FieldEntry> { new FieldEntry(name, type)}, enumAsString, isEnum)
{
}
public Field(string id, IReadOnlyList<FieldEntry> entries, bool enumAsString, bool isEnum)
{
Id = id;
Entries = entries;
IsEnum = isEnum;
EnumAsString = enumAsString;
}
public string Id { get; }
public bool IsEnum { get; }
public IReadOnlyList<FieldEntry> Entries { get; }
public bool EnumAsString { get; }
public override string ToString()
{
return string.Format("{0}: {1}", Id, string.Join(", ", Entries.Select(e => e.Name + "-" + e.Type)));
}
public bool Equals(Field other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(Id, other.Id) && IsEnum == other.IsEnum && Entries.SequenceEqual(other.Entries) && EnumAsString == other.EnumAsString;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Field) obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (Id != null ? Id.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ IsEnum.GetHashCode();
hashCode = (hashCode * 397) ^ Entries.Sum(e => e.GetHashCode());
hashCode = (hashCode * 397) ^ EnumAsString.GetHashCode();
return hashCode;
}
}
}
public class Operation
{
public Operation(string id, string classname, IEnumerable<OperationField> fields, bool allowNoFields)
{
Id = id;
Classname = classname;
Fields = fields.ToList();
AllowNoFields = allowNoFields;
}
public string Id { get; }
public string Classname { get; }
public IReadOnlyList<OperationField> Fields { get; }
public bool AllowNoFields { get; }
}
public class OperationField
{
public string Id { get; }
public string FieldName { get; }
public string PropName { get; }
public string Type { get; }
public OperationField(string id, string fieldName, string propName, string type)
{
Id = id;
FieldName = fieldName;
PropName = propName;
Type = type;
}
}
}