Example #1
0
        /// <summary>
        /// 输出多行_文化信息.
        /// </summary>
        /// <param name="iw">带缩进输出者.</param>
        /// <param name="obj">object. Can be null.</param>
        /// <param name="context">State Object. Can be null.</param>
        /// <returns>返回是否成功输出.</returns>
        public static bool outl_static_CultureInfo(IIndentedWriter iw, object obj, IndentedWriterContext context)
        {
            if (null == iw)
            {
                return(false);
            }
            Type tp = typeof(CultureInfo);

            if (!iw.Indent(tp))
            {
                return(false);
            }
            iw.WriteLine(string.Format("# <{0}>", tp.FullName));
            IndentedWriterMemberOptions options = IndentedWriterMemberOptions.AllowMethod | IndentedWriterMemberOptions.OnlyStatic;

            IndentedWriterUtil.ForEachMember(iw, null, tp, options, delegate(object sender, IndentedWriterMemberEventArgs e) {
                MethodInfo memberinfo = e.MemberInfo as MethodInfo;
                if (null != memberinfo)
                {
                    //if (!memberinfo.IsSpecialName) {
                    //    e.HasDefault = true;
                    //}
                    string name  = memberinfo.Name;
                    int cntparam = memberinfo.GetParameters().Length;
                    if (false)
                    {
                    }
#if (!NETFX_CORE)
                    else if (IndentedWriterUtil.StringComparer.Equals(name, "GetCultures"))
                    {
                        if (cntparam == 1)
                        {
                            e.IsCancel = true;
                            IndentedWriterUtil.WriteLineValue(iw, e.MemberName, e.Value, e.ValueOptions, e.AppendComment);
                            CultureInfo[] lst = null;
                            iw.Indent(null);
                            try {
                                object[] args = new object[1];
                                args[0]       = CultureTypes.AllCultures;
                                lst           = (CultureInfo[])memberinfo.Invoke(null, args);
                                // 显示短格式.
                                foreach (CultureInfo p in lst)
                                {
                                    int lcid = -1;
                                    iw.Write("{0}:\t", p.Name);
#if (!NETFX_PORTABLE)
                                    lcid = p.LCID;
#endif
                                    if (lcid != -1)
                                    {
                                        iw.Write("0x{0:X}", lcid);
                                    }
                                    iw.WriteLine("\t# {0}, {1}", p.EnglishName, p.NativeName);
                                }
                            }
                            catch {
                                // 忽略.
                            }
                            finally {
                                iw.Unindent();
                            }
                            // 显示详细.
                            if (ShowDetail)
                            {
                                IndentedWriterUtil.WriteLineValue(iw, e.MemberName, e.Value, e.ValueOptions, "Detail");
                                IndentedObjectFunctor.CommonProc(iw, lst, context);
                            }
                        }
                    }
#endif
                }
            }, context);
            iw.Unindent();
            return(true);
        }
Example #2
0
        /// <summary>
        /// 输出多行_主函数.
        /// </summary>
        /// <param name="iw">带缩进输出者.</param>
        /// <param name="obj">object. Can be null.</param>
        /// <param name="context">State Object. Can be null.</param>
        /// <returns>返回是否成功输出.</returns>
        public static bool outl_main(IIndentedWriter iw, object obj, IndentedWriterContext context)
        {
            if (null == iw)
            {
                return(false);
            }
            Assembly myAssembly;

#if (NETFX_CORE)
            Type     tp = typeof(MyInfo);
            TypeInfo ti = tp.GetTypeInfo();
            myAssembly = ti.Assembly;
#else
            myAssembly = Assembly.GetEntryAssembly();
#endif
            iw.WriteLine("# zinfoenvironment");
            // test.
            //iw.WriteLine("Hello!");
            //for (int i = 0; i < 3; ++i) {
            //    iw.WriteLine(i);
            //    iw.Indent();
            //}
            //iw.IndentLevel = 0;
            //IndentedWriterObjectLnProc lwo = outl_Version;
            //IndentedWriterObjectLnProc[] lwos = new IndentedWriterObjectLnProc[] { lwo };
            //IEnumerable<IndentedWriterObjectLnProc> lwoe = lwos;
            //foreach (IndentedWriterObjectLnProc p in lwoe) {
            //    p(iw, "");
            //}
            //lwo(iw, "");
            //lwo.Invoke(iw, "");
            //decimal? dec = new decimal(1);
            //IndentedWriterUtil.WriteLineValue(iw, "dec", dec, IndentedWriterValueOptions.Default);
            //IndentedObjectFunctor.CommonProc(iw, dec);
            //IndentedWriterUtil.WriteLineValue(iw, "enum", IndentedWriterValueOptions.ExistName, IndentedWriterValueOptions.Default, null);
            //IndentedWriterUtil.WriteLineValue(iw, "char", 'A', IndentedWriterValueOptions.Default, null);
            //IndentedWriterUtil.WriteLineValue(iw, "int", 255, IndentedWriterValueOptions.Default, null);
            //IndentedWriterUtil.WriteLineValue(iw, "string", Environment.NewLine, IndentedWriterValueOptions.Default, null);
            //IndentedWriterUtil.WriteLineValue(iw, "char(2)", '\t', IndentedWriterValueOptions.Default, null);
            //IndentedWriterUtil.WriteLineValue(iw, "string(2)", "\\\'\"", IndentedWriterValueOptions.Default, null);
            //iw.WriteLine(MemberInfoFormat.GetMemberName(typeof(KeyValuePair<int, object>), MemberNameOptions.All));
            //iw.WriteLine(MemberInfoFormat.GetMemberName(typeof(KeyValuePair<int, object>[]), MemberNameOptions.All));
            //iw.WriteLine(MemberInfoFormat.GetMemberName(typeof(List<KeyValuePair<int, object>>), MemberNameOptions.All));
            //IndentedObjectFunctor.CommonProc(iw, TypeUtil.GetEnumValues(typeof(Environment.SpecialFolder)) ,null);
            Dictionary <string, object> dict = new Dictionary <string, object>();
            dict.Add("a", "abc");
            dict.Add("b", "base");
            dict.Add("ver", myAssembly.GetName().Version);
            iw.WriteLine("Test Dictionary:");
            IndentedObjectFunctor.CommonProc(iw, dict, context);
            // show.
            iw.WriteLine("IntPtr:");
            outl_static_IntPtr(iw, null, context);
            iw.WriteLine("Environment:");
            //IndentedObjectFunctor.CommonProc(iw, Environment.OSVersion, context);
            outl_Environment(iw, null, context);
            //iw.WriteLine("Application Assembly:");
            //IndentedObjectFunctor.CommonProc(iw, myAssembly, context);
            iw.WriteLine("Application AssemblyName:");
            IndentedObjectFunctor.CommonProc(iw, myAssembly.GetName(), context);
            return(true);
        }