예제 #1
0
 public void WriteStringValue(String value)
 {
     AtValueBegin();
     _streamWriter.Write('"');
     _streamWriter.Write(JsonEncoder.Encode(value));
     _streamWriter.Write('"');
     AtValueEnd();
 }
예제 #2
0
        private void WirteEnumValue <T>(T value) where T : struct
        {
            AtValueBegin();
            UInt64 integer = EnumCache <T> .ToUInt64(value);

            _streamWriter.Write('"');
            _streamWriter.Write(JsonEncoder.Encode(value.ToString()));
            _streamWriter.Write('(');
            _streamWriter.Write(integer.ToString(CultureInfo.InvariantCulture));
            _streamWriter.Write(')');
            _streamWriter.Write('"');
            AtValueEnd();
        }
예제 #3
0
        public void WriteFlags <T>(String tag, T value) where T : struct
        {
            WriteTag(tag);
            BeginArrayValue();
            UInt64 flags = EnumCache <T> .ToUInt64(value);

            Boolean first = true;

            for (Int32 index = 0; index < EnumFlags <T> .Integers.Length; index++)
            {
                UInt64 flg = EnumFlags <T> .Integers[index];

                if ((flags & flg) == flg)
                {
                    flags &= ~flg;

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        _streamWriter.Write(", ");
                    }

                    _streamWriter.Write('"');
                    _streamWriter.Write(JsonEncoder.Encode(EnumFlags <T> .Names[index]));
                    _streamWriter.Write('(');
                    _streamWriter.Write(flg.ToString(CultureInfo.InvariantCulture));
                    _streamWriter.Write(')');
                    _streamWriter.Write('"');
                }
            }

            // Unexpected flags
            if (flags != 0)
            {
                if (!first)
                {
                    _streamWriter.Write(", ");
                }

                _streamWriter.Write('(');
                _streamWriter.Write(flags.ToString(CultureInfo.InvariantCulture));
                _streamWriter.Write(')');
            }

            EndArrayValue();
            _streamWriter.WriteLine();
        }