저는 기존 Window Forms 응용 프로그램이 있습니다. 응용 프로그램에는 속성 표가 있습니다. 속성의 값은 런타임에 사용자가 설정합니다. 내가 원하는 것은 주어진 속성의 현재 값을 코드에서 결정하는 것이다. 나는 부분적으로 성공했다. 카테고리와 속성 이름 정보를 얻을 수 있습니다. 나는 사용자가 설정 한 속성의 현재 값뿐만 아니라 두 가지 다른 관련 질문을 얻는데 어려움을 겪고있다. 속성 값 확인
// ICustomTypeDescriptor Interface Implementation
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(GetType());
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(GetType());
}
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(GetType());
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(GetType());
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(GetType());
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(GetType());
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(GetType(), editorBaseType);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(GetType(), attributes);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(GetType());
}
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
// ... This returns a list of properties.
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(GetType(), attributes);
PropertyDescriptor[] arr = new PropertyDescriptor[pdc.Count];
pdc.CopyTo(arr, 0);
PropertyDescriptorCollection propertyCollection = new PropertyDescriptorCollection(arr);
ModifyProperties(propertyCollection); // modifies which properties are visible
// temporary code to get the program to print out the properties
foreach (PropertyDescriptor pd in propertyCollection)
{
Print("input category = "+pd.Category);
Print("input display name = "+pd.DisplayName);
Print("input name = "+pd.Name);
// Print("input value = "+pd.GetValue(Input).ToString()); <--- Does NOT work
}
return propertyCollection;
}
public PropertyDescriptorCollection GetProperties()
{
return TypeDescriptor.GetProperties(GetType());
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
내 질문
은 다음과 같습니다 :내가 사용하고 코드는 다음과 같습니다
어떻게 속성 값을받을 수 있나요? 예를 들어 속성 가로 세로 비율이 있습니다. 표시 이름은 Aspect Ratio이고 이름은 aspectRatio입니다. 이 값은 5입니다. 런타임시 코드를 통해이를 어떻게 retieve 할 수 있습니까?
어떻게 주문할 수 있습니까? 위의 방법을 사용하여 속성을 주문하려고했지만 주문이 실패했습니다. 계속 진행하는 것이 최선인지 모르겠습니다.
모든 의견을 크게 기뻐할 것입니다. 고맙습니다.
기본 반사에서이 새로운 fangled 접근 방식에 빠져있을 수도 있지만 코드에 인스턴스가 없으므로 어떻게 될 수 있습니까? 가치? 당신은 객체의 PropertyDescriptionCollection을 원하지만 객체의 유형은 아닙니다. –