1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection sourceProps;
if (dataSource == null)
sourceProps = PropertyDescriptorCollection.Empty;
object obj1 = ListBindingHelper.GetList(this.dataSource);
sourceProps = ListBindingHelper<T>.GetListItemProperties(obj1, listAccessors);
var cust = new CustomTypePropertyDescriptor<T>(this, GetType(), dataMember, typeof(string));
PropertyDescriptor[] props = new PropertyDescriptor[sourceProps.Count];
for (int i = 0; i < sourceProps.Count; i++)
{
if(sourceProps[i].Name == dataMember)
props[i] = cust;
else
props[i] = sourceProps[i];
}
return new PropertyDescriptorCollection(props);
}
private class CustomTypePropertyDescriptor<T> : PropertyDescriptor
{
public CustomTypePropertyDescriptor(LanguageBindingSource<T> owner, Type componentType, string propertyName, Type propertyType)
: base(propertyName, null)
{
this.propertyType = propertyType;
this.componentType = componentType;
this.owner = owner;
}
private Type propertyType;
private Type componentType;
private LanguageBindingSource<T> owner;
public override object GetValue(object component)
{
return ((IDictionary<Iso, string>)typeof(T).GetProperty(owner.DataMember).GetValue(component, null))[owner.Lang];
}
protected override Attribute[] AttributeArray
{
get { return null; }
set { }
}
public override Type ComponentType
{
get { return componentType; }
}
public override bool IsReadOnly
{
get { return true; }
}
public override Type PropertyType
{
get { return propertyType; }
}
public override bool CanResetValue(object component)
{
return false;
}
public override void ResetValue(object component)
{
}
public override void SetValue(object component, object value)
{
}
public override bool ShouldSerializeValue(object component)
{
return false;
}
} |
Partager