Beispiel #1
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            List <PropertyDescriptorNamedValue> list = new List <PropertyDescriptorNamedValue>();

            if (_type != null)
            {
                if (_values == null)
                {
                    _values = new Dictionary <string, object>();
                }
                if (_defValues == null)
                {
                    _defValues = new Dictionary <string, object>();
                }
                PropertyInfo[] pifs = _type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                if (pifs != null && pifs.Length > 0)
                {
                    for (int i = 0; i < pifs.Length; i++)
                    {
                        if (!pifs[i].IsSpecialName && pifs[i].CanRead && pifs[i].CanWrite)
                        {
                            if (_type.Equals(pifs[i].DeclaringType))
                            {
                                if (!_defValues.ContainsKey(pifs[i].Name))
                                {
                                    _defValues.Add(pifs[i].Name, VPLUtil.GetPropertyDefaultValue(pifs[i]));
                                }
                                if (!_values.ContainsKey(pifs[i].Name))
                                {
                                    _values.Add(pifs[i].Name, _defValues[pifs[i].Name]);
                                }
                                PropertyDescriptorNamedValue p = new PropertyDescriptorNamedValue(pifs[i].Name, attributes, this, pifs[i].PropertyType);
                                list.Add(p);
                            }
                        }
                    }
                }
                FieldInfo[] fifs = _type.GetFields(BindingFlags.Public | BindingFlags.Instance);
                if (fifs != null && fifs.Length > 0)
                {
                    for (int i = 0; i < fifs.Length; i++)
                    {
                        if (!fifs[i].IsSpecialName)
                        {
                            if (_type.Equals(fifs[i].DeclaringType))
                            {
                                if (!_defValues.ContainsKey(fifs[i].Name))
                                {
                                    _defValues.Add(fifs[i].Name, VPLUtil.GetFieldDefaultValue(fifs[i]));
                                }
                                if (!_values.ContainsKey(fifs[i].Name))
                                {
                                    _values.Add(fifs[i].Name, _defValues[fifs[i].Name]);
                                }
                                PropertyDescriptorNamedValue p = new PropertyDescriptorNamedValue(fifs[i].Name, attributes, this, fifs[i].FieldType);
                                list.Add(p);
                            }
                        }
                    }
                }
            }
            PropertyDescriptorCollection ps = new PropertyDescriptorCollection(list.ToArray());

            return(ps);
        }