Esempio n. 1
0
        /// <summary>
        /// 序列化参数值为指定编码的Json
        /// </summary>
        /// <param name="context"></param>
        /// <param name="encoding">编码</param>
        /// <returns></returns>
        public static byte[] SerializeToJson(this ApiParameterContext context, Encoding encoding)
        {
            using var bufferWriter = new RecyclableBufferWriter <byte>();
            context.SerializeToJson(bufferWriter);

            if (Encoding.UTF8.Equals(encoding) == true)
            {
                return(bufferWriter.WrittenSpan.ToArray());
            }
            else
            {
                var utf8Json = bufferWriter.WrittenSegment;
                return(Encoding.Convert(Encoding.UTF8, encoding, utf8Json.Array, utf8Json.Offset, utf8Json.Count));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 序列化参数值为utf8编码的Json
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static byte[] SerializeToJson(this ApiParameterContext context)
 {
     return(context.SerializeToJson(Encoding.UTF8));
 }