Newer
Older
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Linq;
Frederik Carlier
committed
namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
Frederik Carlier
committed
{
Frederik Carlier
committed
public Command()
{
this.Returns = new Collection<Property>();
this.Handlers = new Collection<string>();
this.Parameters = new Collection<Property>();
}
Frederik Carlier
committed
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
public Collection<Property> Returns
{
get;
set;
}
public Property Error
{
get;
set;
}
public Collection<string> Handlers
{
get;
set;
}
public Collection<Property> Parameters
{
get;
set;
}
public bool async
{
get;
set;
}
public string Redirect
{
get;
set;
}
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
public override bool Equals(object obj)
{
var other = obj as Command;
if (other == null)
{
return false;
}
bool equals = base.Equals(obj);
equals &= this.Returns.SequenceEqual(other.Returns);
equals &= Property.Equals(this.Error, other.Error);
equals &= this.Handlers.CollectionEqual(other.Handlers);
equals &= this.Parameters.SequenceEqual(other.Parameters);
return equals;
}
public override int GetHashCode()
{
unchecked
{
int hash = base.GetHashCode();
hash = hash * 23 + this.Redirect.GetHashCode();
if (this.Error != null)
{
hash = hash * 23 + this.Error.GetHashCode();
}
hash = hash * 23 + this.Handlers.GetCollectionHashCode();
hash = hash * 23 + this.Parameters.GetCollectionHashCode();
return hash;
}
}
public override string ToString()
{
StringBuilder name = new StringBuilder();
if (this.Returns.Count > 0)
{
name.Append("(");
bool isFirst = true;
foreach (var p in this.Returns)
{
if (isFirst)
{
isFirst = false;
}
else
{
name.Append(", ");
}
name.Append(p.TypeName);
name.Append(" ");
name.Append(p.Name);
}
name.Append(") ");
}
else
{
name.Append("void ");
}
name.Append(this.Name);
name.Append("(");
bool isFirstParam = true;
foreach (var p in this.Parameters)
{
if (isFirstParam)
{
isFirstParam = false;
}
else
{
name.Append(", ");
}
name.Append(p.TypeName);
name.Append(" ");
name.Append(p.Name);
}
name.Append(")");
return name.ToString();
}
public Property GetParameter(string name)
{
return this.Parameters.SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
}