Example #1
0
            private void InitializeProperties(Type type)
            {
                var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);

                _properties = new EntityPropertyDescriptor[properties.Length];

                for (int i = 0; i < properties.Length; i++)
                {
                    _properties[i] = new EntityPropertyDescriptor(properties[i].Name, properties[i].PropertyType, _dataAccess.IsScalarType(properties[i].PropertyType));
                }
            }
Example #2
0
        private List <object> ListGridItemValues(GridItem gridItem)
        {
            List <object> list = new List <object>();

            try
            {
                FieldInfo field = gridItem.GetType().GetField("objs", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (field != null)
                {
                    object[] objs = (object[])field.GetValue(gridItem);
                    for (int i = 0; i < objs.Length; i++)
                    {
                        object obj = objs[i];
                        EntityCustomTypeDescriptor entityCustomTypeDescriptor = obj as EntityCustomTypeDescriptor;
                        if (entityCustomTypeDescriptor != null)
                        {
                            obj = entityCustomTypeDescriptor.Entity;
                        }
                        list.Add(obj);
                    }
                }
            }
            catch { }

            if (list.Count == 0)
            {
                EntityPropertyDescriptor entityPropertyDescriptor = gridItem.PropertyDescriptor as EntityPropertyDescriptor;
                if (entityPropertyDescriptor != null)
                {
                    list.Add(entityPropertyDescriptor.Entity);
                }
            }

            if (list.Count == 0)
            {
                object value = gridItem.Parent.Value;
                if (!(value is System.Collections.ICollection))
                {
                    list.Add(gridItem.Parent.Value);
                }
            }
            return(list);
        }
Example #3
0
        /// <summary>
        /// Constructs the actual property descriptor collection.
        /// </summary>
        /// <param name="entityToCheck">entity instance which properties should be included in the collection</param>
        /// <param name="typeOfEntity">full type of the entity</param>
        /// <returns>filled in property descriptor collection</returns>
        public PropertyDescriptorCollection GetPropertyDescriptors(IEntity entityToCheck, Type typeOfEntity)
        {
            // get the descriptors of this instance
            PropertyDescriptorCollection instancePropertiesCollection = TypeDescriptor.GetProperties(typeOfEntity);
            ArrayList instanceProperties = new ArrayList();
            Hashtable namesAdded         = new Hashtable();

            foreach (IEntityField currentField in (EntityFields)entityToCheck.Fields)
            {
                EntityPropertyDescriptor newDescriptor = new EntityPropertyDescriptor(currentField, typeOfEntity);
                // check if the field is overriden. If so, replace it with THIS field.
                if (namesAdded.ContainsKey(currentField.Name))
                {
                    // replace
                    instanceProperties.Remove((EntityPropertyDescriptor)namesAdded[currentField.Name]);
                    instanceProperties.Add(newDescriptor);
                    namesAdded[currentField.Name] = newDescriptor;
                }
                else
                {
                    // add
                    instanceProperties.Add(newDescriptor);
                    namesAdded.Add(currentField.Name, newDescriptor);
                }
            }
#if CF
            // grab the propery info's. As the CF can't read the attributes from property descriptors, we have to use these.
            PropertyInfo[] propertyInfos = this.GetType().GetProperties();

            // now walk all properties in the property descriptor collection.
            foreach (PropertyInfo property in propertyInfos)
            {
                if (!namesAdded.ContainsKey(property.Name))
                {
                    // check if the property has a BrowsableAttribute.
                    object[] customAttributes = property.GetCustomAttributes(typeof(BrowsableAttribute), false);
                    if (customAttributes.Length > 0)
                    {
                        if (!((BrowsableAttribute)customAttributes[0]).Browsable)
                        {
                            continue;
                        }
                    }
                    PropertyDescriptor toAdd = instancePropertiesCollection[property.Name];
                    if (toAdd != null)
                    {
                        instanceProperties.Add(toAdd);
                    }
                }
            }
#else
            // now walk all properties in the property descriptor collection. Check if the name occurs in the hashtable. if not and if browsable, copy the descriptor over.
            foreach (PropertyDescriptor property in instancePropertiesCollection)
            {
                if (!namesAdded.ContainsKey(property.Name))
                {
                    if (!property.IsBrowsable)
                    {
                        continue;
                    }

                    // add it
                    instanceProperties.Add(property);
                }
            }
#endif
            return(new PropertyDescriptorCollection((PropertyDescriptor[])instanceProperties.ToArray(typeof(PropertyDescriptor))));
        }