The Standard Code CSharp by hassanhabib/the-standard-skills
npx skills add https://github.com/hassanhabib/the-standard-skills --skill 'The Standard Code CSharp'本技能是 The Standard 的规范 C# 编码风格和组织层。在生成、审查、重构或评估 C# 代码时使用它。
本技能明确覆盖所有提供的 C# 风格规则文件:
它还保留了实现规范中提供的实现配置文件命名约定。
适用于任何 C# 或 .NET 代码,包括模型、代理、服务、控制器、测试和支持代码。
this.。以下是 C# 文件的命名约定和指导原则。
文件名应遵循 PascalCase 命名法,后跟文件扩展名 .cs。
Student.cs
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
StudentService.cs
student.cs
studentService.cs
Student_Service.cs
分部类文件是包含根文件嵌套类的文件。例如:
验证和异常都是分部类,用于在多维空间中展示任何给定类的不同方面。
StudentService.Validations.cs
StudentService.Validations.Add.cs
StudentServiceValidations.cs
StudentService_Validations.cs
变量名应简洁,并能代表其持有或可能持有的值的性质和数量。
var student = new Student();
var s = new Student();
var stdnt = new Student();
同样的规则适用于 lambda 表达式:
students.Where(student => student ... );
students.Where(s => s ... );
var students = new List<Student>();
var studentList = new List<Student>();
var student = new Student();
var studentModel = new Student();
var studentObj = new Student();
如果变量值是其默认值(例如 int 的 0 或字符串的 null),并且你不打算更改该值(例如出于测试目的),那么名称应标识该值。
Student noStudent = null;
Student student = null;
int noChangeCount = 0;
int changeCount = 0;
声明变量并实例化它时,应指明变量的即时类型,即使其值稍后确定。
如果右侧类型明确,则使用 var 声明变量。
var student = new Student();
Student student = new Student();
如果右侧返回值类型不明确(但已知),则必须使用其类型显式声明变量。
Student student = GetStudent();
var student = GetStudent();
如果右侧返回值类型不明确且未知(例如匿名类型),则可以使用 var 作为变量类型。
var student = new
{
Name = "Hassan",
Score = 100
};
如果声明只有一个属性的类型,则直接分配属性。
var inputStudentEvent = new StudentEvent();
inputStudentEvent.Student = inputProcessedStudent;
var inputStudentEvent = new StudentEvent
{
Student = inputProcessedStudent
};
var studentEvent = new StudentEvent
{
Student = someStudent,
Date = someDate
}
var studentEvent = new StudentEvent();
studentEvent.Student = someStudent;
studentEvent.Date = someDate;
如果变量声明超过 120 个字符,则从等号处开始分解。
List<Student> washingtonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
List<Student> washgintonSchoolsStudentsWithGrades = await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
占用两行或更多行的声明,其前后应各有一个空行,以与前后变量声明分隔开。
Student student = GetStudent();
List<Student> washingtonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
School school = await GetSchoolAsync();
Student student = GetStudent();
List<Student> washgintonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
School school = await GetSchoolAsync();
此外,仅占一行的变量声明之间不应有空行。
Student student = GetStudent();
School school = await GetSchoolAsync();
Student student = GetStudent();
School school = await GetSchoolAsync();
方法名应是对方法所做工作的总结,需要保持精确、简短,并能代表操作内容,同时考虑同步性。
方法名必须包含动词,以表示其执行的动作。
public List<Student> GetStudents()
{
...
}
public List<Student> Students()
{
...
}
异步方法应以后缀 Async 结尾,通常指返回 Task 或 ValueTask 的方法。
public async ValueTask<List<Student>> GetStudentsAsync()
{
...
}
public async ValueTask<List<Student>> GetStudents()
{
...
}
输入参数应明确说明它们将被分配给对象的哪个属性,或用于任何操作(例如搜索)。
public async ValueTask<Student> GetStudentByNameAsync(string studentName)
{
...
}
public async ValueTask<Student> GetStudentByNameAsync(string text)
{
...
}
public async ValueTask<Student> GetStudentByNameAsync(string name)
{
...
}
如果你的方法使用特定参数执行操作,请指明。
public async ValueTask<Student> GetStudentByIdAsync(Guid studentId)
{
...
}
public async ValueTask<Student> GetStudentAsync(Guid studentId)
{
...
}
使用方法时,如果输入参数别名与传入的变量部分或完全匹配,则不必使用别名;否则,必须使用别名指定值。
假设你有一个方法:
Student GetStudentByNameAsync(string studentName);
string studentName = "Todd";
Student student = await GetStudentByNameAsync(studentName);
Student student = await GetStudentByNameAsync(studentName: "Todd");
Student student = await GetStudentByNameAsync(toddName);
Student student = await GetStudentByNameAsync("Todd");
Student student = await GetStudentByNameAsync(todd);
通常,将同一逻辑的多行代码封装到它们自己的方法中,并始终保持方法处于细节的第 0 级。
任何只包含一行代码的方法都应使用箭头函数(=>)。
public List<Student> GetStudents() => this.storageBroker.GetStudents();
public List<Student> Students()
{
return this.storageBroker.GetStudents();
}
如果单行方法的长度超过 120 个字符,则在箭头后换行,新行额外缩进一个制表符。
public async ValueTask<List<Student>> GetAllWashingtonSchoolsStudentsAsync() =>
await this.storageBroker.GetStudentsAsync();
public async ValueTask<List<Student>> GetAllWashingtonSchoolsStudentsAsync() => await this.storageBroker.GetStudentsAsync();
如果方法包含通过链式调用分隔或连接的多行代码,则必须有一个作用域。除非参数要换到下一行,否则允许使用带有多行参数的单行方法。
public Student AddStudent(Student student)
{
ValidateStudent(student);
return this.storageBroker.InsertStudent(student);
}
public Student AddStudent(Student student)
{
return this.storageBroker.InsertStudent(student)
.WithLogging();
}
public Student AddStudent(
Student student)
{
return this.storageBroker.InsertStudent(student);
}
public Student AddStudent(Student student) =>
this.storageBroker.InsertStudent(student)
.WithLogging();
public Student AddStudent(
Student student) =>
this.storageBroker.InsertStudent(student);
对于多行方法,在方法逻辑和最终的返回行(如果有)之间换行。
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
return studentsApiClient.GetStudents();
}
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
return studentsApiClient.GetStudents();
}
对于多次方法调用,如果两次调用都少于 120 个字符,则可以堆叠在一起,除非最后一次调用是方法返回,否则用空行分隔。
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public async ValueTask<List<Student>> GetStudentsAsync()
{
StudentsClient washingtonSchoolsStudentsApiClient =
await InitializeWashingtonSchoolsStudentsApiClientAsync();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public async ValueTask<List<Student>> GetStudentsAsync()
{
StudentsClient washingtonSchoolsStudentsApiClient =
await InitializeWashingtonSchoolsStudentsApiClientAsync();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
方法声明的长度不应超过 120 个字符。
public async ValueTask<List<Student>> GetAllRegisteredWashgintonSchoolsStudentsAsync(
StudentsQuery studentsQuery)
{
...
}
public async ValueTask<List<Student>> GetAllRegisteredWashgintonSchoolsStudentsAsync(StudentsQuery studentsQuery)
{
...
}
如果要传递多个参数,并且方法调用的长度超过 120 个字符,则必须按参数换行,每行一个参数。
List<Student> redmondHighStudents = await QueryAllWashingtonStudentsByScoreAndSchoolAsync(
MinimumScore: 130,
SchoolName: "Redmond High");
List<Student> redmondHighStudents = await QueryAllWashingtonStudentsByScoreAndSchoolAsync(
MinimumScore: 130,SchoolName: "Redmond High");
一些方法提供了调用其他方法的扩展。例如,你可以在 Where() 方法之后调用 Select() 方法。依此类推,直到完成整个查询。
我们将遵循一个丑化美化的过程。我们丑化代码以美化我们对链式方法的视图。以下是一些示例:
students.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.ToList();
students
.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.ToList();
第一种方法强制简化和缩短链式调用,因为更多的调用会继续丑化代码,如下所示:
students.SomeMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...);
丑化过程强制将链式调用分解为更小的列表,然后进行处理。第二种方法(非丑化方法)可能需要额外的认知资源来区分新语句和现有语句,如下所示:
student
.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.OrderBy(student => student.Name)
.ToList();
ProcessStudents(students);
在符合标准架构中代表服务或代理的类,其命名约定应体现类的类型,但这不适用于模型。
class Student {
...
}
class StudentModel {
}
以单数形式,适用于任何包含业务逻辑的类。
class StudentService {
....
}
class StudentsService{
...
}
class StudentBusinessLogic {
...
}
class StudentBL {
...
}
以单数形式,适用于任何作为服务和外部资源之间垫片的类。
class StudentBroker {
....
}
class StudentsBroker {
...
}
以复数形式,以反映端点(如 /api/students),通过 RESTful 操作公开你的逻辑。
class StudentsController {
....
}
class StudentController {
...
}
字段是在类或结构中直接声明的任何类型的变量。字段是其包含类型的成员。
类字段采用驼峰命名法。
class StudentsController {
private readonly string studentName;
}
class StudentController {
private readonly string StudentName;
}
class StudentController {
private readonly string _studentName;
}
应遵循"变量"部分中提到的相同命名规则。
引用类私有字段时,使用 this 关键字来区分私有类成员与作用域方法或构造函数级别的变量。
class StudentsController {
private readonly string studentName;
public StudentsController(string studentName) {
this.studentName = studentName;
}
}
class StudentController {
private readonly string _studentName;
public StudentsController(string studentName) {
_studentName = studentName;
}
}
如果输入变量名称与输入别名匹配,则使用它们;否则,必须使用别名,特别是对于传入的值。
int score = 150;
string name = "Josh";
var student = new Student(name, score);
var student = new Student(name: "Josh", score: 150);
var student = new Student("Josh", 150);
Student student = new (...);
实例化类时,确保属性赋值与类声明中的属性顺序匹配。
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Id = Guid.NewGuid(),
Name = "Elbek"
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Name = "Elbek",
Id = Guid.NewGuid()
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(string name, Guid id)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (name: "Elbek", id: Guid.NewGuid());
注释只能用于解释代码无法表达的内容。无论代码是否可见。
突出显示版权的注释应遵循以下模式:
// ---------------------------------------------------------------
// Copyright (c) Coalition of the Good-Hearted Engineers
// FREE TO USE TO CONNECT THE WORLD
// ---------------------------------------------------------------
//----------------------------------------------------------------
// <copyright file="StudentService.cs" company="OpenSource">
// Copyright (C) Coalition of the Good-Hearted Engineers
// </copyright>
//----------------------------------------------------------------
/*
* ==============================================================
* Copyright (c) Coalition of the Good-Hearted Engineers
* FREE TO USE TO CONNECT THE WORLD
* ==============================================================
*/
包含在开发时无法访问的代码,或执行复杂功能的方法,其文档应包含以下详细信息。
| 元素 | 模式 | 示例 |
|---|---|---|
| 代理接口 | I{Resource}Broker | IStorageBroker, IModernApiBroker, ILoggingBroker |
| 代理类 | {Resource}Broker | StorageBroker, ModernApiBroker, LoggingBroker |
| 代理方法 | {Action}{Entity}Async | InsertLegacyUserAsync, PostPersonAsync |
| 服务接口 | I{Entity}Service | ILegacyUserService |
| 服务类 | {Entity}Service | LegacyUserService |
| 服务方法 | Add{Entity}Async | AddLegacyUserAsync |
| 内部异常 | {Adjective}{Entity}Exception | NullLegacyUserException |
| 外部异常 | {Entity}{Category}Exception | LegacyUserValidationException |
| 测试类 | {Entity}ServiceTests | LegacyUserServiceTests |
| 测试方法 | Should{Action}Async / ShouldThrow{Exception}On{Action}… | ShouldAddLegacyUserAsync |
每周安装次数
–
代码仓库
GitHub 星标数
2
首次出现时间
–
安全审计
This skill is the canonical C# coding-style and organization layer for The Standard. Use it whenever generating, reviewing, refactoring, or evaluating C# code.
This skill explicitly covers all supplied C# style rule files:
It also preserves the implementation-profile naming conventions supplied in the implementation specification.
Use this skill for any C# or .NET code, including models, brokers, services, controllers, tests, and support code.
this. for private fields.The following are the naming conventions and guidance for naming C# files.
File names should follow the PascalCase convention followed by the file extension .cs.
Student.cs
StudentService.cs
student.cs
studentService.cs
Student_Service.cs
Partial class files are files that contain nested classes for a root file. For instance:
Both validations and exceptions are partial classes to display a different aspect of any given class in a multi-dimensional space.
StudentService.Validations.cs
StudentService.Validations.Add.cs
StudentServiceValidations.cs
StudentService_Validations.cs
Variable names should be concise and representative of nature and the quantity of the value it holds or will potentially hold.
var student = new Student();
var s = new Student();
var stdnt = new Student();
The same rule applies to lambda expressions:
students.Where(student => student ... );
students.Where(s => s ... );
var students = new List<Student>();
var studentList = new List<Student>();
var student = new Student();
var studentModel = new Student();
var studentObj = new Student();
If a variable value is it's default such as 0 for int or null for strings and you are not planning on changing that value (for testing purposes for instance) then the name should identify that value.
Student noStudent = null;
Student student = null;
int noChangeCount = 0;
int changeCount = 0;
Declaring a variable and instantiating it should indicate the immediate type of the variable, even if the value is to be determined later.
If the right side type is clear, then use var to declare your variable
var student = new Student();
Student student = new Student();
If the right side isn't clear (but known) of the returned value type, then you must explicitly declare your variable with it's type.
Student student = GetStudent();
var student = GetStudent();
If the right side isn't clear and unknown (such as an anonymous types) of the returned value type, you may use var as your variable type.
var student = new
{
Name = "Hassan",
Score = 100
};
Assign properties directly if you are declaring a type with one property.
var inputStudentEvent = new StudentEvent();
inputStudentEvent.Student = inputProcessedStudent;
var inputStudentEvent = new StudentEvent
{
Student = inputProcessedStudent
};
var studentEvent = new StudentEvent
{
Student = someStudent,
Date = someDate
}
var studentEvent = new StudentEvent();
studentEvent.Student = someStudent;
studentEvent.Date = someDate;
If a variable declaration exceeds 120 characters, break it down starting from the equal sign.
List<Student> washingtonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
List<Student> washgintonSchoolsStudentsWithGrades = await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
Declarations that occupy two lines or more should have a new line before and after them to separate them from previous and next variables declarations.
Student student = GetStudent();
List<Student> washingtonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
School school = await GetSchoolAsync();
Student student = GetStudent();
List<Student> washgintonSchoolsStudentsWithGrades =
await GetAllWashingtonSchoolsStudentsWithTheirGradesAsync();
School school = await GetSchoolAsync();
Also, declarations of variables that are of only one line should have no new lines between them.
Student student = GetStudent();
School school = await GetSchoolAsync();
Student student = GetStudent();
School school = await GetSchoolAsync();
Method names should be a summary of what the method is doing, it needs to stay percise and short and representative of the operation with respect to synchrony.
Method names must contain verbs in them to represent the action it performs.
public List<Student> GetStudents()
{
...
}
public List<Student> Students()
{
...
}
Asynchronous methods should be postfixed by the term Async such as methods returning Task or ValueTask in general.
public async ValueTask<List<Student>> GetStudentsAsync()
{
...
}
public async ValueTask<List<Student>> GetStudents()
{
...
}
Input parameters should be explicit about what property of an object they will be assigned to, or will be used for any action such as search.
public async ValueTask<Student> GetStudentByNameAsync(string studentName)
{
...
}
public async ValueTask<Student> GetStudentByNameAsync(string text)
{
...
}
public async ValueTask<Student> GetStudentByNameAsync(string name)
{
...
}
If your method is performing an action with a particular parameter specify it.
public async ValueTask<Student> GetStudentByIdAsync(Guid studentId)
{
...
}
public async ValueTask<Student> GetStudentAsync(Guid studentId)
{
...
}
When utilizing a method, if the input parameters aliases match the passed in variables in part or in full, then you don't have to use the aliases, otherwise you must specify your values with aliases.
Assume you have a method:
Student GetStudentByNameAsync(string studentName);
string studentName = "Todd";
Student student = await GetStudentByNameAsync(studentName);
Student student = await GetStudentByNameAsync(studentName: "Todd");
Student student = await GetStudentByNameAsync(toddName);
Student student = await GetStudentByNameAsync("Todd");
Student student = await GetStudentByNameAsync(todd);
In general encapsulate multiple lines of the same logic into their own method, and keep your method at level 0 of details at all times.
Any method that contains only one line of code should use fat arrows
public List<Student> GetStudents() => this.storageBroker.GetStudents();
public List<Student> Students()
{
return this.storageBroker.GetStudents();
}
If a one-liner method exceeds the length of 120 characters then break after the fat arrow with an extra tab for the new line.
public async ValueTask<List<Student>> GetAllWashingtonSchoolsStudentsAsync() =>
await this.storageBroker.GetStudentsAsync();
public async ValueTask<List<Student>> GetAllWashingtonSchoolsStudentsAsync() => await this.storageBroker.GetStudentsAsync();
If a method contains multiple liners separated or connected via chaining it must have a scope. Unless the parameters are going on the next line then a one-liner method with multi-liner params is allowed.
public Student AddStudent(Student student)
{
ValidateStudent(student);
return this.storageBroker.InsertStudent(student);
}
public Student AddStudent(Student student)
{
return this.storageBroker.InsertStudent(student)
.WithLogging();
}
public Student AddStudent(
Student student)
{
return this.storageBroker.InsertStudent(student);
}
public Student AddStudent(Student student) =>
this.storageBroker.InsertStudent(student)
.WithLogging();
public Student AddStudent(
Student student) =>
this.storageBroker.InsertStudent(student);
For multi-liner methods, take a new line between the method logic and the final return line (if any).
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
return studentsApiClient.GetStudents();
}
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
return studentsApiClient.GetStudents();
}
With mutliple method calls, if both calls are less than 120 characters then they may stack unless the final call is a method return, otherwise separate with a new line.
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public List<Student> GetStudents()
{
StudentsClient studentsApiClient = InitializeStudentApiClient();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public async ValueTask<List<Student>> GetStudentsAsync()
{
StudentsClient washingtonSchoolsStudentsApiClient =
await InitializeWashingtonSchoolsStudentsApiClientAsync();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
public async ValueTask<List<Student>> GetStudentsAsync()
{
StudentsClient washingtonSchoolsStudentsApiClient =
await InitializeWashingtonSchoolsStudentsApiClientAsync();
List<Student> students = studentsApiClient.GetStudents();
return students;
}
A method declaration should not be longer than 120 characters.
public async ValueTask<List<Student>> GetAllRegisteredWashgintonSchoolsStudentsAsync(
StudentsQuery studentsQuery)
{
...
}
public async ValueTask<List<Student>> GetAllRegisteredWashgintonSchoolsStudentsAsync(StudentsQuery studentsQuery)
{
...
}
If you are passing multiple parameters, and the length of the method call is over 120 characters, you must break by the parameters, with one parameter on each line.
List<Student> redmondHighStudents = await QueryAllWashingtonStudentsByScoreAndSchoolAsync(
MinimumScore: 130,
SchoolName: "Redmond High");
List<Student> redmondHighStudents = await QueryAllWashingtonStudentsByScoreAndSchoolAsync(
MinimumScore: 130,SchoolName: "Redmond High");
Some methods offer extensions to call other methods. For instance, you can call a Select() method after a Where() method. And so on until a full query is completed.
We will follow a process of Uglification Beautification. We uglify our code to beautify our view of a chain methods. Here's some examples:
students.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.ToList();
students
.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.ToList();
The first approach enforces simplifying and cutting the chaining short as more calls continues to uglify the code like this:
students.SomeMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...)
.SomeOtherMethod(...);
The uglification process forces breaking down the chains to smaller lists then processing it. The second approach (no uglification approach) may require additional cognitive resources to distinguish between a new statement and an existing one as follows:
student
.Where(student => student.Name is "Elbek")
.Select(student => student.Name)
.OrderBy(student => student.Name)
.ToList();
ProcessStudents(students);
Classes that represent services or brokers in a Standard-Compliant architecture should represent the type of class in their naming convention, however that doesn't apply to models.
class Student {
...
}
class StudentModel {
}
In a singular fashion, for any class that contains business logic.
class StudentService {
....
}
class StudentsService{
...
}
class StudentBusinessLogic {
...
}
class StudentBL {
...
}
In a singular fashion, for any class that is a shim between your services and external resources.
class StudentBroker {
....
}
class StudentsBroker {
...
}
In a plural fashion, to reflect endpoints such as /api/students to expose your logic via RESTful operations.
class StudentsController {
....
}
class StudentController {
...
}
A field is a variable of any type that is declared directly in a class or struct. Fields are members of their containing type.
Class fields are named in a camel cased fashion.
class StudentsController {
private readonly string studentName;
}
class StudentController {
private readonly string StudentName;
}
class StudentController {
private readonly string _studentName;
}
Should follow the same rules for naming as mentioned in the Variables sections.
When referencing a class private field, use this keyword to distinguish private class member from a scoped method or constructor level variable.
class StudentsController {
private readonly string studentName;
public StudentsController(string studentName) {
this.studentName = studentName;
}
}
class StudentController {
private readonly string _studentName;
public StudentsController(string studentName) {
_studentName = studentName;
}
}
If the input variables names match to input aliases, then use them, otherwise you must use the aliases, especially with values passed in.
int score = 150;
string name = "Josh";
var student = new Student(name, score);
var student = new Student(name: "Josh", score: 150);
var student = new Student("Josh", 150);
Student student = new (...);
When instantiating a class instance - make sure that your property assignment matches the properties order in the class declarations.
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Id = Guid.NewGuid(),
Name = "Elbek"
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Name = "Elbek",
Id = Guid.NewGuid()
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(string name, Guid id)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (name: "Elbek", id: Guid.NewGuid());
Comments can only be used to explain what code can't. Whether the code is visible or not.
Comments highlighting copyrights should follow this pattern:
// ---------------------------------------------------------------
// Copyright (c) Coalition of the Good-Hearted Engineers
// FREE TO USE TO CONNECT THE WORLD
// ---------------------------------------------------------------
//----------------------------------------------------------------
// <copyright file="StudentService.cs" company="OpenSource">
// Copyright (C) Coalition of the Good-Hearted Engineers
// </copyright>
//----------------------------------------------------------------
/*
* ==============================================================
* Copyright (c) Coalition of the Good-Hearted Engineers
* FREE TO USE TO CONNECT THE WORLD
* ==============================================================
*/
Methods that have code that is not accessible at dev-time, or perform a complex function should contain the following details in their documentation.
| Element | Pattern | Example |
|---|---|---|
| Broker interface | I{Resource}Broker | IStorageBroker, IModernApiBroker, ILoggingBroker |
| Broker class | {Resource}Broker | StorageBroker, ModernApiBroker, LoggingBroker |
Weekly Installs
–
Repository
GitHub Stars
2
First Seen
–
Security Audits
Next.js 15+ 最佳实践指南:文件约定、RSC边界、异步模式与性能优化
866 周安装
| Broker method | {Action}{Entity}Async | InsertLegacyUserAsync, PostPersonAsync |
| Service interface | I{Entity}Service | ILegacyUserService |
| Service class | {Entity}Service | LegacyUserService |
| Service method | Add{Entity}Async | AddLegacyUserAsync |
| Inner exception | {Adjective}{Entity}Exception | NullLegacyUserException |
| Outer exception | {Entity}{Category}Exception | LegacyUserValidationException |
| Test class | {Entity}ServiceTests | LegacyUserServiceTests |
| Test method | Should{Action}Async / ShouldThrow{Exception}On{Action}… | ShouldAddLegacyUserAsync |