다음을 통해 공유


어댑터 구성을 위한 사용자 지정 형식 변환기

사용자 지정 편집기처럼 사용자 지정 형식 변환기는 자식 중 하나의 System.ComponentModel.TypeConverter 클래스를 재정의합니다. 다음은 변환기가 유지할 값에 서식을 추가하지만 속성 페이지에 나타나지 않는 것을 보여 줍니다. ConvertFrom 메서드는 문자열 값 주위에 대괄호를 추가하고 ConvertTo 메서드는 대괄호를 제거합니다.

다음 코드는 사용자 지정 유형 변환기에 대한 클래스 정의입니다.

using System;  
using System.ComponentModel;  
  
namespace AdapterManagement.ComponentModel {  
  
   public class DesignerTypeConverter : StringConverter {  
  
      public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {  
         return (typeof(String) == destinationType) || base.CanConvertTo (context, destinationType);  
      }  
  
      public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {  
         if (typeof(String) == destinationType && value is String) {  
            return ((String)value).TrimStart('[').TrimEnd(']');  
         }  
         return base.ConvertTo (context, culture, value, destinationType);  
      }  
  
      public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {  
         return (typeof(String) == sourceType) || base.CanConvertFrom (context, sourceType);  
      }  
  
      public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {  
         if (value is String) {  
            return "["+(String)value+"]";  
         }  
         return base.ConvertFrom (context, culture, value);  
      }  
   }  
}  

참고 항목

사용자 지정 어댑터 구성 디자이너
어댑터 구성을 위한 사용자 지정 드롭다운 편집기
어댑터 구성을 위한 사용자 지정 모달 대화 상자 편집기
어댑터에 대한 고급 구성 요소