方法一,对象属性依次赋值,对象成员发生变化时,需修改该方法:
bs.add=true;
bs.edit=true;
bs.list=true;
...
return bs;
方法二,利用反射,批量赋值:
ButtonState bs = new ButtonState();//
Type t = typeof(ButtonState);
PropertyInfo[] myPropertyInfo;
myPropertyInfo = t.GetProperties();
for (int i = 0; i < myPropertyInfo.Length; i++)
{
myPropertyInfo[i].SetValue(bs, true, null);
}
return bs;
对象:
/// <summary>
/// 按钮状态
/// </summary>
public class ButtonState
{
/// <summary>
/// 新增
/// </summary>
public bool add { get; set; }
/// <summary>
/// 编辑
/// </summary>
public bool edit { get; set; }
/// <summary>
/// 列表
/// </summary>
public bool list { get; set; }
/// <summary>
/// 查询
/// </summary>
public bool serch { get; set; }
/// <summary>
/// 查看
/// </summary>
public bool view { get; set; }
}