示例#1
0
        public static Dictionary<string, object> toDictionary<T>(this T entity) where T : IEntity
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            Type type = entity.GetType();
            var properties = type.GetProperties();
            EntityAttribute temp = null;

            foreach (PropertyInfo property in properties)
            {
                temp = property.GetEntity();
                result.Add(temp.ColumnName, property.GetValue(temp.ColumnName));
            }

            return result;
        }
示例#2
0
        public static EntityAttribute GetEntity(this PropertyInfo property)
        {
            EntityAttribute result = null;

            EntityAttribute temp;
            foreach (var attr in property.GetCustomAttributes())
            {
                temp = attr as EntityAttribute;
                if (temp != null)
                {
                    result = temp;
                    break;
                }
            }

            return result;
        }
示例#3
0
        public static object GetValue<T>(this T entity, string columnName) where T : IEntity
        {
            object result = null;

            Type type = entity.GetType();
            var properties = type.GetProperties();
            EntityAttribute temp = null;

            foreach (PropertyInfo property in properties)
            {
                temp = property.GetEntity();
                if (temp != null && temp.ColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase))
                {
                    result = property.GetValue(entity);
                    break;
                }
            }

            return result;
        }