コード例 #1
0
        /// <summary>
        /// Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.
        /// </summary>
        /// <param name="value">a string value to be split and assigned to AnyValueArray</param>
        /// <param name="separator">a separator to split the string</param>
        /// <param name="removeDuplicates">(optional) true to remove duplicated elements</param>
        /// <returns>a newly created AnyValueArray.</returns>
        public static AnyValueArray FromString(string value, char separator, bool removeDuplicates)
        {
            var result            = new AnyValueArray();
            HashSet <string> hash = null;

            if (string.IsNullOrEmpty(value))
            {
                return(result);
            }

            var items = value.Split(separator);

            foreach (var item in items)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    if (removeDuplicates)
                    {
                        if (hash == null)
                        {
                            hash = new HashSet <string>();
                        }
                        if (hash.Contains(item))
                        {
                            continue;
                        }
                        hash.Add(item);
                    }
                    result.Add(item != null ? new AnyValue(item) : null);
                }
            }

            return(result);
        }
コード例 #2
0
        public static SortParams FromValue(object value)
        {
            if (value is SortParams)
            {
                return((SortParams)value);
            }

            var array = value != null?AnyValueArray.FromValue(value) : new AnyValueArray();

            return(new SortParams(array));
        }
コード例 #3
0
        /// <summary>
        /// Converts specified value into ProjectionParams.
        /// </summary>
        /// <param name="value">value to be converted</param>
        /// <returns>a newly created ProjectionParams.</returns>
        /// See <see cref="AnyValueArray.FromValue(object)"/>
        public static ProjectionParams FromValue(object value)
        {
            if (value is ProjectionParams)
            {
                return((ProjectionParams)value);
            }

            var array = value != null?AnyValueArray.FromValue(value) : new AnyValueArray();

            return(new ProjectionParams(array));
        }
コード例 #4
0
        /// <summary>
        /// Creates a new instance of the projection parameters and assigns its value.
        /// </summary>
        /// <param name="values">(optional) values to initialize this object.</param>
        public ProjectionParams(AnyValueArray array)
        {
            if (array == null)
            {
                return;
            }

            for (int index = 0; index < array.Count; index++)
            {
                var value = array.GetAsString(index);
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Add(value);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Creates a new instance and initializes it with specified sort fields.
        /// </summary>
        /// <param name="array">a list of fields to sort by.</param>
        public SortParams(AnyValueArray array)
        {
            if (array == null)
            {
                return;
            }

            for (int index = 0; index < array.Count; index++)
            {
                var value = array.GetAsValue(index);

                if (value != null)
                {
                    var map = value.GetAsMap();

                    if (map != null)
                    {
                        Add(new SortField(map.GetAsStringWithDefault("name", null), map.GetAsBooleanWithDefault("ascending", true)));
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Converts array element into an AnyValueArray or returns default value if conversion is not possible.
        /// </summary>
        /// <param name="index">an index of element to get.</param>
        /// <param name="defaultValue">the default value</param>
        /// <returns>AnyValueArray value of the element or default value if conversion is not supported.</returns>
        public AnyValueArray GetAsArrayWithDefault(int index, AnyValueArray defaultValue)
        {
            var result = GetAsNullableArray(index);

            return(result ?? defaultValue);
        }
コード例 #7
0
        /// <summary>
        /// Converts map element into an AnyValueArray or returns default value if conversion is not possible.
        /// </summary>
        /// <param name="key">a key of element to get.</param>
        /// <param name="defaultValue">the default value</param>
        /// <returns>AnyValueArray value of the element or default value if conversion is not supported.</returns>
        /// See <see cref="GetAsNullableArray(string)"/>
        public AnyValueArray GetAsArrayWithDefault(string key, AnyValueArray defaultValue)
        {
            var value = GetAsNullableArray(key);

            return(value != null ? value : defaultValue);
        }
コード例 #8
0
 /// <summary>
 /// Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.
 /// </summary>
 /// <param name="key">a key of element to get.</param>
 /// <returns>AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.</returns>
 /// See <see cref="AnyValueArray.FromValue(object)"/>
 public AnyValueArray GetAsArray(string key)
 {
     return(AnyValueArray.FromValue(GetAsObject(key)));
 }
コード例 #9
0
        /// <summary>
        /// Converts map element into an AnyValueArray or returns null if conversion is not possible.
        /// </summary>
        /// <param name="key">a key of element to get.</param>
        /// <returns>AnyValueArray value of the element or null if conversion is not supported.</returns>
        /// See <see cref="AnyValueArray"/>
        public AnyValueArray GetAsNullableArray(string key)
        {
            var value = GetAsObject(key);

            return(value != null?AnyValueArray.FromValue(value) : null);
        }
コード例 #10
0
 /// <summary>
 /// Converts object value into an AnyArray or returns empty AnyArray if conversion is not possible.
 /// </summary>
 /// <returns>AnyArray value or empty AnyArray if conversion is not supported.</returns>
 /// See <see cref="AnyValueArray.FromValue(object)"/>
 public AnyValueArray GetAsArray()
 {
     return(AnyValueArray.FromValue(Value));
 }
コード例 #11
0
        /// <summary>
        /// Converts map element into an AnyValueArray or returns default value if conversion is not possible.
        /// </summary>
        /// <param name="key">a key of element to get.</param>
        /// <param name="defaultValue">the default value</param>
        /// <returns>AnyValueArray value of the element or default value if conversion is not supported.</returns>
        /// See <see cref="GetAsNullableArray(string)"/>
        public AnyValueArray GetAsArrayWithDefault(string key, AnyValueArray defaultValue)
        {
            var result = GetAsNullableArray(key);

            return(result ?? defaultValue);
        }
コード例 #12
0
        /// <summary>
        /// Converts map element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.
        /// </summary>
        /// <param name="key">a key of element to get.</param>
        /// <returns>AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.</returns>
        /// See <see cref="AnyValueArray.FromValue(object)"/>
        public AnyValueArray GetAsArray(string key)
        {
            var value = GetAsObject(key);

            return(AnyValueArray.FromValue(key));
        }