Exemplo n.º 1
0
        /// <summary>
        /// 序列化对象为键值对
        /// </summary>
        /// <param name="name">对象名称</param>
        /// <param name="obj">对象实例</param>
        /// <param name="options">选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, string> > Serialize(string name, object obj, FormatOptions options)
        {
            if (string.IsNullOrEmpty(name) == true)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var setting = this.CreateSerializerSettings(options);

            this.Settings?.Invoke(setting);
            var serializer      = JsonSerializer.Create(setting);
            var keyValuesWriter = new KeyValuesWriter(name);

            serializer.Serialize(keyValuesWriter, obj);
            return(keyValuesWriter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 序列化对象为键值对
        /// </summary>
        /// <param name="name">对象名称</param>
        /// <param name="obj">对象实例</param>
        /// <param name="options">选项</param>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, string> > Serialize(string name, object obj, FormatOptions options)
        {
            if (obj == null)
            {
                return(Enumerable.Empty <KeyValuePair <string, string> >());
            }

            if (options == null)
            {
                options = new FormatOptions();
            }

            var setting         = this.CreateSerializerSettings(options);
            var serializer      = JsonSerializer.Create(setting);
            var keyValuesWriter = new KeyValuesWriter(name);

            serializer.Serialize(keyValuesWriter, obj);
            return(keyValuesWriter);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 调试视图
 /// </summary>
 /// <param name="target">查看的对象</param>
 public DebugView(KeyValuesWriter target)
 {
     this.target = target;
 }