Candor.Web.Mvc.HtmlHelperExtension.AnonymousObjectToHtmlAttributesMvc2 C# (CSharp) 메소드

AnonymousObjectToHtmlAttributesMvc2() 공개 정적인 메소드

An enhancement to the MVC3 same named method that takes into account other dictionary types not being double decoded.
public static AnonymousObjectToHtmlAttributesMvc2 ( this htmlHelper, object htmlAttributes ) : RouteValueDictionary
htmlHelper this
htmlAttributes object An anonymous object, RouteValueDictionary, or IDictionary of string,object.
리턴 RouteValueDictionary
        public static RouteValueDictionary AnonymousObjectToHtmlAttributesMvc2(this HtmlHelper htmlHelper, object htmlAttributes)
        {
            //originally copied from MVC3 source
            if (htmlAttributes is RouteValueDictionary)
                return (RouteValueDictionary)htmlAttributes; //<- this is not in the base MVC3 version - Too bad.

            if (htmlAttributes is IDictionary<string, object>)
                return new RouteValueDictionary((IDictionary<string, object>)htmlAttributes); //<- this is not in the base MVC3 version - Too bad.

            var result = new RouteValueDictionary();
            if (htmlAttributes != null)
            {
                foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes))
                {
                    result.Add(property.Name.Replace('_', '-'), property.GetValue(htmlAttributes));
                }
            }
            return result;
        }