Пример #1
0
        /// <summary>
        /// Convert query's string to array of query parts.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="spliter">Char that will be used as query part spliter.</param>
        /// <returns></returns>
        public static QueryPart[] DetectQueryParts(string query, char spliter)
        {
            // Get query parts in string format.
            string[] splitedQuery = query.Split(spliter);

            // Init list.
            QueryPart[] parts = new QueryPart[splitedQuery.Length];

            // Add parts to array. Will auto converted from string to QueryPart.
            for (int i = 0; i < splitedQuery.Length; i++)
            {
                parts[i] = (QueryPart)splitedQuery[i];
            }

            return(parts);
        }
        /// <summary>
        /// Setting part to listed content.
        /// Update existing if found.
        /// </summary>
        /// <param name="queryPart">Target query part.</param>
        public void SetParam(QueryPart queryPart)
        {
            // Try to get data in listed format.
            var lc = ListedContent;

            // If lsted data not found.
            if (lc == null)
            {
                // Drop if has a binary format of data.
                if (content != null && content.Length > 0)
                {
                    throw new NotSupportedException("Your query contain binary data in not ListedContent compatible view." +
                                                    " Adding query part not possible.");
                }

                // Init listed content.
                lc = new List <QueryPart>
                {
                    queryPart
                };
                ListedContent = lc;
                return;
            }
            else
            {
                // Looking for existed property.
                for (int i = 0; i < lc.Count; i++)
                {
                    // Compare by name.
                    if (lc[i].ParamNameEqual(queryPart.propertyName))
                    {
                        lc[i]         = queryPart; // Set new data.
                        ListedContent = lc;        //  Convert to binary.
                        return;
                    }
                }

                // Add as new if not found.
                lc.Add(queryPart);
                ListedContent = lc; //  Convert to binary.
                return;
            }
        }