Exemple #1
0
        //----------------------------------//

        //----------------------------------//

        //----------------------------------//

        /// <summary>
        /// Internal constructor called when its owning table initializes.
        /// </summary>
        internal Column(ColumnAttribute attribute) : base(attribute)
        {
        }
Exemple #2
0
        //-------------------------------------------//

        /// <summary>
        /// Construct a new Table instance.
        /// </summary>
        protected Table(string keyspaceName = null)
        {
            _keyspaceName = keyspaceName;
            _initialize   = true;
            _lock         = new Lock();

            _currentCollections = new ArrayRig <RowCollection>();

            // if the name wasn't set
            Name = Name == null?this.GetType().Name.ToLowercase() : Name.ToLowercase();

            // populate the columns
            Columns = new ArrayRig <Column>();

            // iterate properties
            foreach (PropertyInfo info in this.GetType().GetProperties(
                         BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
            {
                if (info.PropertyType.BaseType == typeof(Column))
                {
                    // get the column attribute
                    ColumnAttribute attribute = info.GetCustomAttribute <ColumnAttribute>(true);

                    // if the attribute isn't found - assume default values
                    if (attribute == null)
                    {
                        attribute = new ColumnAttribute(Column.ColumnClass.Data, info.Name);
                    }

                    // get the column value if it's been set
                    Column column = (Column)info.GetValue(this);

                    // if the column hasn't been assigned
                    if (column == null)
                    {
                        // create a new instance of the column
                        IFunc <ColumnAttribute, Column> activator = Dynamic.Constructor <IFunc <ColumnAttribute, Column> >(info.PropertyType);
                        if (attribute.Name == null)
                        {
                            attribute.Name = info.Name;
                        }
                        activator.ArgA = attribute;
                        column         = activator.Run();
                        info.SetValue(this, column);
                    }

                    // add the column to the collection
                    Columns.Add(column);
                }
            }

            // iterate fields
            foreach (FieldInfo info in this.GetType().GetFields(
                         BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
            {
                if (info.FieldType.BaseType == typeof(Column))
                {
                    // get the column attribute
                    ColumnAttribute attribute = info.GetCustomAttribute <ColumnAttribute>(true);

                    // if the attribute isn't found - assume default values
                    if (attribute == null)
                    {
                        attribute = new ColumnAttribute(Column.ColumnClass.Data, info.Name);
                    }

                    // get the column value if it's been set
                    Column column = (Column)info.GetValue(this);

                    // if the column hasn't been assigned
                    if (column == null)
                    {
                        // create a new instance of the column
                        IFunc <ColumnAttribute, Column> activator = Dynamic.Constructor <FuncSet <ColumnAttribute, Column> >(info.FieldType);
                        if (attribute.Name == null)
                        {
                            attribute.Name = info.Name;
                        }
                        activator.ArgA = attribute;
                        column         = activator.Run();
                        info.SetValue(this, column);
                    }

                    // add the column to the collection
                    Columns.Add(column);
                }
            }
        }