示例#1
0
        /// <summary>
        /// 引用另一个对象的设置属性。
        /// </summary>
        /// <param name="other"></param>
        public virtual void Reference(SerializeOption other)
        {
            NamingHandling = other.NamingHandling;
            Converters.AddRange(other.Converters);
            Indent = other.Indent;
            ReferenceLoopHandling = other.ReferenceLoopHandling;
            DateFormatHandling    = other.DateFormatHandling;
            DateTimeZoneHandling  = other.DateTimeZoneHandling;
            NullValueHandling     = other.NullValueHandling;

            if (other.InclusiveNames != null)
            {
                InclusiveNames = InclusiveNames == null ? other.InclusiveNames : InclusiveNames.Union(other.InclusiveNames).Distinct().ToArray();
            }

            if (other.ExclusiveNames != null)
            {
                ExclusiveNames = ExclusiveNames == null ? other.ExclusiveNames : ExclusiveNames.Union(other.ExclusiveNames).Distinct().ToArray();
            }

            if (other.InclusiveMembers != null)
            {
                if (InclusiveMembers != null)
                {
                    InclusiveMembers.AddRange(other.InclusiveMembers);
                }
                else
                {
                    InclusiveMembers = other.InclusiveMembers;
                }
            }

            if (other.ExclusiveMembers != null)
            {
                if (ExclusiveMembers != null)
                {
                    ExclusiveMembers.AddRange(other.ExclusiveMembers);
                }
                else
                {
                    ExclusiveMembers = other.ExclusiveMembers;
                }
            }
        }
示例#2
0
        /// <summary>
        /// 使用表达式指定在序列化 <typeparamref name="T"/> 时要排除序列化的成员列表。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expressions">一组 <see cref="MemberExpression"/> 表达式。</param>
        /// <returns></returns>
        public SerializeOption Exclude <T>(params Expression <Func <T, object> >[] expressions)
        {
            if (expressions != null && expressions.Length > 0)
            {
                var members = ResolveExpressions(expressions);
                if (!members.IsNullOrEmpty())
                {
                    if (ExclusiveMembers == null)
                    {
                        ExclusiveMembers = new List <MemberInfo>(members);
                    }
                    else
                    {
                        ExclusiveMembers.AddRange(members);
                    }
                }
            }

            return(this);
        }