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
그리드형(광고전용)
'C# > UWP' 카테고리의 다른 글
[C#/UWP] MessageDialog 클래스 사용하기 (비동기 취소하기) (0) | 2016.02.23 |
---|---|
[C#/UWP] MessageDialog 클래스 사용하기 (await 연산자 사용하기) (0) | 2016.02.20 |
[C#/UWP] MessageDialog 클래스 사용하기 (익명 대리자 사용) (0) | 2016.02.19 |
[C#/UWP] MessageDialog 클래스 사용하기 (0) | 2016.02.19 |
[C#/UWP] DisplayRequest 클래스 : 자동 디스플레이 끄기 방지하기 (0) | 2016.02.08 |
[C#/UWP] 알려진 색상 리스트 구하기 (0) | 2016.02.06 |
[C#/UWP] LinearGradientBrush 엘리먼트 : 무지개 색상 브러시 사용하기 (0) | 2016.01.23 |
[C#/UWP] Path 마크업에서 Geometry 구하기 (0) | 2016.01.23 |
[C#/UWP] HyperlinkButton 엘리먼트 : 앱 스토어 실행하기 (0) | 2016.01.22 |
[C#/UWP] WebView 클래스 : InvokeScript 메소드를 사용해 HTML 자바 스크립트 실행하기 (0) | 2016.01.22 |