ObjectBinder - немного дополнительного функционал
От: albenik Россия  
Дата: 16.02.09 14:25
Оценка:
Приветствую!
Для счастья не хватает совсем немного:

1) ObjectBinder: Методов ResetBindings, ResetItem, ResetCurrentItem как в BindingSource.
2) ObjectBinder: Возможности забиндить в Designtime вложенный объект, а не только его свойства.

Первый пункт я решил для себя так (пока не очень дотумкал, получить индекс текущего элемента средсвами только ObjectBinder, но для меня это не очень актуально):
public class ObjectBinderEx : ObjectBinder
{
    public void ResetObject()
    {
        if (Object == null) return;
        var index = List.IndexOf(Object);
        if (index < 0) return;
        OnListChanged(ListChangedType.ItemChanged, index);
    }

    public void ResetItem(int index)
    {
        if (index < 0 || index >= List.Count) return;
        OnListChanged(ListChangedType.ItemChanged, index);
    }

    public void ResetList()
    {
        OnListChanged(ListChangedType.Reset, -1);
    }
}

По второму пункту докопался до TypeAccessor.GetExtendedProperties() и добавили list.Add(p) в самом начале блока добавления вложенных пропертей
(BLToolkit 3.1)
if (!isList &&
    !propertyType.IsValueType &&
    !propertyType.IsArray     &&
    (!propertyType.FullName.StartsWith("System.") || explicitlyBound
    || propertyType.IsGenericType) &&
     propertyType != typeof(Type)   &&
     propertyType != typeof(string) &&
     propertyType != typeof(object) &&
    Array.IndexOf(parentTypes, propertyType) == -1)
{
// НОВАЯ СТРОЧКА
    list.Add(p);
//...
}


Собственно вопросы:
1) Не наступил-ли случайно на грабли?
2) Если грабель нет, добавьте пожалуйста этот функционал в код, особенно второй пункт хочется.

И спасибо за суперский фреймворк!
Re: ObjectBinder - немного дополнительного функционал
От: albenik Россия  
Дата: 20.02.09 10:25
Оценка:
Отвечу сам себе: в пункте 2 есть хорошие такие подводные камни, по каким-то непонятным пока мне причинам в определенных случаях в рантайме получается так:

Дано:
public abstract Class1 : EditableObject<Class1>
{
    private Class3 _C3 = Class3.CreateInstance();
    public Class3 C3
    { 
        get
        {
            return _C3;
        } set
        {
            _C3 = value;
        }
    }
}
public abstarct Class2 : EditableObject<Class2>
{
   public string SomeProperty { get; set; }
}
public abstarct Class3 : EditableObject<Class3>
{
   public string SomeProperty { get; set; }
}

public abstract Class1Class2Link : EditableObject<Class1Class2Link>
{
    private Class1 _C1 = Class1.CreateInstance();
    public Class1 C1
    {
        get 
        {
            return _C1;
        }
        set
        {
            _C1 = value;
        }
    }
    private Class2 _C2 = Class2.CreateInstance();
    public Class2 C2
    {
        get 
        {
            return _C2;
        }
        set
        {
            _C2 = value;
        }
    }

    public SomeLinkProperty { get; set; }
}


В рантайме, не разобрался пока почему, происходит следующий вызов:
BLToolkitExtension.Class1$TypeAccessor.Accessor$C3.GetValue(object); // object.GetType() = typeof(Class1Class2Link)

И естественно генерится InvalidCastException.
Re[2]: ObjectBinder - немного дополнительного функционал
От: albenik Россия  
Дата: 23.02.09 18:06
Оценка:
И снова сам себе отвечаю
По поводу 2го пункта:
Ну за то, что я предложил вначале меня надо бить по рукам больно, вторая попытка

TypeAccessor.cs:817
if (!isList &&
    !propertyType.IsValueType &&
    !propertyType.IsArray &&
    (!propertyType.FullName.StartsWith("System.") || explicitlyBound
    || propertyType.IsGenericType) &&
     propertyType != typeof(Type) &&
     propertyType != typeof(string) &&
     propertyType != typeof(object) &&
    Array.IndexOf(parentTypes, propertyType) == -1)
{
    Type[] childParentTypes = new Type[parentTypes.Length + 1];

    parentTypes.CopyTo(childParentTypes, 0);
    childParentTypes[parentTypes.Length] = itemType;

    PropertyDescriptor[] childParentAccessors = new PropertyDescriptor[parentAccessors.Length + 1];

    parentAccessors.CopyTo(childParentAccessors, 0);
    childParentAccessors[parentAccessors.Length] = pd;

    PropertyDescriptorCollection pdch = GetAccessor(propertyType).PropertyDescriptors;

    pdch = pdch.Sort(new PropertyDescriptorComparer());
    pdch = GetExtendedProperties(
        pdch,
        propertyType,
        propertyPrefix + pd.Name + "+",
        childParentTypes,
        childParentAccessors,
        isNull);

    //НОВОЕ -BEGIN
    if (propertyPrefix.Length != 0 || isNull != null)
        pd = new StandardPropertyDescriptor(pd, propertyPrefix, parentAccessors, isNull);
    objects.Add(pd);
    //НОВОЕ - END
    objects.AddRange(pdch);
}
else
{
    if (propertyPrefix.Length != 0 || isNull != null)
        pd = new StandardPropertyDescriptor(pd, propertyPrefix, parentAccessors, isNull);

    list.Add(pd);
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.