using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Tool;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
People model = new People();
model.PeopleName = "张三";
model.PeopleAge = 18;
model.PeopleAddress = "中国上海";
foreach (PropertyInfo info in model.GetType().GetProperties())
{
string Name = info.Name;
object value = info.GetValue(model, null);
if (info.PropertyType.IsValueType || info.PropertyType.Name.StartsWith("String"))
{
Console.WriteLine("字段属性名称: {0} => 字段属性值: {1}", Name, value.ToString());
}
//info.SetValue(model, "设置遍历该字段的值", null);
}
Console.ReadKey();
}
public class People
{
public string PeopleName { get; set; }
public int PeopleAge { get; set; }
public string PeopleAddress { get; set; }
}
}
}
最后
以上就是活力白开水最近收集整理的关于C#映射类获取类中属性名称与属性的值的全部内容,更多相关C#映射类获取类中属性名称与属性内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复