コード例 #1
0
        /// <summary>
        /// 输出对象_输出成员.
        /// </summary>
        /// <param name="iw">带缩进输出者.</param>
        /// <param name="obj">object.</param>
        /// <param name="context">Context.</param>
        /// <param name="tp">类型.</param>
        /// <param name="showBaseName">是否显示基类类型的名称.</param>
        /// <param name="needtitle">是否需要输出标题.</param>
        public virtual void WriterObject_WriteMember(IIndentedWriter iw, object obj, IndentedWriterContext context, Type tp, bool showBaseName, ref bool needtitle)
        {
            bool needtitle2 = needtitle;

            try {
                IndentedWriterUtil.ForEachMember(iw, obj, tp, m_WriterOptions, delegate(object sender, IndentedWriterMemberEventArgs e) {
                    //Debug.WriteLine(string.Format("{0}: {1}", mi.Name, mi.MemberType));
                    if (needtitle2 && null != e && e.HasDefault)
                    {
                        // 仅当至少有一个成员, 才输出标题.
                        needtitle2 = false;
                        WriterObject_WriteTitle(iw, obj, context, tp, showBaseName);
                    }
                    // EnumerateNoSimple.
                    if (0 == (m_Options & IndentedObjectFunctorOptions.EnumerateNoSimple) && null != e.MemberInfo)
                    {
                        PropertyInfo pi = e.MemberInfo as PropertyInfo;
                        if (null != pi)
                        {
                            string name = pi.Name;
                            foreach (string s in EnumerateSimpleNames)
                            {
                                if (IndentedWriterUtil.StringComparer.Equals(s, name))
                                {
                                    e.IsCancel = true;
                                    break;
                                }
                            }
                        }
                    }
                    //
                    OnHandlerMember(this, e);
                }, context);
            }
            catch (Exception ex) {
                global::System.Diagnostics.Debug.WriteLine(ex);
            }
            needtitle = needtitle2;
        }
コード例 #2
0
 /// <summary>
 /// 输出类型的静态成员, 拥有选项参数.
 /// </summary>
 /// <param name="iw">带缩进输出者.</param>
 /// <param name="tp">type.</param>
 /// <param name="context">State Object. Can be null.</param>
 /// <param name="options">选项. 必须有 <see cref="IndentedWriterMemberOptions.OnlyStatic"/> 标志.</param>
 /// <returns>返回是否成功输出.</returns>
 /// <remarks>
 /// 当 <paramref name="options"/> 具有 <see cref="IndentedWriterMemberOptions.AllowMethod"/> 标志时,还会显示方法信息. 方法必须有返回值, 且没有泛型参数, 其他情况有:
 /// <para>参数数量为0个;</para>
 /// <para>参数数量为1个, 且参数类型为枚举或bool.</para>
 /// </remarks>
 public static bool WriteTypeStatic(IIndentedWriter iw, Type tp, IndentedWriterContext context, IndentedWriterMemberOptions options)
 {
     if (null == iw)
     {
         return(false);
     }
     if (null == tp)
     {
         return(false);
     }
     if (0 == (options & IndentedWriterMemberOptions.OnlyStatic))
     {
         return(false);
     }
     if (!iw.Indent(tp))
     {
         return(false);
     }
     iw.WriteLine(string.Format("# <{0}>", tp.FullName));
     //IndentedWriterUtil.ForEachMember(iw, null, tp, options, null, context);
     IndentedWriterUtil.ForEachMember(iw, null, tp, options, delegate(object sender, IndentedWriterMemberEventArgs e) {
         MethodInfo memberinfo = e.MemberInfo as MethodInfo;
         if (null != memberinfo)
         {
             //string name = memberinfo.Name;
             if (memberinfo.IsStatic &&
                 !memberinfo.IsSpecialName &&
                 null != memberinfo.ReturnType &&
                 !memberinfo.ReturnType.Equals(typeof(void)))
             {
                 ParameterInfo[] pis = memberinfo.GetParameters();
                 if (false)
                 {
                 }
                 else if (0 == pis.Length)
                 {
                     try {
                         e.Value = memberinfo.Invoke(null, null);
                         if (null == e.WriteProc)
                         {
                             e.WriteProc = IndentedObjectFunctor.CommonProc;
                         }
                         if (null == e.Value && null == e.AppendComment)
                         {
                             e.AppendComment = string.Format("<{0}>", memberinfo.ReturnType.Name);
                         }
                         e.HasDefault = true;
                     }
                     catch {
                         // 忽略.
                     }
                 }
                 else if (WriteSimpleMethod(iw, memberinfo, null, null, IndentedWriterValueOptions.Default, e.AppendComment))
                 {
                     e.IsCancel = true;
                 }
             }
         }
     }, context);
     iw.Unindent();
     return(true);
 }