/// <summary>
        /// Creates a QueryCollectionType which implements IQueryClrType so that codegen creates the right list type
        /// </summary>
        /// <typeparam name="TQueryType">The element type of the Collection</typeparam>
        /// <param name="queryType">The query type of the Collection</param>
        /// <param name="clrTypeDefinition">The generic type definition of the collection type, e.g.: List&lt;&gt; </param>
        /// <returns>A QueryClrCollectionType which is used as a hint by Code Generation</returns>
        public static QueryClrCollectionType <TQueryType> ToClrType <TQueryType>(QueryCollectionType queryType, Type clrTypeDefinition) where TQueryType : QueryType
        {
            ExceptionUtilities.CheckArgumentNotNull(clrTypeDefinition, "clrTypeDefinition");
            ExceptionUtilities.Assert(clrTypeDefinition.IsGenericTypeDefinition(), "clrTypeDefinition is not a generic type definition");
            TQueryType elementType = queryType.ElementType as TQueryType;

            return(CreateClrType <TQueryType>(elementType, clrTypeDefinition));
        }
Exemple #2
0
        /// <summary>
        /// Gets the non-strongly typed collection type for this type.
        /// </summary>
        /// <returns>
        /// Instance of <see cref="QueryCollectionType"/> which is a collection of this type.
        /// </returns>
        protected override QueryCollectionType CreateCollectionTypeInternal()
        {
            if (this.queryCollectionType == null)
            {
                this.queryCollectionType = QueryCollectionType.Create(this);
            }

            return((QueryCollectionType)this.queryCollectionType);
        }
        /// <summary>
        /// Creates the typed collection where element type is the current structural type.
        /// </summary>
        /// <returns>Collection of the given type.</returns>
        public new QueryCollectionType <QueryStructuralType> CreateCollectionType()
        {
            if (this.queryCollectionType == null)
            {
                this.queryCollectionType = QueryCollectionType.Create(this);
            }

            return((QueryCollectionType <QueryStructuralType>) this.queryCollectionType);
        }
        /// <summary>
        /// Creates the typed collection where element type is the current primitive type.
        /// </summary>
        /// <returns>Collection of the given type.</returns>
        public new QueryCollectionType <QueryReferenceType> CreateCollectionType()
        {
            if (this.collectionType == null)
            {
                this.collectionType = QueryCollectionType.Create(this);
            }

            return((QueryCollectionType <QueryReferenceType>) this.collectionType);
        }
        /// <summary>
        /// Applies a projection operator which selects a value from each collection element.
        /// </summary>
        /// <param name="selector">The selector.</param>
        /// <param name="resultType">Type of the result</param>
        /// <returns>
        /// Collection of values containing results of the selector applied to all elements of the collection.
        /// </returns>
        public QueryCollectionValue Select(Func <QueryValue, QueryValue> selector, QueryCollectionType resultType)
        {
            ExceptionUtilities.CheckArgumentNotNull(selector, "selector");
            IEnumerable <QueryValue> result = null;

            if (!this.IsNull)
            {
                result = this.Elements.Cast <QueryValue>().Select(e => selector(e)).ToList();
            }

            return(new QueryCollectionValue(resultType, this.EvaluationStrategy, QueryError.GetErrorFromValues(result), result, this.IsSorted));
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the QueryGroupingType class.
        /// </summary>
        /// <param name="keyType">Type of the grouping key.</param>
        /// <param name="elementType">Type of the grouping element.</param>
        /// <param name="evaluationStrategy">Evaluation strategy.</param>
        public QueryGroupingType(QueryType keyType, QueryType elementType, IQueryEvaluationStrategy evaluationStrategy)
            : base(evaluationStrategy)
        {
            this.Key         = QueryProperty.Create("Key", keyType);
            this.elementType = elementType;

            QueryCollectionType collectionType = elementType.CreateCollectionType();

            this.Elements = QueryProperty.Create("Elements", collectionType);

            this.AddProperties(new[] { this.Key, this.Elements });
            this.MakeReadOnly();
        }
        /// <summary>
        /// Initializes a new instance of the QueryCollectionValue class.
        /// </summary>
        /// <param name="type">The collection type.</param>
        /// <param name="evaluationStrategy">The evaluation strategy.</param>
        /// <param name="evaluationError">The evaluation error.</param>
        /// <param name="elements">The elements.</param>
        /// <param name="isSorted">Determines whether the collection is sorted.</param>
        public QueryCollectionValue(QueryCollectionType type, IQueryEvaluationStrategy evaluationStrategy, QueryError evaluationError, IEnumerable <QueryValue> elements, bool isSorted)
            : base(evaluationError, evaluationStrategy)
        {
            ExceptionUtilities.CheckArgumentNotNull(type, "type");

            this.IsSorted = isSorted;
            this.Type     = type;
            if (elements == null)
            {
                this.Elements = null;
            }
            else
            {
                this.Elements = elements.ToList();
            }
        }
Exemple #8
0
        /// <summary>
        /// Creates a strongly-typed QueryProperty of T
        /// </summary>
        /// <typeparam name="TElement">The type of the collection element.</typeparam>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="propertyType">Type of the property.</param>
        /// <returns>Strongly typed QueryProperty of T.</returns>
        public static QueryProperty <QueryCollectionType <TElement> > Create <TElement>(string propertyName, QueryCollectionType <TElement> propertyType)
            where TElement : QueryType
        {
            ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName");
            ExceptionUtilities.CheckArgumentNotNull(propertyType, "propertyType");

            return(new QueryProperty <QueryCollectionType <TElement> >(propertyName, propertyType));
        }
        private void ComputeSelectResult(Func <QueryValue, QueryValue> selector, out IEnumerable <QueryValue> result, out QueryCollectionType resultType)
        {
            // compute the result type by applying predicate to a NULL value
            var nullElement         = this.Type.ElementType.NullValue;
            var selectedElementType = selector(nullElement).Type;

            resultType = selectedElementType.CreateCollectionType();
            result     = null;

            if (!this.IsNull)
            {
                result = this.Elements.Select(e => selector(e));
            }
        }
 /// <summary>
 /// Initializes a new instance of the QueryCollectionValue class.
 /// </summary>
 /// <param name="type">The collection type.</param>
 /// <param name="evaluationStrategy">The evaluation strategy.</param>
 /// <param name="evaluationError">The evaluation error.</param>
 /// <param name="elements">The elements.</param>
 public QueryCollectionValue(QueryCollectionType type, IQueryEvaluationStrategy evaluationStrategy, QueryError evaluationError, IEnumerable <QueryValue> elements)
     : this(type, evaluationStrategy, evaluationError, elements, false)
 {
 }