/// <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); }
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)); }
/// <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)); }
/// <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); } } }
/// <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))); } } } }
/// <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); }
/// <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); }
/// <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))); }
/// <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); }
/// <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)); }
/// <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); }
/// <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)); }