Пример #1
0
 // This helper is a workaround for the fact that Enum.Defined() does not work on non-public enums.
 // There is a custom attribute in System.Reflection.Metadata.Controls that would make it work
 // but we don't want to introduce a dependency on that contract just to support two asserts.
 public static bool IsValidQueryAggregationOption(this QueryAggregationOptions value)
 {
     return(value == QueryAggregationOptions.None ||
            value == QueryAggregationOptions.Associative ||
            value == QueryAggregationOptions.Commutative ||
            value == QueryAggregationOptions.AssociativeCommutative);
 }
Пример #2
0
        //---------------------------------------------------------------------------------------
        // Constructs a new instance of an associative operator.
        //
        // Assumptions:
        //     This operator must be associative.
        //

        internal AssociativeAggregationOperator(IEnumerable <TInput> child, TIntermediate seed, Func <TIntermediate> seedFactory, bool seedIsSpecified,
                                                Func <TIntermediate, TInput, TIntermediate> intermediateReduce,
                                                Func <TIntermediate, TIntermediate, TIntermediate> finalReduce,
                                                Func <TIntermediate, TOutput> resultSelector, bool throwIfEmpty, QueryAggregationOptions options)
            : base(child)
        {
            Contract.Assert(child != null, "child data source cannot be null");
            Contract.Assert(intermediateReduce != null, "need an intermediate reduce function");
            Contract.Assert(finalReduce != null, "need a final reduce function");
            Contract.Assert(resultSelector != null, "need a result selector function");
            Contract.Assert(options.IsValidQueryAggregationOption(), "enum out of valid range");
            Contract.Assert((options & QueryAggregationOptions.Associative) == QueryAggregationOptions.Associative, "expected an associative operator");
            Contract.Assert(typeof(TIntermediate) == typeof(TInput) || seedIsSpecified, "seed must be specified if TIntermediate differs from TInput");

            _seed               = seed;
            _seedFactory        = seedFactory;
            _seedIsSpecified    = seedIsSpecified;
            _intermediateReduce = intermediateReduce;
            _finalReduce        = finalReduce;
            _resultSelector     = resultSelector;
            _throwIfEmpty       = throwIfEmpty;
        }
 internal AssociativeAggregationOperator(IEnumerable <TInput> child, TIntermediate seed, Func <TIntermediate> seedFactory, bool seedIsSpecified, Func <TIntermediate, TInput, TIntermediate> intermediateReduce, Func <TIntermediate, TIntermediate, TIntermediate> finalReduce, Func <TIntermediate, TOutput> resultSelector, bool throwIfEmpty, QueryAggregationOptions options) : base(child)
 {
     this.m_seed               = seed;
     this.m_seedFactory        = seedFactory;
     this.m_seedIsSpecified    = seedIsSpecified;
     this.m_intermediateReduce = intermediateReduce;
     this.m_finalReduce        = finalReduce;
     this.m_resultSelector     = resultSelector;
     this.m_throwIfEmpty       = throwIfEmpty;
 }