摘要:
EF Core Migrations 创建一个WebAPI.Migrations dotnet new webapi -n WebAPI.Migrations Program.cs using System.Reflection; using Microsoft.Extensions.Depende 阅读全文
2024年10月17日 #
2024年10月15日 #
摘要:
Socket\SocketClient\AsynSocketClient.cs using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; 阅读全文
2024年10月10日 #
摘要:
# RabbitMQ 发送端 using System.Text; using RabbitMQ.Client; var factory = new ConnectionFactory(); factory.HostName = "127.0.0.1"; //RabbitMQ服务器地址 factor 阅读全文
摘要:
启动 RabbitMQ 服务 进入到 rabbitmq 的安装 bin 目录 net start RabbitMQ 或者 在 rabbitmq 的 sbin 目录下,双击执行 rabbitmq-server.bat 文件。 停止 RabbitMQ 服务 net stop RabbitMQ 查看服务状 阅读全文
2024年9月25日 #
摘要:
clean-architecture-master\.vs\Movies\DesignTimeBuild\.dtbcache.v2 clean-architecture-master\.vs\Movies\v17\.futdcache.v2 clean-architecture-master\.vs 阅读全文
2024年9月23日 #
摘要:
# DataTableExtensions\App\App.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0</TargetFra 阅读全文
2024年9月13日 #
摘要:
XML解析读取 LINQtoXML\LINQtoXML\Program.cs using System; using System.Linq; using System.Xml.Linq; namespace LINQtoXML { class Program { public void Meth 阅读全文
摘要:
LINQ中的Join 在LINQ中,Join操作符用于连接两个序列中的元素,基于给定的键匹配。Join操作符允许你根据共同的键来关联两个序列中的项,这对于处理多个相关联的数据集非常有用。 代码 public class Employee { public int Id { get; set; } p 阅读全文
2024年9月11日 #
摘要:
delegate、Action、Func 和 Predicate 在C#中,delegate、Action、Func 和 Predicate 都是用来处理方法引用或匿名方法的类型,但它们之间有一些关键的区别。 Delegate delegate 是一个用户定义的类型,用于封装方法的引用。 它可以被实 阅读全文
2024年9月7日 #
摘要:
字节填充,内存对齐,为什么结果是4个字节,而不是三个字节 using System; using System.Runtime.InteropServices; public struct ExampleStruct { public byte b; public short s; // 你以为的是 阅读全文
摘要:
获取结构体成员中每个字段的偏移量 使用Marshal.OffsetOf来查看结构体中每个字段的偏移量: using System; using System.Runtime.InteropServices; public struct ExampleStruct { public byte b; / 阅读全文
摘要:
结构体成员定义的顺序也会影响结构体的大小,内存对齐,内存填充 using System; using System.Runtime.InteropServices; struct StrcutOne { public int b; // 4 bytes public byte a; // 1 pub 阅读全文
2024年9月6日 #
摘要:
配置文件如何注册引用 注册配置文件的形式 注册方式 // 第一种注册方式:注册配置文件 builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings")); AppSettings appS 阅读全文
摘要:
注册配置实例 Registers a configuration instance which TOptions will bind against. AppSettings.cs public class AppSettings { public const string Key = nameof 阅读全文
2024年9月3日 #
摘要:
sql中左连接,右连接,内连接,全连接之间的区别? 定义 1. INNER JOIN INNER JOIN 返回两个表中具有匹配值的行。如果某行在其中一个表中没有匹配,则该行不会出现在结果集中。 2. LEFT JOIN (LEFT OUTER JOIN) LEFT JOIN 返回左表的所有行,即使 阅读全文
2024年9月2日 #
摘要:
MediatR CQRS 目录结构 ├─MediatR_Demo │ ├─Application │ │ └─Movies │ │ ├─Commands │ │ │ └─CreateMovie │ │ └─Queries │ │ ├─GetMovie │ │ └─GetMovies │ ├─Cont 阅读全文
摘要:
DDD中扩展的思路 先到 domain 层 增加相应的实体(entity) 再到 基础设施层(Infrastructure)的数据库上下文中(DB Context)中注册实体 然后回到 domain 层定义 实体对应仓储层(I Repository) 的接口 再到 基础设施层(Infrastruct 阅读全文
2024年9月1日 #
摘要:
# DemoNormal\Demo.DI\Demo.DI.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFram 阅读全文
2024年8月31日 #
摘要:
new 关键字、隐藏基类方法 new 关键字还可以用来隐藏基类中的方法。 当子类的方法名称与基类中的方法名称相同,但不希望子类的方法被视为重写(override)基类的方法时,可以使用 new 关键字来声明子类的方法, 从而隐藏基类的方法。 代码示例 public class BaseClass { 阅读全文
摘要:
泛型中的new关键字的约束的函数 一般用于泛型约束,在函数或者类的末尾,通过 where T : new() 约束,确保 T 类型可以被实例化。 应用场景 在封装sqlsugar中我遇到了类似的用法,传给sqlsugar中的entity必须有一个公开的无参构造函数 👇👇👇👇👇👇 publ 阅读全文
摘要:
# 委托类型 事件触发 回调函数 按钮事件 DelegateButton\DelegateButton.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrame 阅读全文
摘要:
# 委托类型 函数别名 DeleGate\Program.cs using System; class Program { // 定义一个委托类型 public delegate void OperationDelegate(int x, int y); public static void Add 阅读全文
摘要:
LearnPlayground\PubSub\Program.cs using System; // 定义一个委托类型 public delegate void MyDelegate(string message); public class Publisher { // 定义一个事件,使用前面定义 阅读全文
2024年8月30日 #
摘要:
PlayGround\.config\dotnet-tools.json { "version": 1, "isRoot": true, "tools": { "csharpier": { "version": "0.29.1", "commands": [ "dotnet-csharpier" ] 阅读全文
2024年8月29日 #
摘要:
复制配置文件到输出文件夹 <ItemGroup> <None Update="appsettings.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="nlog.config" Cop 阅读全文
摘要:
# PlayGround\.config\dotnet-tools.json { "version": 1, "isRoot": true, "tools": { "csharpier": { "version": "0.29.1", "commands": [ "dotnet-csharpier" 阅读全文
摘要:
lock 为什么要传入一个object对象 public class Singleton { public static Singleton instance; public static readonly object singletonLock = new object(); private S 阅读全文
摘要:
dotnet如何设置restore package path,依赖和项目放在一起 配置说明 再.csproj中添加如下配置,然后 dotnet restore ,可以依赖包放到和项目一起,从而方便移动到没有网络的电脑上执行 <RestorePackagesPath>../packages</Rest 阅读全文
摘要:
using System.Linq.Expressions; using Microsoft.Extensions.Configuration; using SqlSugar; namespace SqlSugarFrameworkCore; public class DbSettings { pu 阅读全文
摘要:
如何创建dotnet-tools的配置文件 dotnet new tool-manifest dotnet tool install csharpier .csharpierrc.json { "printWidth": 100, "useTabs": false, "tabWidth": 4, " 阅读全文
2024年8月28日 #
摘要:
** 能用 foreach 遍历访问的对象需要实现 什么 接口或声明 什么 方法** 要使用 foreach 循环,对象必须实现 I Enumerable 接口或者声明 Get Enumerator 方法。 解释 IEnumerable 接口:这个接口定义了一个名为 GetEnumerator 的方 阅读全文
摘要:
单例模式 单例模式 public class Singleton { // 定义一个静态变量来保存类的实例 private static Singleton uniqueInstance; // 定义一个标识确保线程同步 private static readonly object locker = 阅读全文
2024年8月27日 #
摘要:
任务和线程的区别 在我们了解 Task 之前,如果我们要使用多核的功能可能就会自己来开线程,然而这种线程模型在. net 4.0 之后被一种称为基于“任务的编程模型” 所冲击,因为 task 会比 thread 具有更小的性能开销,不过大家肯定会有疑惑,任务和线程到底有什么区别? 1:任务是架构在线 阅读全文
2024年8月21日 #
摘要:
如何通过efcore生成实体模型 To create an Entity Data Model from the database using the Database First approach in EF Core, we’ll follow these steps: Create a new 阅读全文
摘要:
Entity Framework Core with Existing Database 数据库长这样: Scaffold-DbContext Command 说明 Use Scaffold-DbContext to create a model based on your existing dat 阅读全文
2024年8月19日 #
摘要:
CSharpier 配置 .csharpierrc.json { "printWidth": 100, "useTabs": false, "tabWidth": 4, "endOfLine": "auto" } 参数说明 Print Width Specify at what point the 阅读全文
2024年8月18日 #
摘要:
LinqExpressionLearn\Linq\ParameterRebinder.cs using System.Linq.Expressions; /// <summary> /// 表达式参数 /// </summary> public class ParameterRebinder : E 阅读全文
摘要:
封装前和封装后的实体类设计 如何封装 封装前的例子 假设我们有一个用户实体类 User,在封装前,可能看起来像这样: public class User { public int Id { get; set; } public string UserName { get; set; } public 阅读全文
摘要:
curlRequest\json\createtodo.json { "name": "eat", "status": 0, "remark": "eat apple" } curlRequest\json\createtodo2.json { "name": "eat", "status": 0, 阅读全文
摘要:
获取最新的shell脚本并执行 #!/bin/bash # 获取当前目录 current_dir=$(pwd) # 获取当前脚本的绝对路径 script_path=$(readlink -f "$0") # 使用find查找以temp开头且以.sh结尾的文件,并按修改时间排序 latest_file 阅读全文