zoukankan      html  css  js  c++  java
  • 通过反射,给实体赋值,或者取值

    1.设置值

     Type type = personnelSalary.GetType(); //personnelSalary实体变量
                decimal values = 0;
                foreach (ActionAllowance actionAllowance in li_ActionAllowance)
                {
                    RadNumericTextBox TextBox1 = (RadNumericTextBox)this.FindControl("rntxtSalary_" + actionAllowance.AllowanceCode);
                    PropertyInfo pi = type.GetProperty(actionAllowance.AllowanceCode);//actionAllowance.AllowanceCode 表示属性的名称
                    values = TextBox1.Text == null ? 0 : Convert.ToDecimal(TextBox1.Text);
                    pi.SetValue(personnelSalary, values, null);
                }

    2.得到值

     Type type = personnelSalary.GetType(); //personnelSalary实体变量

    PropertyInfo pi = type.GetProperty(li_ActionAllowance[m].AllowanceCode);
                            htd1.InnerText = li_ActionAllowance[m].AllowanceName;

                            RadNumericTextBox txtName = new RadNumericTextBox();
                            txtName.ID = "rntxtSalary_" + li_ActionAllowance[m].AllowanceCode;
                            txtName.Text = pi.GetValue(personnelSalary, null).ToString();
                            htd2.Controls.Add(txtName);

  • 相关阅读:
    关于Django
    Django
    如何在六个月掌握一门外语
    基础术语
    机器学习
    2018-01-05 通用型的中文编程语言探讨之一: 高考
    2018-01-04 浅尝The Little Prover一书, 重逢Chez Scheme
    2018-01-03 烂尾工程: Java实现的汇编语言编译器
    2018-01-03 中文编程专栏月报:2017年12月
    2017-12-26 Java关键字的汉化用词探讨
  • 原文地址:https://www.cnblogs.com/doubleyong/p/2675041.html
Copyright © 2011-2022 走看看