/// <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)));
        }
Ejemplo n.º 2
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;
        }