/// <summary>
        ///     Places the given column into the given column role.
        /// </summary>
        /// <param name="columnRole">
        ///     The role into which to place the column.
        /// </param>
        /// <param name="column">
        ///     The column to place into the role.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="column"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="InvalidEnumArgumentException">
        ///     <paramref name="columnRole"/> is not a valid member of the
        ///     <see cref="ColumnRole"/> enumeration.
        ///     - or -
        ///     <paramref name="columnRole"/> is equal to <see cref="ColumnRole.CountColumnMetadata"/>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        ///     <paramref name="column"/> is a metadata column (see <see cref="AllMetadataColumns"/>.
        /// </exception>
        public void AddColumnRole(ColumnRole columnRole, ColumnConfiguration column)
        {
            Guard.NotNull(column, nameof(column));

            Guard.NotNull(column.Metadata, nameof(column.Metadata));

            AddColumnRole(columnRole, column.Metadata.Guid);
        }
        /// <summary>
        ///     Adds a new column to the builder with the given
        ///     configuration and projection.
        /// </summary>
        /// <typeparam name="T">
        ///     The <see cref="Type"/> of data being projected.
        /// </typeparam>
        /// <param name="self">
        ///     The builder instance.
        /// </param>
        /// <param name="column">
        ///     The column configuration the added column is to have.
        /// </param>
        /// <param name="projection">
        ///     The projection the added column is to have.
        /// </param>
        /// <returns>
        ///     The builder instance.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="column"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="projection"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static ITableBuilderWithRowCount AddColumn <T>(
            this ITableBuilderWithRowCount self,
            ColumnConfiguration column,
            IProjection <int, T> projection)
        {
            Guard.NotNull(self, nameof(self));
            Guard.NotNull(projection, nameof(projection));

            return(self.AddColumn(new BaseDataColumn <T>(column, projection)));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="BaseDataColumn{T}" />
        ///     class.
        /// </summary>
        /// <param name="configuration">
        ///     The configuration of this column.
        /// </param>
        /// <param name="projection">
        ///     The projection that projects the data in the column.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="configuration"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="projection"/> is <c>null</c>.
        /// </exception>
        public BaseDataColumn(
            ColumnConfiguration configuration,
            IProjection <int, T> projection)
        {
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(projection, nameof(projection));

            this.Configuration      = configuration;
            this.ProjectorInterface = projection.GetType();
            this.Projector          = projection;
        }
        /// <summary>
        ///     Determines if the given <see cref="ColumnConfiguration"/>
        ///     is considered to be a metadata column. The metadata columns
        ///     are found in the <see cref="TableConfiguration"/> class,
        ///     for example <see cref="TableConfiguration.PivotColumn"/>.
        /// </summary>
        /// <param name="self">
        ///     The column to check.
        /// </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="self"/> is one of the <see cref="TableConfiguration"/>
        ///     metadata columns; <c>false</c> otherwise.
        /// </returns>
        public static bool IsMetadataColumn(this ColumnConfiguration self)
        {
            if (self is null)
            {
                return(false);
            }

            return(TableConfiguration.AllMetadataColumns.Contains(
                       self,
                       ColumnConfigurationEqualityComparer.Default));
        }
        /// <summary>
        ///     Adds a new hierarchical column to the builder with the given
        ///     configuration, projection, and info providers.
        /// </summary>
        /// <typeparam name="T">
        ///     The <see cref="Type"/> of data being projected.
        /// </typeparam>
        /// <param name="self">
        ///     The builder instance.
        /// </param>
        /// <param name="column">
        ///     The column configuration the added column is to have.
        /// </param>
        /// <param name="projection">
        ///     The projection the added column is to have.
        /// </param>
        /// <param name="collectionProvider">
        ///     The collection provider for the column.
        /// </param>
        /// <returns>
        ///     The builder instance.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="collectionProvider"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="column"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="projection"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static ITableBuilderWithRowCount AddHierarchicalColumn <T>(
            this ITableBuilderWithRowCount self,
            ColumnConfiguration column,
            IProjection <int, T> projection,
            ICollectionInfoProvider <T> collectionProvider)
        {
            Guard.NotNull(self, nameof(self));
            Guard.NotNull(projection, nameof(projection));
            Guard.NotNull(collectionProvider, nameof(collectionProvider));

            return(self.AddColumn(new HierarchicalDataColumn <T>(column, projection, collectionProvider)));
        }
        /// <summary>
        ///     Creates a new <see cref="ColumnConfiguration"/> that
        ///     is a clone of the given ColumnConfiguration, except
        ///     for the name projection, which is replaced by the given
        ///     name projection.
        /// </summary>
        /// <param name="self">
        ///     The <see cref="ColumnConfiguration"/> to be modified.
        /// </param>
        /// <param name="nameProjection">
        ///     The new name projection.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="nameProjection"/> is <c>null</c>.
        /// </exception>
        public static ColumnConfiguration WithDynamicName(
            this ColumnConfiguration self,
            IProjection <int, string> nameProjection)
        {
            var newConfiguration = new ColumnConfiguration(
                new ColumnMetadata(
                    self.Metadata.Guid,
                    self.Metadata.Name,
                    nameProjection,
                    self.Metadata.Description),
                self.DisplayHints);

            return(newConfiguration);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HierarchicalDataColumn{T}"/>
        ///     class.
        /// </summary>
        /// <param name="configuration">
        ///     The configuration of this column.
        /// </param>
        /// <param name="projection">
        ///     The projection that projects the data in the column.
        /// </param>
        /// <param name="collectionProvider">
        ///     The providers that define how to display the hierarchical data.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="configuration"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="projection"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="collectionProvider"/> is <c>null</c>.
        /// </exception>
        public HierarchicalDataColumn(
            ColumnConfiguration configuration,
            IProjection <int, T> projection,
            ICollectionInfoProvider <T> collectionProvider)
            : base(configuration, projection)
        {
            Guard.NotNull(collectionProvider, nameof(collectionProvider));

            Type collectionOutputType = null;

            foreach (var i in collectionProvider.GetType().GetInterfaces())
            {
                if (i.IsGenericType)
                {
                    var genericInterface = i.GetGenericTypeDefinition();
                    if (genericInterface == typeof(ICollectionAccessProvider <,>))
                    {
                        Type collectionInputType = i.GetGenericArguments()[0];
                        collectionOutputType = i.GetGenericArguments()[1];
                        if (collectionInputType != typeof(T))
                        {
                            throw new InvalidOperationException(
                                      $"TCollection on the ICollectionAccessProvider<TCollection, TElement>implemented on " +
                                      $"{nameof(collectionProvider)} doesn't match T of {nameof(HierarchicalDataColumn<T>)} from column " +
                                      $"{configuration.Metadata.Guid}. TCollection = {collectionInputType.Name}, T = {typeof(T).Name}");
                        }

                        break;
                    }
                }
            }

            if (collectionOutputType == null)
            {
                throw new InvalidOperationException(
                          $"No valid ICollectionAccessProvider<,> found on {nameof(HierarchicalDataColumn<T>)} {configuration.Metadata.Guid}.");
            }

            this.CollectionInfoProvider = collectionProvider;
        }
 /// <summary>
 ///     Sets the format provider for the given configuration.
 /// </summary>
 /// <param name="self">
 ///     The <see cref="ColumnConfiguration"/> to be modified.
 /// </param>
 /// <param name="formatProvider">
 ///     The new <see cref="IFormatProvider"/> for the configuration.
 ///     This parameter may be <c>null</c>.
 /// </param>
 public static void SetFormatProvider(
     this ColumnConfiguration self,
     IFormatProvider formatProvider)
 {
     self.Metadata.FormatProvider = formatProvider;
 }