/// <summary>
        /// Initializes a new instance of the <see cref="DataAnnotationsPropertyMetadata"/> class.
        /// </summary>
        /// <param name="queryParameterAttribute">The <see cref="QueryParameterAttribute"/>.</param>
        /// <param name="propertyInfo">The <see cref="PropertyInfo"/> from which the base class should retrieve its information about the property.</param>
        /// <param name="realPropertyInfo">The real <see cref="PropertyInfo"/> for further processing.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyInfo" />' and '<paramref name="realPropertyInfo" />' cannot be null. </exception>
        public DataAnnotationsPropertyMetadata(QueryParameterAttribute queryParameterAttribute, [NotNull] PropertyInfo propertyInfo, [NotNull] PropertyInfo realPropertyInfo)
            : base(queryParameterAttribute, propertyInfo)
        {
            if (realPropertyInfo == null)
            {
                throw new ArgumentNullException(nameof(realPropertyInfo));
            }

            this.realPropertyInfo = realPropertyInfo;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyMetadata"/> class.
        /// </summary>
        /// <param name="queryParameterAttribute">The <see cref="QueryParameterAttribute"/>.</param>
        /// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyInfo" />' cannot be null. </exception>
        public PropertyMetadata([CanBeNull] QueryParameterAttribute queryParameterAttribute, [NotNull] PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            this.queryParameterAttribute = queryParameterAttribute;
            this.propertyInfo            = propertyInfo;
        }
        public static string GetQueryParamters(this object obj)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                foreach (object attr in attrs)
                {
                    QueryParameterAttribute parameterAttribute = attr as QueryParameterAttribute;
                    if (parameterAttribute != null)
                    {
                        dict.Add(parameterAttribute.Name, prop.GetValue(obj, null)?.ToString() ?? string.Empty);
                        break;
                    }
                }
            }

            return(GetQueryParameters(dict));
        }
Exemple #4
0
        /// <summary>
        /// Get Custom Attribute Property Name
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        private static QueryParameterAttribute GetQueryParameterValue(this PropertyInfo prop)
        {
            var customAttribute = prop.GetCustomAttributes(typeof(QueryParameterAttribute), false);
            var parameters      = new QueryParameterAttribute()
            {
                PropertyName = prop.Name, IsQuerystring = true
            };

            if (customAttribute.Length > 0)
            {
                var attr = customAttribute.FirstOrDefault() as QueryParameterAttribute;

                if (attr != null)
                {
                    parameters.HasPropertyName = !string.IsNullOrWhiteSpace(attr.PropertyName);
                    parameters.PropertyName    = !string.IsNullOrWhiteSpace(attr.PropertyName) ? attr.PropertyName : prop.Name;
                    parameters.IsQuerystring   = attr.IsQuerystring;
                }
            }

            return(parameters);
        }
Exemple #5
0
        public void Constructor_SetsName()
        {
            var sut = new QueryParameterAttribute(_name);

            sut.Name.Should().Be(_name);
        }