示例#1
0
        private static void SerializeScalar(object obj, FieldDescriptor fd, TextWriter textWriter, TranslationContext translationContext)
        {
            // check wether we need quotation marks to surround the value.
            bool       needQuotationMarks = true;
            ScalarType st = fd.ScalarType;

            if (st != null)
            {
                needQuotationMarks = st.NeedsJsonQuotationWrap();
            }

            textWriter.Write('"');
            textWriter.Write(fd.TagName);
            textWriter.Write('"');
            textWriter.Write(':');
            if (needQuotationMarks)
            {
                textWriter.Write('"');
            }
            fd.AppendValue(textWriter, obj, translationContext, Format.Json);
            if (needQuotationMarks)
            {
                textWriter.Write('"');
            }
        }