Exemple #1
0
        private void WriteValue(object value)
        {
            if (value == null)
            {
                return;
            }

            if (value is byte)
            {
                output.Write((byte)value);
            }
            else if (value is short)
            {
                output.Write((short)value);
            }
            else if (value is int)
            {
                output.Write((int)value);
            }
            else if (value is long)
            {
                output.Write((long)value);
            }
            else if (value is float)
            {
                output.Write((float)value);
            }
            else if (value is double)
            {
                output.Write((double)value);
            }
            else if (value is DateTime)
            {
                output.Write(UnixDateTime.ToUnixTimestamp((DateTime)value));
            }
            else if (value is String)
            {
                string s  = (string)value;
                int    sz = s.Length;
                output.Write(sz);
                for (int i = 0; i < sz; i++)
                {
                    output.Write(s[i]);
                }
            }
            else if (value is Array)
            {
                //TODO:
            }
            else if (value is PathStruct)
            {
                PathStruct pathStruct  = (PathStruct)value;
                string[]   memberNames = pathStruct.MemberNames;
                int        sz          = pathStruct.MemberCount;

                output.Write(sz);
                for (int i = 0; i < sz; i++)
                {
                    string memberName = memberNames[i];
                    WriteValue(memberName);
                    Write(pathStruct.GetValue(memberName));
                }
            }
            else
            {
                throw new ArgumentException("The value is not supported.");
            }
        }