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;
}

C# 处理实体类赋值(获取嵌套类型,支持list 自定义类型)的更多相关文章

  1. C#、Python中分别是怎么实现通过字符串获取实体类的值以及给实体类赋值

    一.引入 最近遇到一个项目里面的功能,在给实体类赋值的时候,由于赋值字段是动态生成的,所以如果用常用的方法(直接实体类的名称.字段名=要赋的值),将会生成很多无用的代码,所以找到了一个通过反射的赋值与 ...

  2. java中遍历实体类,获取属性名和属性值

    方式一(实体类): //java中遍历实体类,获取属性名和属性值 public static void testReflect(Object model) throws Exception{ for ...

  3. 获取jdk支持的编码类型

    //获取jdk支持的编码类型 Map<String,Charset> maps = Charset.availableCharsets(); for(Map.Entry<String ...

  4. C#开发BIMFACE系列9 服务端API之获取应用支持的文件类型

    系列目录     [已更新最新开发文章,点击查看详细] BIMFACE最核心能力之一是工程文件格式转换.无需安装插件,支持数十种工程文件格式在云端转换,完整保留原始文件信息.开发者将告别原始文件解析烦 ...

  5. [转]C#反射,根据反射将数据库查询数据和实体类绑定,并未实体类赋值

    本文来自:http://www.cnblogs.com/mrchenzh/archive/2010/05/31/1747937.html /****************************** ...

  6. 好用的ASP.NET 分页类 简单好用 支持 AJAX 自定义文字

    在做网站没用 JS UI控件时 很实用 用法: var ps=new PageString(); /*可选参数*/ ps.SetIsEnglish = true;// 是否是英文 (默认:false) ...

  7. Android利用反射机制为实体类属性赋值

    在做android项目时,有时会遇到从网络上获取json类型数据,赋值给实体类,实体类属性少可以一个一个的赋值,如果实体类有很多属性,赋值可能就要耗很长的功夫了,幸好Java给我们提供了反射机制.下面 ...

  8. MVC过滤器中获取实体类属性值

    本文地址:http://www.cnblogs.com/outtamyhead/p/3616913.html,转载请保留本地址! 最近在项目遇到了这个问题:获取Action行参中实体类的属性值,主要的 ...

  9. hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题

    因为一直报实体类空异常,去网上查了资料只查到了并没有查到数据库空值时不给实体类赋值的属性 异常 org.hibernate.InvalidMappingException: Could not par ...

  10. iOS开发之使用Runtime给Model类赋值

    本篇博客算是给网络缓存打个基础吧,本篇博客先给出简单也是最容易使用的把字典转成实体类的方法,然后在给出如何使用Runtime来给Model实体类赋值.本篇博客会介绍一部分,主要是字典的key与Mode ...

随机推荐

  1. springboot滚动分页展示列表(类似layui瀑布流效果)

    背景: 公司项目要求获取用户关联的好友列表,要求分页查询,十条数据一页,滚动页面是点击加载更多,显示下一页列表. ​ 示例图: 实现: 本项目采用的前端模板是freemaker,主要前端页面代码(没有 ...

  2. springboot集成支付宝的支付(easy版)

    SpringBoot对接支付宝 需要先注册账号 到支付宝开发者平台创建网页支付应用 启用公钥模式 需要使用到appId和下面的两个秘钥 写配置信息的代码 1.引入依赖 <dependency&g ...

  3. Kubeadm搭建kubernetes集群

    Kubeadm搭建kubernetes集群 环境说明 | 角色 | ip | 操作系统 |组件 | | – | – | – | | master | 192.168.203.100 |centos8 ...

  4. mindxdl--common--http_handler.go

    // Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.// Package common this file ...

  5. 基于python的数学建模---最小二乘拟合

    import numpy as np import matplotlib.pyplot as plt from scipy.optimize import leastsq from matplotli ...

  6. IDEA项目下out与target目录的区别详解

    IDEA项目下out与target目录的区别详解 一.目录主要区别: out存放的是该项目下所有Module(模块)的编译结果. target存放的是单个Module的编译结果. 二.目录详解 out ...

  7. 【离线数仓】Day01-用户行为数据采集:数仓概念、需求及架构、数据生成及采集、linux命令及其他组件常见知识

    一.数据仓库概念 二.项目需求及架构设计 1.需求分析 2.项目框架 3.框架版本选型 服务器选型:云主机 服务器规划 三.数据生成模块 1.数据基本格式 公共字段:所有手机都包含 业务字段:埋点上报 ...

  8. Elasticsearch模糊查询、多字段in查询、时间范围查询,DSL和java API两种方式

    Elasticsearch模糊查询.多字段in查询.时间范围查询,DSL和java API两种方式 项目场景: Elasticsearch模糊查询某字段.多字段in查询.时间范围查询,通过DSL和ja ...

  9. Django静态文件配置、form表单、request对象、连接数据库、ORM

    目录 静态文件配置 静态文件相关配置 1.接口前缀 浏览器停用缓存 2.接口前缀动态匹配 form表单 action 控制数据提交的地址 method 控制数据提交的方法 请求方法补充 get: 朝服 ...

  10. BeanShell 后置处理器/前置处理器实现urldecode 解码

    1.使用正则/Json提取器提取需要解码的值 2.在提取的接口中添加后置处理器或在下个调用接口中添加前置处理器 3.编码实现 String token = vars.get("access_ ...