protected void WriteValue(SubStream outstream, object data) { if (data == null) { outstream.WriteByte((byte)'.'); } else if (data is string) { outstream.WriteByte((byte)'s'); outstream.WriteString((string)data); } else if (data is float) { outstream.WriteByte((byte)'f'); outstream.WriteSingle((float)data); } else if (data is int) { outstream.WriteByte((byte)'i'); outstream.WriteInt32((int)data); } else if (data is byte[]) { outstream.WriteByte((byte)'R'); WriteRawBinary(outstream, (byte[])data); } else if (data is List <string> ) { outstream.WriteByte((byte)'S'); WriteStringList(outstream, (List <string>)data); } else if (data is List <float> ) { outstream.WriteByte((byte)'F'); WriteSingleList(outstream, (List <float>)data); } else if (data is List <int> ) { outstream.WriteByte((byte)'I'); WriteInt32List(outstream, (List <int>)data); } else if (data is IList) { outstream.WriteByte((byte)'M'); WriteList(outstream, (IList)data); } else if (data is IDictionary) { outstream.WriteByte((byte)'T'); WriteKeyValuePairs(outstream, (IDictionary)data); } else { throw new InvalidOperationException(String.Format("Unable to write value of type {0}", data.GetType().ToString())); } }
protected void WriteKeyValuePairs(SubStream outstream, IDictionary data) { foreach (DictionaryEntry de in data) { outstream.WriteString(de.Key.ToString()); WriteValue(outstream, de.Value); } outstream.WriteByte(0); }
protected void WriteValue(SubStream outstream, object data) { if (data == null) { outstream.WriteByte((byte)'.'); } else if (data is string) { outstream.WriteByte((byte)'s'); outstream.WriteString((string)data); } else if (data is float) { outstream.WriteByte((byte)'f'); outstream.WriteSingle((float)data); } else if (data is int) { outstream.WriteByte((byte)'i'); outstream.WriteInt32((int)data); } else if (data is byte[]) { outstream.WriteByte((byte)'R'); WriteRawBinary(outstream, (byte[])data); } else if (data is List<string>) { outstream.WriteByte((byte)'S'); WriteStringList(outstream, (List<string>)data); } else if (data is List<float>) { outstream.WriteByte((byte)'F'); WriteSingleList(outstream, (List<float>)data); } else if (data is List<int>) { outstream.WriteByte((byte)'I'); WriteInt32List(outstream, (List<int>)data); } else if (data is IList) { outstream.WriteByte((byte)'M'); WriteList(outstream, (IList)data); } else if (data is IDictionary) { outstream.WriteByte((byte)'T'); WriteKeyValuePairs(outstream, (IDictionary)data); } else { throw new InvalidOperationException(String.Format("Unable to write value of type {0}", data.GetType().ToString())); } }
protected void WriteKeyValuePairs(SubStream outstream, IDictionary data) { foreach (DictionaryEntry de in data) { outstream.WriteString(de.Key.ToString()); WriteValue(outstream, de.Value); } outstream.WriteByte(0); }