Пример #1
0
        /// <summary>
        /// <para>在不进行序列化的情况下,获取对象被序列化后的二进制数据大小</para>
        /// <para>In the case of no serialization,Gets the size of the binary data after the object is serialized</para>
        /// </summary>
        /// <param name="context">序列化大小所需要的上下文. The context required for the serialization size</param>
        /// <param name="value">要获取序列化大小的值. The value to get the serialization size</param>
        /// <returns>对象被序列化后的数据大小. The size of the data after the object is serialized</returns>
        public static int Size <T>(ref BssomSizeContext context, T value)
        {
            if (context.Option == null)
            {
                context.Option = BssomSerializerOptions.Default;
            }

            return(context.Option.FormatterResolver.GetFormatterWithVerify <T>().Size(ref context, value));
        }
Пример #2
0
        /// <summary>
        /// <para>在不进行序列化的情况下,获取对象被序列化后的二进制数据大小</para>
        /// <para>In the case of no serialization,Gets the size of the binary data after the object is serialized</para>
        /// </summary>
        /// <param name="value">要获取序列化大小的值. The value to get the serialization size</param>
        /// <param name="option">使用的配置,如果为<c>null</c>,则使用默认配置. The options. Use <c>null</c> to use default options</param>
        /// <returns>对象被序列化后的数据大小. The size of the data after the object is serialized</returns>
        public static int Size <T>(T value, BssomSerializerOptions option = null)
        {
            if (option == null)
            {
                option = BssomSerializerOptions.Default;
            }

            BssomSizeContext sizeContext = new BssomSizeContext(option);

            return(option.FormatterResolver.GetFormatterWithVerify <T>().Size(ref sizeContext, value));
        }