#c#
Вопрос:
Я хочу включить сведения о совместном владельце в профиль владельцев основных счетов.Здесь будет несколько совместных владельцев. Я использую класс «выбор акционеров», полученный из класса collectiobass, которому присвоены сведения о совместных владельцах. При выполнении приложения свойство возвращает только емкость и количество. это не называется дескриптором свойств, почему?
public class ShareholderCollection : CollectionBase, ICustomTypeDescriptor
{
public void Add( UiclsJointHolderSummary sh)
{
this.List.Add(sh);
}
public void Remove( UiclsJointHolderSummary sh)
{
this.List.Remove(sh);
}
public UiclsJointHolderSummary this[int index]
{
get{
return (UiclsJointHolderSummary)this.List[index];
}
set
{
base.List[index] = (UiclsJointHolderSummary)value;
}
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
public object GetEditor(System.Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
for (int i = 0; i < this.Count; i = i 1)
{
ShareholderCollectionPropertyDescriptor pd = new
` `ShareholderCollectionPropertyDescriptor( this,i);
pds.Add(pd);
}
return pds;
}
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return GetProperties(attributes);
}
public object GetPropertyOwner(PropertyDescriptor pd )
{
return this;
}
}
Класс дескриптора
public class ShareholderCollectionPropertyDescriptor : PropertyDescriptor
{
private ShareholderCollection collection;
private int index = 1;
public ShareholderCollectionPropertyDescriptor(ShareholderCollection _Coll,int _id) : base("#" _id.ToString(), null)
{
this.collection = _Coll;
this.index = _id;
}
public override AttributeCollection Attributes
{
get
{
// var attributes = TypeDescriptor.GetAttributes(GetValue(null), false);
return new AttributeCollection(null);
//return attributes;
}
}
public override bool CanResetValue(object component)
{
return true;
}
public override Type ComponentType
{
get => this.collection.GetType();
}
public override string DisplayName
{
get
{
UiclsJointHolderSummary sh = this.collection[index];
return "[" sh.NDX.ToString().Trim() "] " sh.INITIALS.ToString() " " sh.LASTNAME.ToString();
}
}
public override string Description
{
get
{
UiclsJointHolderSummary sh = this.collection[index];
StringBuilder sb = new StringBuilder();
sb.Append(sh.ADDRESS.ADDRESS1);
sb.Append(",");
sb.Append(sh.ADDRESS.ADDRESS2);
sb.Append(",");
sb.Append(sh.ADDRESS.ADDRESS3);
sb.Append(",");
sb.Append(sh.ADDRESS.CITY);
sb.Append(",");
sb.Append(sh.ADDRESS.PCODE);
return sb.ToString();
}
}
public override object GetValue(object component)
{
return this.collection[index];
}
public override bool IsReadOnly
{ get => false; }
//public override string Name
//{
// get { return "#" index.ToString(); }
//}
public override Type PropertyType
{
get => this.collection[index].GetType();
}
public override void ResetValue(object component)
{
throw new NotImplementedException();
}
public override void SetValue(object component, object value)
{
throw new NotImplementedException();
}
public override bool ShouldSerializeValue(object component)
{
return true;
}
//private static string GetDisplayName(ShareholderCollection ilst, int ind )
//{
// UiclsJointHolderSummary sh = ilst.Item(ind);
// return "[" sh.NDX.ToString().Trim() "] " sh.INITIALS.ToString() " " sh.LASTNAME.ToString();
// //return str=DisplayName;
//}
}
convertor class
public class ShareholderCollectionConverter: ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context , CultureInfo culture , Object pvalue , Type destType )
{
if ((destType == typeof(string) )amp;amp; (pvalue.GetType()==typeof( ShareholderCollection)))
{
return "Joint Shareholders";
}
return base.ConvertTo(context, culture, pvalue, destType);
}
}
property class
ShareholderCollection JointHolder= new ShareholderCollection ();
[TypeConverter(typeof(ShareholderCollectionConverter))]
[Category("23. Joint Members")]
[DisplayName("10. Shareholders")]
[Browsable(true)]
[ReadOnly(true)]
public ShareholderCollection JointHolders
{
get
{
return JointHolder;
}
set { JointHolder = value; }
}
значения свойств, назначенные во время выполнения
clsJoinShareholderCollSub objJointShareholderCollSub = new clsJoinShareholderCollSub();
ShareholderCollection sb = objJointShareholderCollSub.getJointHolders(objUIclsFolio);
objUIclsFolio.JointHolders = sb;
pgGeneralFrmFolio.SelectedObject = objUIclsFolio;
pgGeneralFrmFolio.Refresh();