zoukankan      html  css  js  c++  java
  • C#通过反射给对象赋值

    class Program
        {
            static void Main(string[] args)
            {
                UserSearchRequest model = new UserSearchRequest()
                {
                    Name = "'1'=0",
                    Age = 10
                };
    
    
                Type type = model.GetType();
                //var ps = type.GetProperties();
    
                var ps = type.GetProperties().Where(u=>u.PropertyType.FullName =="System.String").ToList();
    
                foreach (var p in ps)
                {
                    Console.WriteLine("PropertyName:{0},Value:{1}",p.Name,p.GetValue(model,null).ToString());
                    p.SetValue(model, "1001",null);
                    Console.WriteLine("PropertyName:{0},Value:{1}", p.Name, p.GetValue(model, null).ToString());
                }
    
                Console.ReadLine();
            }
        }
    
        public class UserSearchRequest
        {
            public string Name { set; get; }
            public int Age { set; get; }
        }
  • 相关阅读:
    JMeter和JMeterPlugin 下载安装
    Beanshell语法
    逻辑控制器
    常用配置元件
    jmeter结构体系
    正则表达式提取器
    ab 测试工具
    spring cloud_docker
    jmeter+maven
    TFS
  • 原文地址:https://www.cnblogs.com/binlyzhuo/p/6170502.html
Copyright © 2011-2022 走看看