기본 클래스 (Node)와 상속 된 유형이 있습니다.조건부 속성
Class Node
{
Base_Attributes...
}
Class Derived : Node
{
Derived_Attributes...
}
이러한 유형은 프로젝트에 추가 한 DLL에 있습니다. 그리고 그 클래스의 속성 중 하나가 Node라는 클래스가 있습니다. mainform 어딘가에
Class Item
{
Point location;
String name;
Node quiddity;
bool[] IsBrowsable;
public Point Location{set;get;}
public String Name{set;get;}
public String NodeAttrib{set;get;}
[Browsable(IsBrowsable[thisindex])]
public String DerivedTypeAttribe{set;get;}
[Browsable(IsBrowsable[otheroneindex])]
public String DerivedTypeAttribe{set;get;}
Item(string type)
{
switch(type)
{
case"some":
Node = new derived_some();
IsBrowsable[thisindex] = true;
break;
}
}
}
과 : :이 같은 itme의 속성을 표시하는 내가 PropertyGrid가이
propertygrid.selectedobject = item;
문제는 여기에서 파생 된 형식에 지정된 일부 속성이있어 내가 그들을 표시해야 propetygrid하지만 런타임에 노드의 유형을 알 수 없습니다. 나는 부울 배열을 사용하여 Browsabl() 특성을 설정하려고 시도했지만 Browsable Parameter는 상수 값이어야한다고 판명되었습니다. 어떤 생각을 어떻게 할 수 있습니까?
전체적으로 들어갈 시간이 없지만 실제로이 작업을 수행 할 수는 있습니다. TypeConverter 또는 (더 복잡한) ICustomTypeDescriptior. 일반적으로 ExpandableTypeConverter를 상속하고 GetProperties를 재정의 (적절한 경우 필터링)하면 충분합니다. –
답변 해 주셔서 감사합니다. 이걸 어떻게 성취 할 수 있겠 니? – void