public string CreateFilterEditor(Property property, PropertyFilterMode mode, string values)
        {
            if (!property.Indexable) return "";

            switch (mode)
            {
                case PropertyFilterMode.Display:
                    return CreateFilterEditorDisplayMode(property);
                case PropertyFilterMode.Selected:
                    return CreateFilterEditorSelectedMode(property, values);
                case PropertyFilterMode.Edit:
                    return CreateFilterEditorEditMode(property, values);
            }
            return "";
        }
        /// <summary>
        /// Automatically create parameters from object properties
        /// </summary>
        /// <param name="request">The REST request to add this parameter to</param>
        /// <param name="obj">Object to serialize to the request body</param>
        /// <param name="objProperties">The object properties</param>
        /// <param name="filterMode">Include or exclude the properties?</param>
        /// <returns>The request object to allow call chains</returns>
        public static IRestRequest AddObject(this IRestRequest request, object obj, IEnumerable<string> objProperties, PropertyFilterMode filterMode)
        {
            var type = obj.GetType();

            var objectProperties = objProperties == null ? null : new HashSet<string>(objProperties);
            var addedProperties = new HashSet<string>();

            while (type != typeof(object))
            {
#if NO_TYPEINFO
                var typeInfo = type;
                var props = typeInfo.GetProperties();
#else
                var typeInfo = type.GetTypeInfo();
                var props = typeInfo.DeclaredProperties;
#endif

                foreach (var prop in props.Where(x => !addedProperties.Contains(x.Name)))
                {
                    bool isAllowed;

                    if (objectProperties == null)
                    {
                        isAllowed = true;
                    }
                    else
                    {
                        if (filterMode == PropertyFilterMode.Include)
                        {
                            isAllowed = objectProperties.Contains(prop.Name);
                        }
                        else
                        {
                            isAllowed = !objectProperties.Contains(prop.Name);
                        }
                    }

                    if (!isAllowed)
                        continue;

                    addedProperties.Add(prop.Name);

                    var propType = prop.PropertyType;
                    var val = prop.GetValue(obj, null);

                    if (val != null)
                    {
                        if (propType.IsArray)
                        {
                            var elementType = propType.GetElementType();
#if NO_TYPEINFO
                            var elementTypeInfo = elementType;
#else
                            var elementTypeInfo = elementType.GetTypeInfo();
#endif

                            if (((Array)val).Length > 0 &&
                                (elementTypeInfo.IsPrimitive || elementTypeInfo.IsValueType || elementType == typeof(string)))
                            {
                                // convert the array to an array of strings
                                var values =
                                    (from object item in ((Array)val) select item.ToString()).ToArray<string>();
                                val = string.Join(",", values);
                            }
                            else
                            {
                                // try to cast it
                                val = string.Join(",", (string[])val);
                            }
                        }

                        request.AddParameter(prop.Name, val);
                    }
                }

                type = typeInfo.BaseType;
            }

            return request;
        }
 public string CreateFilterEditor(Property property, PropertyFilterMode mode, string values)
 {
     return "";
 }
示例#4
0
        /// <summary>
        /// Automatically create parameters from object properties
        /// </summary>
        /// <param name="request">The REST request to add this parameter to</param>
        /// <param name="obj">Object to serialize to the request body</param>
        /// <param name="objProperties">The object properties</param>
        /// <param name="filterMode">Include or exclude the properties?</param>
        /// <returns>The request object to allow call chains</returns>
        public static IRestRequest AddObject(this IRestRequest request, object obj, IEnumerable <string> objProperties, PropertyFilterMode filterMode)
        {
            var type = obj.GetType();

            var objectProperties = objProperties == null ? null : new HashSet <string>(objProperties);
            var addedProperties  = new HashSet <string>();

            while (type != typeof(object))
            {
#if NO_TYPEINFO
                var typeInfo = type;
                var props    = typeInfo.GetProperties();
#else
                var typeInfo = type.GetTypeInfo();
                var props    = typeInfo.DeclaredProperties;
#endif

                foreach (var prop in props.Where(x => !addedProperties.Contains(x.Name)))
                {
                    bool isAllowed;

                    if (objectProperties == null)
                    {
                        isAllowed = true;
                    }
                    else
                    {
                        if (filterMode == PropertyFilterMode.Include)
                        {
                            isAllowed = objectProperties.Contains(prop.Name);
                        }
                        else
                        {
                            isAllowed = !objectProperties.Contains(prop.Name);
                        }
                    }

                    if (!isAllowed)
                    {
                        continue;
                    }

                    addedProperties.Add(prop.Name);

                    var propType = prop.PropertyType;
                    var val      = prop.GetValue(obj, null);

                    if (val != null)
                    {
                        if (propType.IsArray)
                        {
                            var elementType = propType.GetElementType();
#if NO_TYPEINFO
                            var elementTypeInfo = elementType;
#else
                            var elementTypeInfo = elementType.GetTypeInfo();
#endif

                            if (((Array)val).Length > 0 &&
                                (elementTypeInfo.IsPrimitive || elementTypeInfo.IsValueType || elementType == typeof(string)))
                            {
                                // convert the array to an array of strings
                                var values = (from object item in (Array)val select item.ToString()).ToArray();
                                val = string.Join(",", values);
                            }
                            else
                            {
                                // try to cast it
                                val = string.Join(",", (string[])val);
                            }
                        }

                        request.AddParameter(prop.Name, val);
                    }
                }

                type = typeInfo.BaseType;
            }

            return(request);
        }
示例#5
0
        /// <summary>
        /// Port of AddObject to RestSharp.Portable
        /// </summary>
        /// <param name="request">The REST request to add this parameter to</param>
        /// <param name="obj">Object to serialize to the request body</param>
        /// <param name="objProperties">The object properties</param>
        /// <param name="filterMode">Include or exclude the properties?</param>
        /// <returns>The request object to allow call chains</returns>
        public static IRestRequest AddObject(this IRestRequest request, object obj, IEnumerable <string> objProperties, PropertyFilterMode filterMode)
        {
            // automatically create parameters from object props
            var type  = obj.GetType();
            var props = type.GetProperties();

            var objProps = (objProperties == null ? null : objProperties.Where(x => x != null).ToList());

            foreach (var prop in props)
            {
                bool isAllowed;

                if (objProps == null)
                {
                    isAllowed = true;
                }
                else
                {
                    if (filterMode == PropertyFilterMode.Include)
                    {
                        isAllowed = objProps.Contains(prop.Name);
                    }
                    else
                    {
                        isAllowed = !objProps.Contains(prop.Name);
                    }
                }

                if (!isAllowed)
                {
                    continue;
                }

                var propType = prop.PropertyType;
                var val      = prop.GetValue(obj, null);

                if (val != null)
                {
                    if (propType.IsArray)
                    {
                        var elementType = propType.GetElementType();

                        if (((Array)val).Length > 0 &&
                            (elementType.IsPrimitive || elementType.IsValueType || elementType == typeof(string)))
                        {
                            // convert the array to an array of strings
                            var values =
                                (from object item in ((Array)val) select item.ToString()).ToArray <string>();
                            val = string.Join(",", values);
                        }
                        else
                        {
                            // try to cast it
                            val = string.Join(",", (string[])val);
                        }
                    }

                    request.AddParameter(prop.Name, val);
                }
            }

            return(request);
        }