Exemple #1
0
        /// <summary>
        /// 将对象属性转换为字典
        /// </summary>
        /// <param name="proMapper">The object.</param>
        /// <returns>Dictionary&lt;System.String, System.Object&gt;.</returns>
        public static Dictionary <string, object> ToDictionary(this IPropertyMapper proMapper)
        {
            if (proMapper == null)
            {
                return(null);
            }
            var dic        = new Dictionary <string, object>();
            var properties = proMapper.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var property in properties)
            {
                var propertyName = proMapper.MapPropertyName(property.Name);
                if (string.IsNullOrEmpty(propertyName))
                {
                    continue;
                }
                dic[propertyName] = property.GetValue(proMapper);
            }
            return(dic);
        }