Exemplo n.º 1
0
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            if (context.PropertyDescriptor == null)
            {
                return(null);
            }

            System.ComponentModel.DefaultValueAttribute dva = context.PropertyDescriptor.Attributes.Get(typeof(System.ComponentModel.DefaultValueAttribute)) as System.ComponentModel.DefaultValueAttribute;

            System.ComponentModel.PropertyDescriptorCollection pdc = new System.ComponentModel.PropertyDescriptorCollection(null, false);
            foreach (DynStandardValue sv in GetAllPossibleValues(context))
            {
                if (!sv.Visible)
                {
                    continue;
                }

                UpdateStringFromResource(context, sv);
                var epd = new EnumChildPropertyDescriptor(context, sv.Value.ToString(), sv.Value);
                epd.Attributes.Add(new System.ComponentModel.ReadOnlyAttribute(!sv.Enabled), true);
                epd.Attributes.Add(new System.ComponentModel.DescriptionAttribute(sv.Description), true);
                epd.Attributes.Add(new System.ComponentModel.DisplayNameAttribute(sv.DisplayName), true);
                epd.Attributes.Add(new System.ComponentModel.BrowsableAttribute(sv.Visible), true);

                // setup the default value;
                if (dva != null)
                {
                    bool bHasBit = EnumUtil.IsBitsOn(dva.Value, sv.Value);
                    epd.DefaultValue = bHasBit;
                }
                pdc.Add(epd);
            }
            return(pdc);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Fill the Login object from a DataRow
 /// </summary>
 /// <param name="dr">DataRow containing the objects info</param>
 public void Fill(System.Data.DataRow dr)
 {
     System.ComponentModel.PropertyDescriptorCollection props = System.ComponentModel.TypeDescriptor.GetProperties(this);
     for (int i = 0; (i < props.Count); i = (i + 1))
     {
         System.ComponentModel.PropertyDescriptor prop = props[i];
         if ((prop.IsReadOnly != true))
         {
             try
             {
                 if ((dr[prop.Name].Equals(System.DBNull.Value) != true))
                 {
                     if ((prop.PropertyType.Equals(dr[prop.Name].GetType()) != true))
                     {
                         prop.SetValue(this, prop.Converter.ConvertFrom(dr[prop.Name]));
                     }
                     else
                     {
                         prop.SetValue(this, dr[prop.Name]);
                     }
                 }
             }
             catch (System.Exception)
             {
             }
         }
     }
 }
Exemplo n.º 3
0
        public static DataTable ToDataTable2 <T>(this List <T> iList)
        {
            var dataTable = new DataTable();

            System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection =
                System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            for (int i = 0; i < propertyDescriptorCollection.Count; i++)
            {
                System.ComponentModel.PropertyDescriptor propertyDescriptor = propertyDescriptorCollection[i];
                Type type = propertyDescriptor.PropertyType;

                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    type = Nullable.GetUnderlyingType(type);
                }
                dataTable.Columns.Add(propertyDescriptor.Name, type);
            }
            object[] values = new object[propertyDescriptorCollection.Count];
            foreach (T iListItem in iList)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = propertyDescriptorCollection[i].GetValue(iListItem);
                }
                dataTable.Rows.Add(values);
            }
            return(dataTable);
        }
Exemplo n.º 4
0
        private StringBuilder ConvertToString <T>(IList <T> data)
        {
            System.ComponentModel.PropertyDescriptorCollection properties =
                System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            StringBuilder       sb       = new StringBuilder();
            List <PropertyInfo> property = typeof(T).GetProperties().ToList();
            var lstOrderList             = property.Where(e => ((DisplayAttribute)e.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()) != null && ((DisplayAttribute)e.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()).Order != -1).OrderBy(e => ((DisplayAttribute)e.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()).Order).ToList();

            sb.Append("<table style=\"border-collapse:collapse;text-align:left\">");
            //write column headings
            sb.Append("<tr>");
            foreach (var prop in lstOrderList)
            {
                if (prop.Name != "AcRcLevelText")
                {
                    sb.Append("<td><b><font face=Arial size=" + "10px" + ">" + prop.Name + "</font></b></td>");
                }
                else
                {
                    sb.Append("<td><b><font face=Arial size=" + "10px" + "></font></b></td>");
                }
            }
            sb.Append("</tr>");
            foreach (T item in data)
            {
                sb.Append("<tr>");
                foreach (var prop in lstOrderList)
                {
                    sb.Append("<td><font face=Arial size=" + "10px" + ">" + prop.GetValue(item) + "&nbsp; </font></td>");
                }
                sb.Append("</tr>");
            }
            return(sb);
        }
Exemplo n.º 5
0
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            System.ComponentModel.PropertyDescriptorCollection propertyDescriptors = base.GetProperties(context, value, attributes);

            int propertyCount = 0;

            for (int i = 0; i < propertyDescriptors.Count; i++)
            {
                if (ShowProperty(propertyDescriptors[i]))
                {
                    propertyCount++;
                }
            }

            int k = 0;

            System.ComponentModel.PropertyDescriptor[] filteredProperties = new System.ComponentModel.PropertyDescriptor[propertyCount];
            for (int i = 0; i < propertyDescriptors.Count; i++)
            {
                if (ShowProperty(propertyDescriptors[i]))
                {
                    filteredProperties[k++] = propertyDescriptors[i];
                }
            }

            return(new System.ComponentModel.PropertyDescriptorCollection(filteredProperties));
        }
Exemplo n.º 6
0
        public static System.Data.DataTable ConvertListToDataTable <T>(System.Collections.Generic.IList <T> list)
        {
            if (list == null)
            {
                return(null);
            }

            System.ComponentModel.PropertyDescriptorCollection props = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));

            using (System.Data.DataTable table = new System.Data.DataTable())
            {
                table.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;

                for (int i = 0; i < props.Count; i++)
                {
                    System.ComponentModel.PropertyDescriptor prop = props[i];
                    table.Columns.Add(prop.Name, prop.PropertyType);
                }
                object[] values = new object[props.Count];
                foreach (T item in list)
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = props[i].GetValue(item);
                    }
                    table.Rows.Add(values);
                }
                return(table);
            }
        }
Exemplo n.º 7
0
        public DataTable ConvertirATabla <T>(IList <T> data)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();

            foreach (System.ComponentModel.PropertyDescriptor prop in properties)
            {
                var _attr = prop.Attributes.OfType <System.ComponentModel.DataAnnotations.Schema.ColumnAttribute>();
                if (_attr.Any())
                {
                    var _col = new DataColumn(_attr.First().TypeName.ToUpper(), Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
                    _col.AllowDBNull = true;
                    table.Columns.Add(_col);
                }
            }

            foreach (T item in data)
            {
                DataRow row = table.NewRow();
                foreach (System.ComponentModel.PropertyDescriptor prop in properties)
                {
                    var _attr = prop.Attributes.OfType <System.ComponentModel.DataAnnotations.Schema.ColumnAttribute>();
                    if (_attr.Any())
                    {
                        row[_attr.First().TypeName.ToUpper()] = prop.GetValue(item) ?? DBNull.Value;
                    }
                }

                table.Rows.Add(row);
            }
            return(table);
        }
Exemplo n.º 8
0
        public void UpdateOnSaveChanges(TEntity entity, out OperationResult rState)
        {
            try
            {
                var result = this.GetByPkValue(this.GetPkValue(entity, out rState), out rState);

                System.ComponentModel.PropertyDescriptorCollection originalProps = System.ComponentModel.TypeDescriptor.GetProperties(entity);

                foreach (System.ComponentModel.PropertyDescriptor item in originalProps)
                {
                    if (item.Attributes[typeof(System.Data.Objects.DataClasses.EdmScalarPropertyAttribute)] != null &&
                        !(bool)(item.Attributes[typeof(System.Data.Objects.DataClasses.EdmScalarPropertyAttribute)].GetType().GetProperty("EntityKeyProperty")
                                .GetValue(item.Attributes[typeof(System.Data.Objects.DataClasses.EdmScalarPropertyAttribute)], null)))
                    {
                        item.SetValue(result, entity.GetType().GetProperty(item.Name).GetValue(entity, null));
                    }
                }
                entity = result;
                //this.SaveChanges(out rState);
                rState = new OperationResult(null);
            }
            catch (Exception ex)
            {
                rState = new OperationResult(ex);
            }
        }
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties()
        {
            if (m_PropertyDescriptorCollection != null)
            {
                return(m_PropertyDescriptorCollection);
            }

            System.ComponentModel.PropertyDescriptorCollection originalProperties = base.GetProperties();
            List <System.ComponentModel.PropertyDescriptor>    newProperties      = new List <System.ComponentModel.PropertyDescriptor>();

            foreach (System.ComponentModel.PropertyDescriptor pd in originalProperties)
            {
                newProperties.Add(pd);
            }

            // System.Diagnostics.Debug.WriteLine(" *** ID: " + m_Facility.TempId.ToString());

            if (m_Facility != null && !String.IsNullOrEmpty(m_Facility.ObjectTypeId))
            {
                var c = GetRuntimeProperties(m_Facility);
                newProperties.AddRange(c);
                m_PropertyDescriptorCollection = new System.ComponentModel.PropertyDescriptorCollection(newProperties.ToArray(), true);
                return(m_PropertyDescriptorCollection);
            }

            return(new System.ComponentModel.PropertyDescriptorCollection(newProperties.ToArray(), true));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 将List转换成DataTable,如果数据为空,则返回一个没有内容的DataTable
        /// </summary>
        /// <param name="data">要转换的数据</param>
        /// <returns>datatable</returns>
        public static DataTable ToDataTable <T>(IList <T> data)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            DataTable dt = new DataTable();

            if (null == data)
            {
                return(dt);
            }
            Type nullableType;

            for (int i = 0; i < properties.Count; i++)
            {
                var property = properties[i];
                nullableType = Nullable.GetUnderlyingType(property.PropertyType);
                dt.Columns.Add(property.Name, null == nullableType ? property.PropertyType : nullableType);
            }
            object[] values = new object[properties.Count];
            foreach (T item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = properties[i].GetValue(item);
                }
                dt.Rows.Add(values);
            }
            return(dt);
        }
Exemplo n.º 11
0
        private void prepareFindSqlQuery(string key, object parameters, bool?sortDescendingByDate, out string whereClause, out object queryParameter)
        {
            // prepare sql where statement
            System.Text.StringBuilder query = new System.Text.StringBuilder("Select [Value] FROM \"", 120).Append(TableName).Append("\" WHERE");

            // prepare key filter
            if (key != null)
            {
                query.Append(" [Key] = @Key");
            }
            // prepare parameters filter
            if (parameters != null)
            {
                System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(parameters);

                var values = new List <KeyValuePair <string, object> > (properties.Count + 1);
                values.Add(new KeyValuePair <string, object> ("Key", key));

                int i = 0;
                foreach (System.ComponentModel.PropertyDescriptor property in properties)
                {
                    ++i;
                    object value = property.GetValue(parameters);
                    string vName = "v" + i;
                    if (i > 1 || key != null)
                    {
                        query.Append(" AND");
                    }
                    query.Append(" [Value] LIKE @").Append(vName);
                    values.Add(new KeyValuePair <string, object> (vName, "%\"" + property.Name + "\":" + Newtonsoft.Json.JsonConvert.SerializeObject(value) + "%"));
                }
                queryParameter = createAnonymousType(values);
            }
            else
            {
                queryParameter = new { Key = key };
            }
            // prepare sort mode
            if (sortDescendingByDate.HasValue)
            {
                if (sortDescendingByDate.Value)
                {
                    if (key == null)
                    {
                        query.Append(" Order by [Id] DESC");
                    }
                    else
                    {
                        query.Append(" Order by [Key], [Date] DESC");
                    }
                }
                else
                {
                    query.Append(" Order by [Id]");
                }
            }
            whereClause = query.ToString();
        }
Exemplo n.º 12
0
        static EnumerableDbDataReader()
        {
            DataTable  = new DataTable();
            Properties = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));

            foreach (System.ComponentModel.PropertyDescriptor prop in Properties)
            {
                DataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            }
        }
Exemplo n.º 13
0
        public static List <KeyValuePair <string, object> > ParseToList(this object obj)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(obj);
            List <KeyValuePair <string, object> > result = new List <KeyValuePair <string, object> > (properties.Count);

            foreach (System.ComponentModel.PropertyDescriptor property in properties)
            {
                result.Add(new KeyValuePair <string, object> (property.Name, property.GetValue(obj)));
            }
            return(result);
        }
Exemplo n.º 14
0
        public static Dictionary <string, object> ParseToDictionary(this object obj)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(obj);
            Dictionary <string, object> result = new Dictionary <string, object> (properties.Count + 1, StringComparer.Ordinal);

            foreach (System.ComponentModel.PropertyDescriptor property in properties)
            {
                result.Add(property.Name, property.GetValue(obj));
            }
            return(result);
        }
Exemplo n.º 15
0
        // Method implemented to expose Volume and PayLoad properties conditionally, depending on TypeOfCar
        public System.ComponentModel.PropertyDescriptorCollection GetProperties()
        {
            var props = new System.ComponentModel.PropertyDescriptorCollection(null);

            for (int i = 0; i < Properties.Count; i++)
            {
                var item = Properties[i];
                props.Add(new CustomPropertyDescriptor(ref item, item.EditorType == null ? null : new Attribute[] { new System.ComponentModel.EditorAttribute(item.EditorType, item.EditorType) }));
            }

            return(props);
        }
Exemplo n.º 16
0
            private Dictionary <string, PropertyStoreItem> CreatePropertyStoreItems()
            {
                Dictionary <string, PropertyStoreItem> propertyStoreItems = new Dictionary <string, PropertyStoreItem>();

                System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(this._type);
                foreach (System.ComponentModel.PropertyDescriptor property in properties)
                {
                    PropertyStoreItem item = new PropertyStoreItem(property.PropertyType, GetExplicitAttributes(property).Cast <Attribute>());
                    propertyStoreItems[property.Name] = item;
                }

                return(propertyStoreItems);
            }
Exemplo n.º 17
0
 System.ComponentModel.PropertyDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetProperties()
 {
     // Create a new collection object PropertyDescriptorCollection
     System.ComponentModel.PropertyDescriptorCollection pds = new System.ComponentModel.PropertyDescriptorCollection(null);
     // Iterate the list of parameters
     for (int i = 0; i < this.Items.Count; i++)
     {
         // For each parameter create a property descriptor
         // and add it to the PropertyDescriptorCollection instance
         ParameterCollectionPropertyDescriptor pd = new ParameterCollectionPropertyDescriptor(this, i);
         pds.Add(pd);
     }
     return(pds);
 }
Exemplo n.º 18
0
        private ExtendVersion GetExtendVersion(string ExtenderCATID, string ExtenderName, object ExtendeeObject)
        {
            if (ExtenderName != Name)
            {
                return(ExtendVersion.None);
            }

            try
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(ExtendeeObject);
                if (properties == null)
                {
                    return(ExtendVersion.None);
                }

                PropertyDescriptor property = properties["ItemType"];
                if (property == null)
                {
                    return(ExtendVersion.None);
                }

                object value = property.GetValue(ExtendeeObject);
                if (value == null)
                {
                    return(ExtendVersion.None);
                }

                string itemType = value.ToString();
                if (string.Equals(itemType, "Antlr3", StringComparison.OrdinalIgnoreCase))
                {
                    return(ExtendVersion.Antlr3);
                }

                if (string.Equals(itemType, "Antlr4", StringComparison.OrdinalIgnoreCase))
                {
                    return(ExtendVersion.Antlr4);
                }

                return(ExtendVersion.None);
            }
            catch (Exception ex)
            {
                if (ex.IsCritical())
                {
                    throw;
                }

                return(ExtendVersion.None);
            }
        }
Exemplo n.º 19
0
 public Int32 CompareTo(Object obj)
 {
     System.ComponentModel.PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties(this);
     Avenue.Workflow.Access.Theme xT = null;
     if (typeof(Theme) == obj.GetType())
     {
         xT = (Theme)obj;
         return(this.CompareTo(xT, pdc["[DEFAULTPROPERTY]"]));
     }
     else
     {
         return(this.CompareTo((Theme)obj, pdc["[DEFAULTPROPERTY]"]));
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Convertir un List en un Datatable
        /// </summary>
        /// <param name="data">Datos que va a contener la lista.</param>
        /// <returns></returns>
        public static DataTable ConvertListToDataTable <T>(List <T> data)
        {
            // http://stackoverflow.com/questions/19076034/how-to-fill-a-datatable-with-listt
            System.ComponentModel.PropertyDescriptorCollection props =
                System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            DataTable table = new DataTable();

            table.TableName = "Tabla";
            for (int i = 0; i < props.Count; i++)
            {
                System.ComponentModel.PropertyDescriptor prop = props[i];
                if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    table.Columns.Add(prop.Name, prop.PropertyType.GetGenericArguments()[0]);
                }
                else
                {
                    if (prop.PropertyType.IsArray)
                    {
                        table.Columns.Add(prop.Name, typeof(string));
                    }
                    else
                    {
                        table.Columns.Add(prop.Name, prop.PropertyType);
                    }
                }
            }
            object[] values = new object[props.Count];
            foreach (T item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    if (props[i].PropertyType.IsArray)
                    {
                        values[i] = GetPropiedades(props[i].GetValue(item));
                        if (values[i].ToString().ToLower().IndexOf("length : 0") >= 0)
                        {
                            values[i] = string.Empty;
                        }
                    }
                    else
                    {
                        values[i] = props[i].GetValue(item);
                    }
                }
                table.Rows.Add(values);
            }
            return(table);
        }
Exemplo n.º 21
0
        /// <summary>
        /// This method creates ConfigWrapperDefinition based on the given configType. In case in config files written in C# it will use Properties as Config parameters.
        /// In case of Java it will scan for pairs of getters and setters, and if it will find one it will create a property for it. For example void setTest(string value) and string getTest()
        /// will generate property 'string Test'
        /// </summary>
        /// <param name="configType"></param>
        /// <returns></returns>
        internal static ConfigWrapperDefinition CreateConfigWrapperDefinition(Type configType)
        {
            ConfigWrapperDefinition configWrapperDefinition = null;

            if (configType != null)
            {
                bool isJava = CheckIfJavaType(configType);

                configWrapperDefinition = new ConfigWrapperDefinition(isJava, configType.FullName);

                if (isJava == false)
                {
                    System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(configType);
                    configWrapperDefinition.AddProperties(properties);
                }
                else
                {
                    //check for java if there are any java getters
                    String getterPrefix         = "get";
                    String setterPrefix         = "set";
                    String getterPropertyPrefix = "get_"; // .net style getter generated for properties

                    MethodInfo[] methods = configType.GetMethods(BindingFlags.Public | BindingFlags.Instance);

                    foreach (MethodInfo method in methods)
                    {
                        if (method.Name.StartsWith(getterPrefix, StringComparison.InvariantCulture) == true && method.Name.StartsWith(getterPropertyPrefix, StringComparison.InvariantCulture) == false)
                        {
                            String propertyName = method.Name.Substring(getterPrefix.Length);
                            Type   propertyType = method.ReturnParameter.ParameterType;
                            //check if there is any corresponding set method for this property
                            if (methods.Any(item => item.Name.Equals(setterPrefix + propertyName, StringComparison.CurrentCulture)))
                            {
                                //check if setter has one input of the same type as the getter return type
                                MethodInfo setter = configType.GetMethod(setterPrefix + propertyName, BindingFlags.Public | BindingFlags.Instance, null, new Type[] { propertyType }, null);
                                if (setter != null)
                                {
                                    //TODO: Description for hava config values
                                    string propertyDescription = propertyName;
                                    //finally add the property
                                    configWrapperDefinition.AddProperty(propertyName, method.ReturnParameter.ParameterType.FullName, method.ReturnParameter.ParameterType.AssemblyQualifiedName, propertyName, propertyDescription);
                                }
                            }
                        }
                    }
                }
            }
            return(configWrapperDefinition);
        }
Exemplo n.º 22
0
        private static void TestBindingList()
        {
            List <Employee> list = new List <Employee>();
            Employee        emp1 = new Employee();

            emp1.Name    = "Peter";
            emp1.Address = "New York";
            list.Add(emp1);
            Employee emp2 = new Employee();

            emp2.Name    = "John";
            emp2.Address = "Boston";
            list.Add(emp2);


            DevAge.ComponentModel.BoundList <Employee> bd = new DevAge.ComponentModel.BoundList <Employee>(list);

            bd.ListChanged += delegate(object sender, System.ComponentModel.ListChangedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("ListChanged " + list.Count);
            };

            System.ComponentModel.PropertyDescriptorCollection props = bd.GetItemProperties();

            int r;

            r = bd.BeginAddNew();

            bd.SetEditValue(props[0], "Pluto");
            bd.SetEditValue(props[1], "Via Tripoli");

            bd.EndEdit(true);


            r = bd.BeginAddNew();

            bd.SetEditValue(props[0], "Pluto");
            bd.SetEditValue(props[1], "Corso Orbassano");

            bd.EndEdit(false);


            bd.BeginEdit(0);

            bd.SetEditValue(props[0], "Davide");

            bd.EndEdit(true);
        }
Exemplo n.º 23
0
        private static void TestBindingDataView()
        {
            //Create a sample DataSet
            System.Data.DataSet   ds    = new System.Data.DataSet();
            System.Data.DataTable table = ds.Tables.Add("Table1");
            table.Columns.Add("Col1", typeof(string));
            table.Columns.Add("Col2", typeof(double));
            table.Rows.Add("Value 1", 59.7);
            table.Rows.Add("Value 2", 59.9);


            System.Data.DataView dView = table.DefaultView;

            DevAge.ComponentModel.BoundDataView bd = new DevAge.ComponentModel.BoundDataView(dView);

            bd.ListChanged += delegate(object sender, System.ComponentModel.ListChangedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("ListChanged " + dView.Count);
            };

            System.ComponentModel.PropertyDescriptorCollection props = bd.GetItemProperties();

            int r;

            r = bd.BeginAddNew();

            bd.SetEditValue(props[0], "Pluto");
            bd.SetEditValue(props[1], 394);

            bd.EndEdit(true);


            r = bd.BeginAddNew();

            bd.SetEditValue(props[0], "Peter");
            bd.SetEditValue(props[1], 89);

            bd.EndEdit(false);


            bd.BeginEdit(0);
            bd.SetEditValue(props[0], "Test");
            bd.EndEdit(true);

            bd.BeginEdit(0);
            bd.SetEditValue(props[0], "Test 2");
            bd.EndEdit(false);
        }
        public System.ComponentModel.PropertyDescriptorCollection GetProperties()
        {
            // Create a new collection object PropertyDescriptorCollection
            System.ComponentModel.PropertyDescriptorCollection pds = new System.ComponentModel.PropertyDescriptorCollection(null);

            // Iterate the list of employees
            for (short i = 0; i < eaCollection.Count; ++i)
            {
                // For each Element create a property descriptor
                // and add it to the PropertyDescriptorCollection instance
                BrowsableCollectionPropertyDescriptor <T> pd =
                    new BrowsableCollectionPropertyDescriptor <T>(this, i);
                pds.Add(pd);
            }
            return(pds);
        }
Exemplo n.º 25
0
        private static ICollection <KeyValuePair <ValidationContext, object> > GetPropertyValues(object instance, ValidationContext validationContext)
        {
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(instance);
            List <KeyValuePair <ValidationContext, object> >   items      = new List <KeyValuePair <ValidationContext, object> >(properties.Count);

            foreach (System.ComponentModel.PropertyDescriptor property in properties)
            {
                ValidationContext context = CreateValidationContext(instance, validationContext);
                context.MemberName = property.Name;

                if (_store.GetPropertyValidationAttributes(context).Any())
                {
                    items.Add(new KeyValuePair <ValidationContext, object>(context, property.GetValue(instance)));
                }
            }
            return(items);
        }
Exemplo n.º 26
0
        public static bool _GetProperties_System_Object_System_Boolean( )
        {
            //class object
            System.ComponentModel.TypeDescriptor _System_ComponentModel_TypeDescriptor = new System.ComponentModel.TypeDescriptor();

            //Parameters
            System.Object  component        = null;
            System.Boolean noCustomTypeDesc = false;

            //ReturnType/Value
            System.ComponentModel.PropertyDescriptorCollection returnVal_Real        = null;
            System.ComponentModel.PropertyDescriptorCollection returnVal_Intercepted = null;

            //Exception
            System.Exception exception_Real        = null;
            System.Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnVal_Real = _System_ComponentModel_TypeDescriptor.GetProperties(component, noCustomTypeDesc);
            }

            catch (System.Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnVal_Intercepted = _System_ComponentModel_TypeDescriptor.GetProperties(component, noCustomTypeDesc);
            }

            catch (System.Exception e)
            {
                exception_Intercepted = e;
            }


            return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
        public static bool _GetProperties_System_ComponentModel_BaseNumberConverter_System_ComponentModel_ITypeDescriptorContext_System_Object( )
        {
            //class object
            System.ComponentModel.BaseNumberConverter _System_ComponentModel_BaseNumberConverter = new System.ComponentModel.BaseNumberConverter();

            //Parameters
            System.ComponentModel.ITypeDescriptorContext context = null;
            System.Object _value = null;

            //ReturnType/Value
            System.ComponentModel.PropertyDescriptorCollection returnVal_Real        = null;
            System.ComponentModel.PropertyDescriptorCollection returnVal_Intercepted = null;

            //Exception
            System.Exception exception_Real        = null;
            System.Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnVal_Real = _System_ComponentModel_BaseNumberConverter.GetProperties(context, _value);
            }

            catch (System.Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnVal_Intercepted = _System_ComponentModel_BaseNumberConverter.GetProperties(context, _value);
            }

            catch (System.Exception e)
            {
                exception_Intercepted = e;
            }


            return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
Exemplo n.º 28
0
        public List <MODCampos> ObtenerCampos <T>()
        {
            var resultado = new List <MODCampos>();

            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
            foreach (System.ComponentModel.PropertyDescriptor prop in properties)      //
            {
                var _attr = prop.Attributes.OfType <System.ComponentModel.DataAnnotations.Schema.ColumnAttribute>();
                if (_attr.Any())
                {
                    resultado.Add(new MODCampos {
                        Nombre = _attr.First().TypeName.ToUpper(), Ordinal = _attr.First().Order
                    });
                }
            }

            return(resultado);
        }
Exemplo n.º 29
0
        /// <summary>
        /// 对象转化为字典
        /// </summary>
        public static Dictionary <string, object> ToAnonymousDict(object data)
        {
            Dictionary <string, object> dict = null;

            if (data != null)
            {
                dict = new Dictionary <string, object>();

                System.ComponentModel.PropertyDescriptorCollection pds = System.ComponentModel.TypeDescriptor.GetProperties(data);

                foreach (System.ComponentModel.PropertyDescriptor pd in pds)
                {
                    dict.Add(pd.Name, pd.GetValue(data));
                }
            }

            return(dict);
        }
Exemplo n.º 30
0
 public System.Data.DataTable ConvertToDataTable <T>(IList <T> data, string[] selection)
 {
     System.ComponentModel.PropertyDescriptorCollection properties =
         System.ComponentModel.TypeDescriptor.GetProperties(typeof(T));
     System.Data.DataTable table = new System.Data.DataTable();
     //order arrangement
     foreach (string selectedName in selection)
     {
         System.ComponentModel.PropertyDescriptor prop = properties.Find(selectedName, true);
         if (prop != null)
         {
             if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))))
             {
                 table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
             }
             else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)))
             {
                 table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
             }
         }
     }
     //foreach (System.ComponentModel.PropertyDescriptor prop in properties)
     //    if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))))
     //        table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
     //    else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))
     //        table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
     foreach (T item in data)
     {
         System.Data.DataRow row = table.NewRow();
         foreach (System.ComponentModel.PropertyDescriptor prop in properties)
         {
             if ((!prop.PropertyType.IsGenericType && selection != null && selection.Contains(prop.Name.Trim())) || (selection != null && prop.PropertyType.IsGenericType && selection.Contains(prop.Name.Trim()) && (selection != null && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))))
             {
                 row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
             }
             else if ((!prop.PropertyType.IsGenericType && selection == null) || (selection == null && prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)))
             {
                 row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
             }
         }
         table.Rows.Add(row);
     }
     return(table);
 }
Exemplo n.º 31
0
        private CustomTypeDescriptor(Type type, bool isAnonymousClass, MemberInfo[] members, string[] names)
        {
            if (type == null) 
                throw new ArgumentNullException("type");

            //
            // No members supplied? Get all public, instance-level fields and 
            // properties of the type that are not marked with the JsonIgnore
            // attribute.
            //
            
            if (members == null)
            {
                const BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public;
                FieldInfo[] fields = type.GetFields(bindings);
                PropertyInfo[] properties = type.GetProperties(bindings);
                
                //
                // Filter out members marked with JsonIgnore attribute.
                //
                
                ArrayList memberList = new ArrayList(fields.Length + properties.Length);
                memberList.AddRange(fields);
                memberList.AddRange(properties);

                for (int i = 0; i < memberList.Count; i++)
                {
                    MemberInfo member = (MemberInfo) memberList[i];
                    
                    if (!member.IsDefined(typeof(JsonIgnoreAttribute), true))
                        continue;
                    
                    memberList.RemoveAt(i--);
                }
                
                members = (MemberInfo[]) memberList.ToArray(typeof(MemberInfo));
            }
                        
            PropertyDescriptorCollection logicalProperties = new PropertyDescriptorCollection(null);
            
            int index = 0;
            
            foreach (MemberInfo member in members)
            {
                FieldInfo field = member as FieldInfo;
                string name = names != null && index < names.Length ? names[index] : null;
                TypeMemberDescriptor descriptor = null;

                if (field != null)
                {
                    //
                    // Add public fields that are not read-only and not 
                    // constant literals.
                    //
            
                    if (field.DeclaringType != type && field.ReflectedType != type)
                        throw new ArgumentException(null, "members");
                
                    if (!field.IsInitOnly && !field.IsLiteral)
                        descriptor = new TypeFieldDescriptor(field, name);
                }
                else
                {
                    PropertyInfo property = member as PropertyInfo;
                    
                    if (property == null)
                        throw new ArgumentException(null, "members");
                    
                    //
                    // Add public properties that can be read and modified.
                    // If property is read-only yet has the JsonExport 
                    // attribute applied then include it anyhow (assuming
                    // that the type author probably has customizations
                    // that know how to deal with the sceanrio more 
                    // accurately). What's more, if the type is anonymous 
                    // then the rule that the proerty must be writeable is
                    // also bypassed.
                    //

                    if (property.DeclaringType != type && property.ReflectedType != type)
                        throw new ArgumentException(null, "members");

                    if ((property.CanRead) &&
                        (isAnonymousClass || property.CanWrite || property.IsDefined(typeof(JsonExportAttribute), true)) &&
                        property.GetIndexParameters().Length == 0)
                    {
                        //
                        // Properties of an anonymous class will always use 
                        // their original property name so that no 
                        // transformation (like auto camel-casing) is 
                        // applied. The rationale for the exception here is
                        // that since the user does not have a chance to
                        // decorate properties of an anonymous class with
                        // attributes, there is no way an overriding policy
                        // can be implemented.
                        //

                        descriptor = new TypePropertyDescriptor(property, 
                            isAnonymousClass ? Mask.EmptyString(name, property.Name) : name);
                    }
                }
                
                if (descriptor != null)
                {
                    descriptor.ApplyCustomizations();
                    logicalProperties.Add(descriptor);
                }
                
                index++;
            }
                
            _properties = logicalProperties;
        }
Exemplo n.º 32
0
        public CustomTypeDescriptor(Type type, MemberInfo[] members, string[] names)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            //
            // No members supplied? Get all public, instance-level fields and
            // properties of the type that are not marked with the JsonIgnore
            // attribute.
            //

            if (members == null)
            {
                const BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public;
                FieldInfo[] fields = type.GetFields(bindings);
                PropertyInfo[] properties = type.GetProperties(bindings);

                //
                // Filter out members marked with JsonIgnore attribute.
                //

                ArrayList memberList = new ArrayList(fields.Length + properties.Length);
                memberList.AddRange(fields);
                memberList.AddRange(properties);

                for (int i = 0; i < memberList.Count; i++)
                {
                    MemberInfo member = (MemberInfo) memberList[i];

                    if (!member.IsDefined(typeof(JsonIgnoreAttribute), true))
                        continue;

                    memberList.RemoveAt(i--);
                }

                members = (MemberInfo[]) memberList.ToArray(typeof(MemberInfo));
            }

            PropertyDescriptorCollection logicalProperties = new PropertyDescriptorCollection(null);

            int index = 0;

            foreach (MemberInfo member in members)
            {
                FieldInfo field = member as FieldInfo;
                string name = names != null && index < names.Length ? names[index] : null;

                if (field != null)
                {
                    //
                    // Add public fields that are not read-only and not
                    // constant literals.
                    //

                    if (field.DeclaringType != type && field.ReflectedType != type)
                        throw new ArgumentException("fields");

                    if (!field.IsInitOnly && !field.IsLiteral)
                        logicalProperties.Add(new TypeFieldDescriptor(field, name));
                }
                else
                {
                    PropertyInfo property = member as PropertyInfo;

                    if (property != null)
                    {
                        //
                        // Add public properties that can be read and modified.
                        //

                        if (property.DeclaringType != type && property.ReflectedType != type)
                            throw new ArgumentException("properties");

                        if (property.CanRead && property.CanWrite)
                            logicalProperties.Add(new TypePropertyDescriptor(property, name));
                    }
                    else
                    {
                        throw new ArgumentException("members");
                    }
                }

                index++;
            }

            _properties = logicalProperties;
        }