想到啥就写点啥

.Net Core nuget包版本自动升级实现

前言

因为公司有自己的私有包服务,但是在发包的过程中,时常会出现忘记升级包版本的情况,导致需要重新发包,就显得比较麻烦,于是就有了实现自动升级包版本的想法。鉴于服务是区分为四个环境的(dev,test,staging和master),所以对应的包版本标识也应该有四个。

数据结构与算法之美(三)

跳表

跳表:带有多级索引的链表。

跳表使用空间换时间的设计思路,通过构建多级索引来提高查询的效率,实现了基于链表的“二分查找”。跳表是一种动态数据结构,支持快速的插入、删除、查找操作,时间复杂度都是O(logn)。

数据结构与算法之美(二)

递归

递归需要满足的三个条件

  1. 一个问题的解可以分解为几个子问题的解

    何为子问题?子问题就是数据规模更小的问题。

  2. 这个问题与分解之后的子问题,除了数据规模不同,求解思路完全一样

  3. 存在递归中止条件

    把问题分解为子问题,把子问题再分解为子子问题,一层一层分解下去,不能存在无限循环,这就需要有终止条件。

数据结构与算法之美(一)

基础知识

20个最常用的、最基础数据结构与算法

10个数据结构:数组、链表、栈、队列、散列表、二叉树、堆、跳表、图、Trie树。

10个算法:递归、排序、二分查找、搜索、哈希算法、贪心算法、分治算法、回溯算法、动态规划、字符串匹配算法。

重构-改善既有代码的设计(七)

处理继承关系

函数上移(Pull Up Method)

  • 示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    class Employee {...}

    class Saleman extends Employee {
    get name() {...}
    }

    class Engineer extends Employee {
    get name() {...}
    }

    重构为

    1
    2
    3
    4
    5
    6
    class Employee{
    get name() {...}
    }

    class Saleman extends Employee {...}
    class Engineer extends Employee {...}

重构-改善既有代码的设计(六)

重构API

将查询函数和修改函数分离(Separate Query from Modifier)

  • 示例

    1
    2
    3
    4
    5
    function getTotalOutatandingAndSendBill(){
    const result = customer.invoices.reduce((total, each) => each.amount + total, 0);
    sendBill();
    return result;
    }

    重构为

    1
    2
    3
    4
    5
    6
    function totalOutstanding(){
    return customer.invoices.reduce((total, each) => each.amount + total, 0);
    }
    function sendBill(){
    emailGateway.send(formatBill(customer));
    }

重构-改善既有代码的设计(三)

封装

封装记录(Encapsulate Record)

  • 示例

    1
    organization = {name: "Acme Gooseberries",country:"GB"};

    重构为

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    class Oraganization{
    constructor(data){
    this._name = data.name;
    this._country = data.country;
    }
    get name() { return this._name; }
    set name(arg) {this._name = arg; }
    get country() { return this._country; }
    set country(arg) {this._country = arg; }
    }

重构-改善既有代码的设计(二)

重构名录-第一组重构

提炼函数(Extract Function)

  • 示例

    1
    2
    3
    4
    5
    6
    7
    8
    function printOwing(invoice){
    printBanner()
    let outstanding = calculateOutstanding();

    // print details
    console.log(`name:${invoice.customer}`);
    console.log(`amount:${outstanding}`);
    }

    重构为

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function printOwing(invoice){
    printBanner()
    let outstanding = calculateOutstanding();
    printDetails(outstanding)

    function printDetails(outstanding){
    console.log(`name:${invoice.customer}`);
    console.log(`amount:${outstanding}`);
    }
    }

© 2026 我想探索一下世界

Elegant theme by Shiro · Made by Acris with ❤️