public void AddColumnToAllRows(PropertyInfo prototypePropertyInfo, IComparable actualValue = null)
        {
            CreateablePropertyInfo cpi = new CreateablePropertyInfo(prototypePropertyInfo);
            Context context            = new Context(cpi.ToPropertyInfo());

            foreach (Row row in Rows)
            {
                Column column = new Column(row, actualValue, context);
                row.Columns.Add(column);
            }
        }
        public void AddColumnToAllRows(string name, Type propertyType, IComparable actualValue = null)
        {
            CreateablePropertyInfo cpi = new CreateablePropertyInfo(name, propertyType);
            Context context            = new Context(cpi.ToPropertyInfo());

            foreach (Row row in Rows)
            {
                Column column = new Column(row, actualValue, context);
                row.Columns.Add(column);
            }
        }
        public static Table GetTableFromTypedList <T>(List <T> typedList) where T : new()
        {
            List <PropertyInfo> propertyList;
            Table resultTable = new Table();

            if (typeof(T) != typeof(CustomDynamicObject))
            {
                propertyList = TypedPropertyList.GetPropertyList(typeof(T));

                foreach (T currentT in typedList)
                {
                    Row currentRow = new Row(resultTable);
                    foreach (PropertyInfo propInfo in propertyList)
                    {
                        Column currentColumn = null;
                        if (!string.IsNullOrWhiteSpace(propInfo.Name))
                        {
                            if (propInfo.CanRead && propInfo.CanWrite)
                            {
                                Context     context = new Context(propInfo);
                                IComparable value   = (IComparable)propInfo.GetValue(currentT, null);
                                currentColumn = new Column(currentRow, value, context);
                            }
                        }
                        if (currentColumn != null)
                        {
                            currentRow.Columns.Add(currentColumn);
                        }
                    }
                    if (currentRow.Columns.Count > 0)
                    {
                        resultTable.Rows.Add(currentRow);
                    }
                }
            }
            else
            {
                if (typedList.Count > 0)
                {
                    Dictionary <string, Type> propertyDict = (typedList[0] as CustomDynamicObject).GetPropertyNamesAndTypes();

                    foreach (T currentT in typedList)
                    {
                        Row currentRow = new Row(resultTable);
                        foreach (KeyValuePair <string, Type> propInfo in propertyDict)
                        {
                            Column currentColumn       = null;
                            CreateablePropertyInfo cpi = new CreateablePropertyInfo(propInfo.Key, propInfo.Value);
                            Context     context        = new Context(cpi.ToPropertyInfo());
                            IComparable value          = (IComparable)((currentT as CustomDynamicObject).GetPropertyValue(propInfo.Key));
                            currentColumn = new Column(currentRow, value, context);

                            if (currentColumn != null)
                            {
                                currentRow.Columns.Add(currentColumn);
                            }
                        }
                        if (currentRow.Columns.Count > 0)
                        {
                            resultTable.Rows.Add(currentRow);
                        }
                    }
                }
            }

            return(resultTable);
        }
Exemplo n.º 4
0
        public void ChangeContextType(Type newType)
        {
            CreateablePropertyInfo cpi = new CreateablePropertyInfo(_context.PropInfo.Name, newType);

            _context = new Context(cpi.ToPropertyInfo());
        }