C# 处理实体类赋值(获取嵌套类型,支持list 自定义类型)
2024-10-20 20:43:00
public static T AESEncrypt<T>(T obj) where T : class
{
if (obj == null)
{
return obj;
} var properties = typeof(T).GetProperties(); foreach (System.Reflection.PropertyInfo info in properties)
{
if (info.GetMethod.ReturnType.Name == typeof(string).Name)
{
if (obj.GetType().GetProperty(info.Name).GetValue(obj, null) != null)
{
string plaintext = obj.GetType().GetProperty(info.Name).GetValue(obj, null).ToString();
string ciphertext = PEIS_Interface_HN.Common.AESUtils.Encrypt_Hex(plaintext, "db6d159a3b341cc53373aab7f72ccb1896b88782", "");
obj.GetType().GetProperty(info.Name).SetValue(obj, ciphertext);
}
}
else if (info.PropertyType.IsGenericType)//info.GetMethod.ReturnType.Name == typeof(List<>).Name )
{
var list = obj.GetType().GetProperty(info.Name).GetValue(obj, null) as IList;
if (list != null)
{
foreach (var item in list)
{
var ps = item.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo i in ps)
{ if (i.GetMethod.ReturnType.Name == typeof(string).Name)
{
if (item.GetType().GetProperty(i.Name).GetValue(item, null) != null)
{
string plaintext = item.GetType().GetProperty(i.Name).GetValue(item, null).ToString();
string ciphertext = PEIS_Interface_HN.Common.AESUtils.Encrypt_Hex(plaintext, "db6d159a3b341cc53373aab7f72ccb1896b88782", "");
item.GetType().GetProperty(i.Name).SetValue(item, ciphertext);
}
}
else if (i.PropertyType.IsClass&&!i.PropertyType.IsGenericType)
{
object propertyValue = i.GetValue(item);
if (propertyValue != null)
{ foreach (var it in propertyValue.GetType().GetProperties())
{
string plaintext = it.GetValue(propertyValue)==null ?string.Empty:it.GetValue(propertyValue).ToString();
string ciphertext = PEIS_Interface_HN.Common.AESUtils.Encrypt_Hex(plaintext, "db6d159a3b341cc53373aab7f72ccb1896b88782", "");
it.SetValue(propertyValue, ciphertext);
} }
}
else if (i.GetMethod.ReturnType.Name == typeof(List<>).Name)
{
var zlist = item.GetType().GetProperty(i.Name).GetValue(item, null) as IList;
if (zlist != null)
{
foreach (var it in zlist)
{
var p = it.GetType().GetProperties();
foreach (System.Reflection.PropertyInfo zi in p)
{ if (zi.GetMethod.ReturnType.Name == typeof(string).Name)
{
if (it.GetType().GetProperty(zi.Name).GetValue(it, null) != null)
{
string plaintext = it.GetType().GetProperty(zi.Name).GetValue(it, null).ToString();
string ciphertext = PEIS_Interface_HN.Common.AESUtils.Encrypt_Hex(plaintext, "db6d159a3b341cc53373aab7f72ccb1896b88782", "");
it.GetType().GetProperty(zi.Name).SetValue(it, ciphertext);
}
}
}
}
} } } } } } }
return obj;
}
最新文章
- 车牌号对应归属地及城市JSON带简码
- Qt拖拽界面 (*.ui) 缩放问题及解决办法(在最顶层放一个Layout)
- 函数xdes_init
- OpenJudge/Poj 1191 棋盘分割
- QT 自定义assert
- Spring MVC 中的 forward 和 redirect
- Android 点击事件,4种回调。
- 关于jsp中超链接的相对路径
- 机器学习实战__安装python环境
- 图片输出onerror事件
- adb调试实用命令
- java web每天定时执行任务(四步轻松搞定)
- RxSwift 系列(三) -- Combination Operators
- Java多线程:wait(),notify(),notifyAll()
- C# 跳转新的标签页
- 题解-洛谷P1303 A*B Problem(高精)
- metasploit 教程之信息收集
- CCF CSP 201509-1 数列分段
- Android破解学习之路(十六)—— dll破解的IL指令
- ACM-ICPC 2017 Asia Xi&#39;an A XOR (线性基+线段树思想)
热门文章
- Linux学习环境搭建流程
- 微信小程序canvas 证件照制作
- [C++] - GCC和LLVM对方法 warning: non-void function does not return a value [-Wreturn-type] 的处理差异
- Java安全之Mojarra JSF反序列化
- lambda、map、reduce、filter、sorted函数
- 学习ASP.NET Core Blazor编程系列十——路由(下)
- vue项目中,alert使用
- 云小课|云小课教您如何选择Redis实例类型
- TabControl控件的简单使用-添加tab
- ATM购物车项目总结