Esempio n. 1
0
        private void MainLogic()
        {
            //highlightBrush = new SolidColorBrush(new UISettings().UIElementColor(UIElementType.Highlight));
            highlightBrush = new SolidColorBrush(SystemColors.HighlightColor);

            // DependencyObjectを継承しているすべてのクラスを追加
            // WPFではDependencyObjectのみでは取得できない
            AddToClassList(typeof(System.Windows.DependencyObject));
            AddToClassList(typeof(System.Windows.UIElement));
            AddToClassList(typeof(System.Windows.Window));

            // それらを名前のアルファベット順にソート
            classes.Sort((t1, t2) =>
            {
                return(String.Compare(t1.GetTypeInfo().Name, t2.GetTypeInfo().Name));
            });

            // ソート済みのクラスをすべてツリー構造に追加
            ClassAndSubclasses rootClass = new ClassAndSubclasses(rootType);

            AddToTree(rootClass, classes);

            // StackPanelに追加されたTextBlockを使ってツリーを表示
            Display(rootClass, 0);
        }
Esempio n. 2
0
        private void Display(ClassAndSubclasses parentClass, int indent)
        {
            TypeInfo typeInfo = parentClass.Type.GetTypeInfo();

            // TextBlockを作成し、型の名前を設定
            TextBlock txtblk = new TextBlock();

            txtblk.Inlines.Add(new Run()
            {
                Text = new string(' ', 8 * indent)
            });
            txtblk.Inlines.Add(new Run()
            {
                Text = typeInfo.Name
            });

            // sealed(継承不可)クラスかどうかをチェック
            if (typeInfo.IsSealed)
            {
                txtblk.Inlines.Add(new Run()
                {
                    Text       = " (sealed)",
                    Foreground = highlightBrush
                });
            }

            // クラスがインスタンス化可能かどうかをチェック
            IEnumerable <ConstructorInfo> constructorInfos = typeInfo.DeclaredConstructors;
            bool existsPublicConstructor = false;

            foreach (ConstructorInfo constructorInfo in constructorInfos)
            {
                if (constructorInfo.IsPublic)
                {
                    existsPublicConstructor = true;
                    break;
                }
            }

            if (existsPublicConstructor == false)
            {
                txtblk.Inlines.Add(new Run()
                {
                    Text       = " (non-instantiable)",
                    Foreground = highlightBrush
                });
            }

            // StackPanelに追加
            stackPanel.Children.Add(txtblk);

            // このメソッドを全てのサブクラスで再帰的に呼び出す
            foreach (ClassAndSubclasses sublcass in parentClass.Subclasses)
            {
                Display(sublcass, indent + 1);
            }
        }
        void Display(ClassAndSubclasses parentClass, int indent)
        {
            TypeInfo typeInfo = parentClass.Type.GetTypeInfo();

            // Create TextBlock with type name
            TextBlock txtblk = new TextBlock();

            txtblk.Inlines.Add(new Run {
                Text = new string(' ', 8 * indent)
            });
            txtblk.Inlines.Add(new Run {
                Text = typeInfo.Name
            });

            // Indicate if the class is sealed
            if (typeInfo.IsSealed)
            {
                txtblk.Inlines.Add(new Run
                {
                    Text       = " (sealed)",
                    Foreground = highlightBrush
                });
            }

            // Indicate if the class can't be instantiated
            IEnumerable <ConstructorInfo> constructorInfos = typeInfo.DeclaredConstructors;
            int publicConstructorCount = 0;

            foreach (ConstructorInfo constructorInfo in constructorInfos)
            {
                if (constructorInfo.IsPublic)
                {
                    publicConstructorCount += 1;
                }
            }

            if (publicConstructorCount == 0)
            {
                txtblk.Inlines.Add(new Run
                {
                    Text       = " (non-instantiable)",
                    Foreground = highlightBrush
                });
            }

            // Add to the StackPanel
            stackPanel.Children.Add(txtblk);

            // Call this method recursively for all subclasses
            foreach (ClassAndSubclasses subclass in parentClass.Subclasses)
            {
                Display(subclass, indent + 1);
            }
        }
        void AddToTree(ClassAndSubclasses parentClass, List <Type> classes)
        {
            foreach (Type type in classes)
            {
                Type baseType = type.GetTypeInfo().BaseType;

                if (baseType == parentClass.Type)
                {
                    ClassAndSubclasses subClass = new ClassAndSubclasses(type);
                    parentClass.Subclasses.Add(subClass);
                    AddToTree(subClass, classes);
                }
            }
        }
        public MainPage()
        {
            this.InitializeComponent();
            highlightBrush = new SolidColorBrush(new UISettings().UIElementColor(UIElementType.Highlight));

            // Accumulate all the classes that derive from DependencyObject
            AddToClassList(typeof(Windows.UI.Xaml.DependencyObject));

            // Sort them alphabetically by name
            classes.Sort((t1, t2) =>
            {
                return(String.Compare(t1.GetTypeInfo().Name, t2.GetTypeInfo().Name));
            });

            // Put all these sorted classes into a tree structure
            ClassAndSubclasses rootClass = new ClassAndSubclasses(rootType);

            AddToTree(rootClass, classes);

            // Display the tree using TextBlock's added to StackPanel
            Display(rootClass, 0);
        }