每个人都有自己的知识体系。
Toggle navigation
Home
随笔
C#/.Net
树莓派 / Raspberry
皓月汉化组
Beego
Golang
OxideMod
apache
haproxy
windows
Java
Objective-C
日语/罗马音歌词/日语常识
MongoDB
python
电学
公告
Minecraft服务器-公告
NanoPi
C4D (CINEMA 4D)
生活
推流/m3u8/rtmp/rtsp
Unity3d
ffmpeg
数据结构
区块链
tarui
UnityForPSVita
About Me
Archives
Tags
C# 复杂实体类递归反射并赋值(未完善)
2017-05-23 10:50:07
339
0
0
akiragatsu
public static T SetReflectionObject<T>(T t) { System.Reflection.PropertyInfo[] //properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); properties = t.GetType().GetProperties(); if (t.GetType().Name.StartsWith("List")) { System.Collections.ICollection MyIlist = t as System.Collections.ICollection; foreach (var l in MyIlist) { SetReflectionObject(l); } return t; } foreach (System.Reflection.PropertyInfo item in properties) { if (item.GetValue(t, null) == null) { if (item.PropertyType.Name.StartsWith("String")) { item.SetValue(t, ""); } if (item.PropertyType.Name.StartsWith("List")) { item.SetValue(t, Activator.CreateInstance(item.PropertyType)); } } else if (item.PropertyType.Name.StartsWith("List")) { System.Collections.ICollection Ilist = item.GetValue(t, null) as System.Collections.ICollection; foreach (var l in Ilist) { SetReflectionObject(l); } } } return t; }
Pre:
Next:
只允许远程用户同时一个连接
0
likes
339
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.