-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTypedObject.cs
More file actions
164 lines (151 loc) · 4.25 KB
/
TypedObject.cs
File metadata and controls
164 lines (151 loc) · 4.25 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* A very basic RTMPS client
*
* @author Gabriel Van Eyck
*/
/////////////////////////////////////////////////////////////////////////////////
//
//Ported to C# by Ryan A. LaSarre
//
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PVPNetConnect
{
/// <summary>
/// The class that defines a TypedObject and packet object
/// </summary>
public class TypedObject : Dictionary<string, object>
{
/// <summary>
/// The type
/// </summary>
public string type;
/// <summary>
/// Initializes a new instance of the <see cref="TypedObject"/> class.
/// </summary>
public TypedObject()
{
this.type = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="TypedObject"/> class.
/// </summary>
/// <param name="type">The type.</param>
public TypedObject(string type)
{
this.type = type;
}
/// <summary>
/// Makes the array collection.
/// </summary>
/// <param name="data">The data.</param>
/// <returns></returns>
public static TypedObject MakeArrayCollection(object[] data)
{
TypedObject ret = new TypedObject("flex.messaging.io.ArrayCollection");
ret.Add("array", data);
return ret;
}
/// <summary>
/// Gets the TO.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public TypedObject GetTO(string key)
{
if(this[key] is TypedObject)
return (TypedObject)this[key];
return null;
}
/// <summary>
/// Gets the string.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public string GetString(string key)
{
return (string)this[key];
}
/// <summary>
/// Gets the int.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public int? GetInt(string key)
{
object val = this[key];
if (val == null)
return null;
else if (val is int)
return (int)val;
else
return Convert.ToInt32((double)val);
}
/// <summary>
/// Gets the double.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public double? GetDouble(string key)
{
object val = this[key];
if (val == null)
return null;
else if (val is double)
return (double)val;
else
return Convert.ToDouble((int)val);
}
/// <summary>
/// Gets the bool.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public bool GetBool(string key)
{
return (bool)this[key];
}
/// <summary>
/// Gets the array.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public object[] GetArray(string key)
{
if (this[key] is TypedObject && GetTO(key).type.Equals("flex.messaging.io.ArrayCollection"))
return (object[])GetTO(key)["array"];
else
return (object[])this[key];
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
if (type == null)
return base.ToString();
else if (type.Equals("flex.messaging.io.ArrayCollection"))
{
StringBuilder sb = new StringBuilder();
object[] data = (object[])this["array"];
sb.Append("ArrayCollection[");
for (int i = 0; i < data.Length; i++)
{
sb.Append(data[i]);
if (i < data.Length - 1)
sb.Append(", ");
}
sb.Append(']');
return sb.ToString();
}
else
return type + ":" + base.ToString();
}
}
}