示例#1
0
 private void BuildChildren(ObjectRelation parent)
 {
     if (this.properties == null)
     {
         return;
     }
     for (int index = 0; index < this.properties.Count; ++index)
     {
         bool flag = typeof(IBindingList).IsAssignableFrom(this.properties[index].PropertyType) || typeof(IList).IsAssignableFrom(this.properties[index].PropertyType) || typeof(ITypedList).IsAssignableFrom(this.properties[index].PropertyType) || typeof(IListSource).IsAssignableFrom(this.properties[index].PropertyType);
         if (!flag && typeof(IEnumerable).IsAssignableFrom(this.properties[index].PropertyType) && this.properties[index].PropertyType.IsGenericType)
         {
             flag = !(this.list is string);
         }
         if (flag)
         {
             IEnumerable list = this.list as IEnumerable;
             if (list != null)
             {
                 IEnumerator    enumerator     = list.GetEnumerator();
                 ObjectRelation objectRelation = !enumerator.MoveNext() ? new ObjectRelation((object)this.properties[index].PropertyType) : new ObjectRelation(this.properties[index].GetValue(enumerator.Current));
                 objectRelation.childNames.Add(this.properties[index].Name);
                 objectRelation.parent = this;
                 this.childRelations.Add(objectRelation);
             }
         }
     }
 }
示例#2
0
        //private IList LoadFromEnumerable()
        //{
        //    IEnumerable e = this.list as IEnumerable;
        //    if (e == null)
        //    {
        //        return null;
        //    }

        //    IEnumerator enumerator = e.GetEnumerator();
        //    List<object> newlist = new List<object>(255);
        //    while (enumerator.MoveNext())
        //    {
        //        newlist.Add(enumerator.Current);
        //    }

        //    return newlist;
        //}

        private void BuildChildren(ObjectRelation parent)
        {
            if (this.properties == null)
            {
                return;
            }

            for (int i = 0; i < properties.Count; i++)
            {
                bool isIList = typeof(IBindingList).IsAssignableFrom(this.properties[i].PropertyType) ||
                               typeof(IList).IsAssignableFrom(this.properties[i].PropertyType) ||
                               typeof(ITypedList).IsAssignableFrom(this.properties[i].PropertyType) ||
                               typeof(IListSource).IsAssignableFrom(this.properties[i].PropertyType);

                if (!isIList && typeof(IEnumerable).IsAssignableFrom(this.properties[i].PropertyType) && this.properties[i].PropertyType.IsGenericType)
                {
                    //this.list = this.LoadFromEnumerable();

                    isIList = !(list is string);
                }

                if (isIList)//(IEnumerable).IsAssignableFrom(this.properties[i].PropertyType)
                {
                    IEnumerable values = this.list as IEnumerable;
                    if (values == null)
                    {
                        continue;
                    }

                    ObjectRelation child = null;
                    IEnumerator    e     = values.GetEnumerator();
                    if (e.MoveNext())
                    {
                        child = new ObjectRelation(properties[i].GetValue(e.Current));
                    }
                    else
                    {
                        child = new ObjectRelation(properties[i].PropertyType);
                    }

                    //ObjectRelation child = new ObjectRelation(properties[i].PropertyType);
                    child.childNames.Add(this.properties[i].Name);
                    child.parent = this;
                    this.childRelations.Add(child);
                }
            }
        }
示例#3
0
 public static ObjectRelation GetObjectRelation(
     object dataSource,
     string dataMember)
 {
     if (dataSource is BindingSource)
     {
         if (((BindingSource)dataSource).DataSource == null && !string.IsNullOrEmpty(dataMember))
         {
             return((ObjectRelation)null);
         }
         if (((BindingSource)dataSource).DataSource is DataSet && !string.IsNullOrEmpty(dataMember))
         {
             dataSource = ((BindingSource)dataSource).DataSource;
         }
     }
     return(ObjectRelation.GetObjectRelation(ListBindingHelper.GetList(dataSource, dataMember)));
 }
示例#4
0
 public static ObjectRelation GetObjectRelation(object dataSource, string dataMember)
 {
     return(ObjectRelation.GetObjectRelation(ListBindingHelper.GetList(dataSource, dataMember)));
 }