• C#代码简洁规范


     var sth=new zfsdfsdfs()

    sth.ssss();

    直接变成

    new zfsdfsdfs().ssss();

    for循环和foreach循环和if else是代码混乱的大敌。

    之前的代码

    Expression<Func<Math_RoleInfo, bool>> exp1 = null;
    if (where == null)
    {
    exp1 = item => true;
    }
    else
    {
    exp1 = where;
    }
     1、 Expression<Func<Math_RoleInfo, bool>> exp1 = where == null ? item => true : where;

    1、巧用select where orderby 等方式。

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

    将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、能用字典,不用对象。

    {
    key:"",
    value:[1,2,3,4,5]
    }

    改为:

    {{
    "xxx-xxxx-xxxx-xxxxx":{
    value:[1,2,3,4,5]
    }
    }
    '}

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

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

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

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

    8、在bus层和显示层之间要建立 dto层,从bus到dto,从dto到bus,这样可以建立数据消费的版本。

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

    10、复杂的sql语句要写在视图和存储过程中。

    11、减少if的使用,能少就少:

    if(a>=0)
    {
    printf("malaing")
    }
    else
    {
    }
    a?print('maliang'):()=>{}
     fullUrl = process.env.SINGLE === 'true' ? `/${prefix}/${url}` : `/${process.env.APP_NAME}/${prefix}/${url}`;
     
     return this.hasRead ? 0 : this.count;
  • 相关阅读:
    mybatis ForEach Collection集合等规范解析(转)
    IntelliJ IDEA怎么安装
    django数据库基本操作-增删改查(tip)-基本
    解决Django中在.js文件中用ajax请求后端,找不到CSRF问题
    jQuery判断当前元素是第几个元素&获取第N个元素
    python 判断字符串是否为空用什么方法?
    jq 跳转方式汇总
    SwitchOmega的详细配置——for Windows
    ubuntu怎用使用命令搜索软件源中的软件
    ubuntu16.04中文乱码解决方案
  • 原文地址:https://www.cnblogs.com/sexintercourse/p/12194558.html
Copyright © 2020-2023  润新知