[Mono-bugs] [Bug 664838] New: CurencyManager and PropertyManager GetItemProperties() method doesn't honor ITypedList.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Jan 16 18:07:48 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=664838

https://bugzilla.novell.com/show_bug.cgi?id=664838#c0


           Summary: CurencyManager and PropertyManager GetItemProperties()
                    method doesn't honor ITypedList.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: x86
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

CurencyManager and PropertyManager GetItemProperties() method don't return
properties correctly, for example ITypedList honored which can be very useful
when customising properties.

Calling through to ListBindingHelper.GetListItemProperties would be helpful.


Reproducible: Always

Steps to Reproduce:
[Test]
public void Test_BindingManagers_GetItemProperties()
{
    TypedList<TestDataSourceWithRelatedObjects> list = new
TypedList<TestDataSourceWithRelatedObjects>();
    TestDataSourceWithRelatedObjects item = list.AddNew();
    item.List = new BindingList<TestDataSource>();

    BindingContext bc = new BindingContext();
    AssertPropertyDescriptorCollectionObjType(bc, list, "",
typeof(TestDataSourceWithRelatedObjects));
    AssertPropertyDescriptorCollectionObjType(bc, list, "ObjProperty",
typeof(TestDataSource));
    AssertPropertyDescriptorCollectionObjType(bc, list, "List",
typeof(TestDataSource));
}

static void AssertPropertyDescriptorCollectionObjType(
    BindingContext bc,
    object dataSource,
    string dataMember,
    Type objType)
{
    var bm = bc[dataSource, dataMember];
    MyPropertyDescriptorCollection properties = bm.GetItemProperties() as
MyPropertyDescriptorCollection;
    if (properties == null)
    {
        throw new InvalidOperationException("GetItemProperties did not return a
custom PropertyDescriptorCollection");
    }
    AssertEquals(
        objType, properties.ObjType,
        "PropertyDescriptorCollection for " + objType + " returned for
DataSource=" + ListUtil.GetListElementType(dataSource.GetType()).Name + "
DataMember=" + dataMember);
}

class TypedList<T> : BindingList<T>, ITypedList
{
    public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[]
listAccessors)
    {
        return new MyPropertyDescriptorCollection(
            listAccessors == null
            ? typeof(T)
            : GetListElementType(listAccessors[listAccessors.Length -
1].PropertyType));
    }

    Type GetListElementType(Type type)
    {
        return typeof(IEnumerable).IsAssignableFrom(type) ?
ListUtil.GetListElementType(type) : type;
    }

    public string GetListName(PropertyDescriptor[] listAccessors)
    {
        return null;
    }
}

class MyPropertyDescriptorCollection : PropertyDescriptorCollection
{
    public MyPropertyDescriptorCollection(Type objType)
        : base(null)
    {
        if (objType == null)
        {
            throw new ArgumentNullException("objType");
        }
        ObjType = objType;
        foreach (PropertyDescriptor property in
TypeDescriptor.GetProperties(objType))
        {
            Add(property);
        }
    }

    public Type ObjType { get; private set; }
}

class TestDataSourceWithRelatedObjects
{
    public event EventHandler ObjPropertyChanged;

    TestDataSource objProperty;
    public TestDataSource ObjProperty
    {
        get { return objProperty; }
        set
        {
            objProperty = value;
            if (ObjPropertyChanged != null)
            {
                ObjPropertyChanged(this, EventArgs.Empty);
            }
        }
    }

    public BindingList<TestDataSource> List { get; set; }
}

class TestDataSource
{
}

Actual Results:  
The unit test fails.

Expected Results:  
The unit test should pass, as it does with ms.net.

These changes fix the issue and cause the above test to pass:

CurrencyManager.GetItemProperties changed to:
    public override PropertyDescriptorCollection GetItemProperties()
    {
        return GetItemProperties(null, null);
    }

    protected internal override PropertyDescriptorCollection
GetItemProperties(ArrayList dataSources, ArrayList propertyAccessors)
    {
        return ListBindingHelper.GetListItemProperties(
            list,
            propertyAccessors == null ? null :
(PropertyDescriptor[])propertyAccessors.ToArray(typeof(PropertyDescriptor)));
    }

PropertyManager.GetItemProperties changed to:
    public override PropertyDescriptorCollection GetItemProperties()
    {
        return GetItemProperties(null, null);
    }

    protected internal override PropertyDescriptorCollection
GetItemProperties(ArrayList dataSources, ArrayList listAccessors)
    {
        return ListBindingHelper.GetListItemProperties(
            data_source,
            listAccessors == null ? null :
(PropertyDescriptor[])listAccessors.ToArray(typeof(PropertyDescriptor)));
    }

RelatedCurrencyManager.GetItemProperties added:
    public override PropertyDescriptorCollection GetItemProperties()
    {
        return GetItemProperties(null, null);
    }

    protected internal override PropertyDescriptorCollection
GetItemProperties(ArrayList dataSources, ArrayList listAccessors)
    {
        if (prop_desc == null) return new PropertyDescriptorCollection(null);

        ArrayList list = new ArrayList(1);
        list.Add(prop_desc);
        if (listAccessors != null && listAccessors.Count > 0)
        {
            list.AddRange(listAccessors);
        }
        return parent.GetItemProperties(null, list);
    }

RelatedPropertyManager.GetItemProperties changed to:
    public override PropertyDescriptorCollection GetItemProperties()
    {
        return GetItemProperties(null, null);
    }

    protected internal override PropertyDescriptorCollection
GetItemProperties(ArrayList dataSources, ArrayList listAccessors)
    {
        if (prop_desc == null) return new PropertyDescriptorCollection(null);

        ArrayList list = new ArrayList(1);
        list.Add(prop_desc);
        if (listAccessors != null && listAccessors.Count > 0)
        {
            list.AddRange(listAccessors);
        }
        return parent.GetItemProperties(null, list);
    }

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list