Prompt file imported from TadeasBurda/copilot-settings (
.github/prompts/order-csharp-members.prompt.md). Copyright stays with the author.
🧠 Prompt: Order and Format C# Class Members
📝 Description
This prompt formats and reorders members of a C# class to follow a clean and consistent structure. It ensures proper indentation and organizes members in a logical order for readability and maintainability.
🎯 Goals
- Format code with 4-space indentation.
- Place opening braces on new lines.
- Reorder class members in the following order:
- constants (
const, e.g.const int MAX_DATA_POINTS) - abstract fields
- private static readonly fields (e.g. static readonly int _count)
- private static fields with default value (e.g. static int = 0)
- private readonly fields (e.g. readonly string _name)
- private fields with default value (e.g. int = 0)
- private nullable fields (e.g. int?)
- protected static readonly fields
- protected static fields
- protected readonly fields
- protected fields
- abstract properties
- internal properties
- public properties
- properties with the
[ObservableProperty]attribute - Constructors
- abstract methods (including async)
- Methods (in order: public, protected, private; async methods are placed after non-async in each group)
public void Dispose()method (always at the end, before the destructor)- Destructor (
~Class(), always the very last member)
- constants (
- Constants must always be placed first and use UPPER_SNAKE_CASE naming convention (e.g.
MAX_DATA_POINTS). - Abstract fields, properties, and methods must always be placed before non-abstract members of the same type.
- Properties with the
[ObservableProperty]attribute must always be grouped together, immediately after normal properties. - The
public void Dispose()method must always be placed at the end of the class, just before the destructor. - The destructor (
~Class()) must always be the very last member of the class. - If a constructor is a primary constructor, do not change it to a regular constructor; always preserve its primary form.
- Normalize naming conventions (PascalCase for types and members, camelCase for fields).
- Remove unnecessary whitespace and align code blocks.
📥 Input
A C# class file with unordered or poorly formatted members.
📤 Output
A clean, well-formatted C# class with members ordered and styled according to standard conventions.
🛠️ Notes
- Do not modify logic or add/remove comments unless necessary for formatting.
- Preserve attributes, region tags, and preprocessor directives.
- Remove all helper comments used for member grouping (e.g.
// 1. Constants,// (none)) from the final output. These comments must not remain in the resulting code.