레이어 다이어그램에 사용자 지정 속성 추가
이 Visual Studio 2010 Feature Pack을 사용하면 Visual Studio 2010 Ultimate에서 레이어 다이어그램에 있는 요소의 사용자 지정 속성을 정의할 수 있습니다. 사용자가 보고 편집할 수 있도록 이러한 속성을 속성 창에 표시할 수 있습니다. 자세한 내용은 Visual Studio 기능 팩을 참조하십시오.
레이어 요소(ILayerElement)에는 Name, Description 등의 몇 가지 표준 속성이 있습니다. 이러한 속성은 사용자가 속성 창에서 편집할 수 있으며 프로그램 코드에서 읽고 업데이트할 수도 있습니다.
레이어 요소와 연결될 수 있는 속성을 직접 정의할 수 있습니다. 이렇게 하는 가장 간단한 방법은 모든 ILayerElement에 연결된 Properties 사전에 값을 추가하는 것입니다. 이 방법은 사용자 고유의 프로그램 코드에서만 속성을 사용하려는 경우 충분할 수 있습니다.
그러나 사용자 지정 속성을 정의하여 속성 창에서 추가 값을 사용자에게 표시할 수 있습니다. 사용자 지정 속성 설명자는 PropertyExtension<T>에서 상속하는 클래스입니다. 여기서 T는 ILayerElement이거나 파생 클래스 중 하나입니다. T는 속성이 정의되는 형식입니다.
예를 들어 다음 형식에 대한 속성을 정의할 수 있습니다.
ILayerModel - 모델
ILayer - 각 레이어
ILayerDependencyLink - 레이어 간의 링크
ILayerComment
ILayerCommentLink
참고
ILayerElement와 함께 문자열을 저장하기 위한 보다 간단한 메커니즘도 있습니다. 각 요소에 연결된 Properties 사전에 값을 삽입할 수 있습니다. 이 방법은 사용자가 직접 편집할 수 없도록 하려는 데이터에 유용합니다. 자세한 내용은 프로그램 코드에서 레이어 모델 탐색 및 업데이트를 참조하십시오.
예제
다음 코드는 일반적인 사용자 지정 속성 설명자입니다. 이 코드에서는 사용자가 사용자 지정 유효성 검사 메서드에 값을 제공할 수 있도록 하는 레이어 모델의 부울 속성(ILayerModel)을 정의합니다.
using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ArchitectureTools.Extensibility.Layer;
namespace MyNamespace
{
/// <summary>
/// Custom properties are added to the Layer Designer via a custom
/// Property Descriptor. We have to export this Property Descriptor
/// using MEF to make it available in the Layer Designer.
/// </summary>
[Export(typeof(IPropertyExtension))]
public class AllTypesMustBeReferencedProperty
: PropertyExtension<ILayerModel>
{
/// <summary>
/// Each custom property must have a unique name.
/// Usually we use the full name of this class.
/// </summary>
public static readonly string FullName =
typeof(AllTypesMustBeReferencedProperty).FullName;
/// <summary>
/// Construct the property. Notice the use of FullName.
/// </summary>
public AllTypesMustBeReferencedProperty()
: base(FullName)
{ }
/// <summary>
/// The display name is shown in the Properties window.
/// We therefore use a localizable resource.
/// </summary>
public override string DisplayName
{
get { return Strings.AllTypesMustBeReferencedDisplayName; }
}
/// <summary>
/// Description shown at the bottom of the Properties window.
/// We use a resource string for easier localization.
/// </summary>
public override string Description
{
get { return Strings.AllTypesMustBeReferencedDescription; }
}
/// <summary>
/// This is called to set a new value for this property. We must
/// throw an exception if the value is invalid.
/// </summary>
/// <param name="component">The target ILayerElement</param>
/// <param name="value">The new value</param>
public override void SetValue(object component, object value)
{
ValidateValue(value);
base.SetValue(component, value);
}
/// <summary>
/// Helper to validate the value.
/// </summary>
/// <param name="value">The value to validate</param>
private static void ValidateValue(object value)
{ }
public override Type PropertyType
{ get { return typeof(bool); } }
/// <summary>
/// The segment label of the properties window.
/// </summary>
public override string Category
{
get
{
return Strings.AllTypesMustBeReferencedCategory;
}
}
}
}