Share via


레이어 다이어그램에 사용자 지정 속성 추가

Visual Studio Ultimate 에서 레이어 다이어그램의 확장 코드를 작성할 때, 레이어 다이어그램의 모든 요소를 사용하여 값을 저장할 수 있습니다. 값은 다이어그램 저장되고 다시 열릴때 유지 됩니다. 또한 사용자가 보고 편집할 수 있도록 이러한 속성을 속성 창에 표시할 수 있습니다. 예를 들어, 사용자가 각 계층에서 클래스의 이름을 사용자가 지정한 패턴을 따르는지 확인 하기 위해 유효성 검사 코드를 작성하고 각 계층에 대해 정규식을 지정할 수 있습니다.

사용자에게 표시되지 않는 속성

레이어 다이어그램에 있는 모든 요소에 값을 연결 하기 위한 코드를 원한다면 MEF 구성 요소를 정의할 필요가 없습니다. ILayerElement 에서 Properties 라는 사전이 있습니다. 레이어 요소 사전에 마샬링할 수 값을 추가 하면 됩니다. 레이어 다이어그램의 일부로 저장 됩니다. 자세한 내용은 프로그램 코드에서 레이어 모델 탐색 및 업데이트을 참조하십시오.

사용자가 편집할 수 있는 속성

초기 준비

중요

속성을 표시 하려면 레이어 속성을 표시 하려는 각 컴퓨터에서 다음과 같이 변경을 해야 합니다.

  1. 메모장을 관리자 권한으로 실행 으로 실행합니다.%ProgramFiles%\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Architecture Tools\ExtensibilityRuntime\extension.vsixmanifest를 엽니다.

  2. Content 요소 내부에 다음을 추가합니다:

    <MefComponent>Microsoft.VisualStudio.ArchitectureTools.Extensibility.Layer.Provider.dll</MefComponent>
  3. Windows 시작 메뉴의 Microsoft Visual Studio 2012, Visual Studio 도구 에서 개발자 명령 프롬프트 를 엽니다.

    Enter

    devenv /rootSuffix /updateConfiguration

    devenv /rootSuffix Exp /updateConfiguration

  4. Visual Studio를 다시 시작합니다.

코드가 VSIX 프로젝트에 있는지 확인합니다

명령, 제스처 또는 유효성 검사 프로젝트 속성을 사용하는 경우 아무 것도 추가할 필요가 없습니다. MEF 구성 요소로 정의 된 Visual Studio 확장성 프로젝트에서 사용자 지정 속성에 대한 코드를 정의 합니다. 자세한 내용은 레이어 다이어그램에 명령 및 제스처 추가 또는 레이어 다이어그램에 사용자 지정 아키텍처 유효성 검사 추가를 참조하십시오.

사용자 지정 속성 정의

사용자 지정 속성을 만들려면 다음과 같이 클래스를 정의 합니다.

[Export(typeof(IPropertyExtension))]
public class MyProperty 
      : PropertyExtension<ILayerElement>
{
  // Implement the interface.
}

ILayerElement 또는 해당 파생된 클래스에서 속성을 정의할 수 있습니다. 여기서 말하는 클래스는 다음을 포함합니다:

  • ILayerModel - 모델

  • ILayer - 각 레이어

  • ILayerDependencyLink - 레이어 간의 링크

  • ILayerComment

  • ILayerCommentLink

사용자 지정 속성을 보려면

중요

사용자 지정 속성은 모델링 프로젝트를 로드하기 전에 아키텍처 탐색기가 열려 있는 경우에 표시 됩니다.아키텍처 탐색기를 연 다음 사용자 지정 속성을 보기 위해 Visual Studio를 중지 및 재시작 합니다.아키텍처 메뉴에서 을 선택한 다음 아키텍처 탐색기를 클릭합니다.

사용자 지정 속성을 테스트 하려면 F5 키를 눌러 Visual Studio의 실험적 인스턴스를 시작 합니다. 적절 한 레이어 요소의 예를 만들고, 이것을 선택 합니다. 속성 창에서 사용자 지정 속성을 볼 수 있습니다.

예제

다음 코드는 일반적인 사용자 지정 속성 설명자입니다. 이 코드에서는 사용자가 사용자 지정 유효성 검사 메서드에 값을 제공할 수 있도록 하는 레이어 모델의 부울 속성(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;
      }
    }
  }
}

참고 항목

개념

레이어 다이어그램 확장