src/EasyFrameWork/Reflection/ClassAction.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Easy.Reflection
{
public class ClassAction
{
/// <summary>
/// 取出类的属性值
/// </summary>
/// <typeparam name="T">类别</typeparam>
/// <param name="obj">对象</param>
/// <returns>返回字典</returns>
public static Dictionary<string, object> GetPropertieValues<T>(T obj)
{
Type objType = typeof(T);
var properties = objType.GetProperties();
return properties.Where(item => item.GetValue(obj, null) != null).ToDictionary(item => item.Name, item => item.GetValue(obj, null));
}
/// <summary>
/// 获取属性值
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="item">类型实例</param>
/// <param name="property">属性名称</param>
/// <returns>属性值</returns>
public static object GetPropertyValue<T>(T item, string property)
{
Type entityType = typeof(T);
PropertyInfo proper = entityType.GetProperty(property);
if (proper != null && proper.CanRead)
{
return proper.GetValue(item, null);
}
else return null;
}
public static object GetObjPropertyValue(object item, string property)
{
Type entityType = item.GetType();
PropertyInfo proper = entityType.GetProperty(property);
if (proper != null && proper.CanRead)
{
return proper.GetValue(item, null);
}
else return null;
}
/// <summary>
/// 设置属性值
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="item"></param>
/// <param name="property"></param>
后面还有 68 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。