快速设置类属性

时间:2010-04-04 15:07:00

标签: c# class

class UserClass{

    #region Class properties which are binding from DB
    .
    .
    .
    #endregion


    #region Constructor Methods
    public UserClass(int _iUser_id)
    {
        // of course this is wrong but how can i quickly set properties 
        // which are coming from DB by extension method over context class?
        this = DAO.context.GetById<UserClass>(_iUser_id);
    }
    #endregion
}

2 个答案:

答案 0 :(得分:2)

您需要手动设置属性。

如果你真的想,你可以使用反射或表达树来遍历属性,但它可能不值得。

答案 1 :(得分:0)

您可以使用静态方法而不是构造函数:

public static UserClass GetById(int userId) {
    return DAO.context.GetById<UserClass>(userId);
}