첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

▶ 클래스 계층도 표시하기 예제

using System;
using System.Collections.Generic;

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

...

private StackPanel stackPanel;

...

List<Type> descendentTypeList = GetDescendentTypeList(typeof(DependencyObject)); // '자손 타입 리스트 구하기' 참조

ClassInfo rootClassInfo = new ClassInfo(typeof(DependencyObject));

BuildClassHierarchy(rootClassInfo, descendentTypeList); // '클래스 계층도 만들기' 참조

DisplayClassHierarchy(this.stackPanel, rootClassInfo, 0);

 

728x90

 

▶ 클래스 계층도 표시하기

using System;
using System.Collections.Generic;
using System.Reflection;

using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

...

this.highlightBrush = new SolidColorBrush(new UISettings().UIElementColor(UIElementType.Highlight));

...

#region 클래스 계층도 표시하기 - DisplayClassHierarchy(container, parentClassInfo, indent)

/// <summary>
/// 클래스 계층도 표시하기
/// </summary>
/// <param name="container">컨테이너</param>
/// <param name="parentClassInfo">부모 클래스 정보</param>
/// <param name="indent">들여쓰기</param>
public void DisplayClassHierarchy(StackPanel container, ClassInfo parentClassInfo, int indent)
{
    TypeInfo parentTypeInfo = parentClassInfo.Type.GetTypeInfo();

    TextBlock textBlock = new TextBlock();

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

    if(parentTypeInfo.IsSealed)
    {
        textBlock.Inlines.Add(new Run { Text = " (sealed)", Foreground = this.highlightBrush });
    }

    IEnumerable<ConstructorInfo> constructorInfoEnumerable = parentTypeInfo.DeclaredConstructors;

    int publicConstructorCount = 0;

    foreach(ConstructorInfo constructorInfo in constructorInfoEnumerable)
    {
        if(constructorInfo.IsPublic)
        {
            publicConstructorCount++;
        }
    }

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

    container.Children.Add(textBlock);

    foreach(ClassInfo childClassInfo in parentClassInfo.ChildClassInfoList)
    {
        DisplayClassHierarchy(container, childClassInfo, indent + 1);
    }
}

#endregion
728x90
그리드형(광고전용)
Posted by icodebroker
,