Sunday, November 16, 2014

HTML Decode field of object

  /// <summary>
        /// HTML Decode field of object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="field"></param>
        public static void HtmlDecode<T>(T item, string field)
        {
            Type type;
            PropertyInfo fieldPropertyInfo;
            type = item.GetType();
            fieldPropertyInfo = type.GetProperty(field);
            if (fieldPropertyInfo.PropertyType == typeof(string))
                fieldPropertyInfo.SetValue(item, HttpUtility.HtmlDecode(Convert.ToString(fieldPropertyInfo.GetValue(item, null))), null);
        }

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...