런타임에 사용자 지정 속성을 정의 할 수 있도록 응용 프로그램에 ICustomTypeDescriptor를 구현했습니다.개체에 대한 ICustomTypeDescriptor 래퍼
public class DynamicClass <T> : ICustomTypeDescriptor
{
private readonly T _object;
public DynamicClass(T trackedObject)
{
_object = trackedObject;
}
// Collection to code add dynamic properties
public KeyedCollection<string, DynamicProperty> Properties
{
get;
private set;
}
// ICustomTypeDescriptor implementation
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(_object, true);
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(_object, true);
}
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(_object, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(_object, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(_object, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(_object, true);
}
public object GetEditor(Type editorBaseType)
{
throw new NotImplementedException();
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(_object, true);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(_object, attributes, true);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return TypeDescriptor.GetProperties(_object, true);
}
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return TypeDescriptor.GetProperties(_object, attributes, true);
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return _object;
}
}
문제는 내가 DynamicClass 바인더를 사용하여 텍스트 상자에 개체를 바인딩 할 때 지금은 더 이상 작동하지 않는다는 것입니다 :처럼 내 기본 구현 보인다.
나는 이런 식으로 그것을 사용 :
DynamicClass<ExtensionModel> binder = new DynamicClass<ExtensionModel>(ext);
_versionLabel.DataBindings.Add("Text", binder, "SelectedVersion", false, DataSourceUpdateMode.OnPropertyChanged);
나는 예외 있어요 '. 개체 대상 유형과 일치하지 않습니다'
에서 (BindingContext를 newBindingContext 바인딩 바인딩) System.Windows.Forms.BindingContext.UpdateBinding에서 ( 결합 제본)개체가 대상 유형과 일치하지 않습니다.
System.Reflection.RuntimeMethodInfo.Invoke에서 System.Reflection.RuntimeMethodInfo.CheckConsistency (개체 대상)에 에서 (오브젝트 OBJ, BindingFlags의 invokeAttr 바인더 바인더 [] 파라미터 CultureInfo를 배양 부울 skipVisibilityChecks 개체) System.Reflection.RuntimeMethodInfo.Invoke System.ComponentModel에서 (오브젝트 OBJ, BindingFlags의 invokeAttr 바인더 바인더 개체 [] 매개은 CultureInfo 배양)에서 System.ComponentModel.ReflectEventDescriptor.AddEventHandler
(개체 성분, 대표 값). ReflectPropertyDescriptor.AddValueChanged (Object componen t, System.Windows.Forms.ListManagerBindingsCollection.AddCore에서 System.Windows.Forms.Binding.SetListManager (BindingManagerBase bindingManagerBase에서 System.Windows.Forms.BindToObject.CheckBinding())에 핸들러 핸들러)() 바인딩 바인딩 System.Windows.Forms.BindingsCollection.Add에서 System.Windows.Forms.Control.UpdateBindings()
바인더 대신 바인더가 작동합니다. ext 개체를 사용합니다. ICustomTypeDescriptor 구현에서 뭔가를 놓쳤습니까?
SelectedVersion 속성은 무엇을 반환하며 DynamicClass 클래스 내에 있습니까? 이 문제를 해결할 수 있었습니까? – Martin