Exemple #1
0
        public static void PrintClass(Type tp, Action <List <String> > printer)
        {
            List <String> all      = new List <String>();
            Type          baseType = tp.BaseType;
            String        bases    = "";

            if (baseType != null)
            {
                bases = baseType.Name;
            }
            all.Add(String.Format("{0} ({1}) : {2}", tp.Name, tp.Namespace, bases));
            all.Add("");
            if (printer == null)
            {
                string pth = String.Format("C:\\Users\\N4TH\\Desktop\\CSclasses\\{0}_{1}.txt", tp.Name, tp.Namespace);
                printer = (lines) => System.IO.File.WriteAllLines(@pth, lines);
            }
            FieldInfo[] fields = tp.GetFields();
            if (fields.Length > 0)
            {
                //all.Add("--- fields");
                foreach (FieldInfo field in fields)
                {
                    all.Add(field.ToString());                            //printer(field.ToString());
                }
            }
            MethodInfo[] methods = tp.GetMethods();
            if (methods.Length > 0)
            {
                //all.Add("--- methods");
                foreach (MethodInfo method in methods)
                {
                    all.Add(MethodInfoExtensions.GetSignature(method));                               //all.Add(method.ToString()); // printer(method.ToString());
                }
            }
            printer(all);
        }
Exemple #2
0
        public static void Hierarchy(Type tp, Action <List <String> > printer)
        {
            // Dictionary<Type,Tuple<List<FieldInfo>,List<MethodInfo>>> levels = new Dictionary<Type, Tuple<List<FieldInfo>, List<MethodInfo>>>();
            Boolean disag = true;

            List <String> all  = new List <String>();
            Type          next = tp;

            while (next != null)
            {
                if (disag)
                {
                    all = new List <String>();
                }
                Type   baseType = next.BaseType;
                String bases    = "";
                if (baseType != null)
                {
                    bases = baseType.Name;
                }
                all.Add("");
                all.Add(String.Format("=== {0} ({1}) : {2}", next.Name, next.Namespace, bases));
                // var flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
                var flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;

                foreach (FieldInfo field in next.GetFields(flags))
                {
                    all.Add(field.ToString());
                }
                all.Add("");
                foreach (MethodInfo method in next.GetMethods(flags))
                {
                    all.Add(MethodInfoExtensions.GetSignature(method));
                }
                all.Add("");

                if (disag)
                {
                    if (printer == null)
                    {
                        string pth = String.Format("C:\\Users\\N4TH\\Desktop\\CSclasses\\{0}_{1}.txt", next.Name, next.Namespace);
                        // printer = (lines) => System.IO.File.WriteAllLines(@pth, lines);
                        System.IO.File.WriteAllLines(@pth, all);
                    }
                    else
                    {
                        printer(all);
                    }
                }

                next = next.BaseType;
            }
            if (!disag)
            {
                if (printer == null)
                {
                    string pth = String.Format("C:\\Users\\N4TH\\Desktop\\CSclasses\\{0}_{1}.txt", tp.Name, tp.Namespace);
                    printer = (lines) => System.IO.File.WriteAllLines(@pth, lines);
                }
                printer(all);
            }
        }