C#代码简洁规范

1、巧用select where orderby 等方式。

将复杂的for循环和foreach循环提炼在

List<Math_Deptinfo> list = bLL_Deptinfo.Search(start, length, out total, where);
            List<UI_Math_Deptinfo> listUIRoleModel = new List<UI_Math_Deptinfo>();
            foreach (Math_Deptinfo item in list)
            {
                UI_Math_Deptinfo uIRoleModel = Mapper.Map<UI_Math_Deptinfo>(item);
                listUIRoleModel.Add(uIRoleModel);
            }

           
 list.Select(item => Mapper.Map<UI_Math_Deptinfo>(item)).ToList();

2、将一些常量代码,进行static优化。

 #region 操作上的称呼
    /// <summary>
    /// 操作上的称呼
    /// </summary>
    public class OpCommonString
    {
        public static string DeleteSuccess = "删除成功";
        public static string DeleteFail = "删除失败";
        public static string InsertSuccess = "录入成功";
        public static string InsertFail = "录入失败";
        public static string UpdateSuccess = "更新成功";
        public static string UpdateFail = "更新失败";
        public static string Executing = "程序正在处理......";
        public static string ExecutedSuccess = "处理成功";
        public static string ExecutedError = "处理失败";
    }
    #endregion

3、能用字典,不用对象。

4、能在maper里面配置,不在for循环里自己赋值。

5、接口数据尽量简洁,前端可以用computered进行加工。

6、所有的系统类都要尽可能进行封装,这样可以减少项目的风险。

7、使用泛型接口,强制。

8、在bus层和显示层之间要建立 dto层,从bus到dto,从dto到bus

9、前端和后端要建立token机制。

猜你喜欢

转载自www.cnblogs.com/sexintercourse/p/12194558.html
今日推荐