• 通过反射,给实体赋值,或者取值


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

  • 相关阅读:
    HDU 1713 相遇周期 (最小公倍数)
    HDU 1270 小希的数表 (暴力枚举+数学)
    HDU 1052 Tian Ji -- The Horse Racing (贪心)
    CodeForces 732D Exams (二分)
    CodeForces 732C Sanatorium (if-else)
    CodeForces 732B Cormen — The Best Friend Of a Man (贪心)
    CodeForces 732A Buy a Shovel (水题)
    CodeForces 743C Vladik and fractions (数论)
    Node基础
    正向代理与反向代理
  • 原文地址:https://www.cnblogs.com/doubleyong/p/2675041.html
Copyright © 2020-2023  润新知