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
public Collection<Property> Returns
{
get;
set;
}
public Property Error
{
get;
set;
}
Frederik Carlier
committed
/// <remarks>
/// This property is currently ignored.
/// </remarks>
Frederik Carlier
committed
public Collection<string> Handlers
{
get;
set;
}
public Collection<Property> Parameters
{
get;
set;
}
public bool async
{
get;
set;
}
public string Redirect
{
get;
set;
}
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.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();
}
Frederik Carlier
committed
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
146
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));
}