Some checks failed
Build and Test / build (push) Has been cancelled
- Kilocode AI agent rules and guidelines - Setup and implementation guides - Architecture documentation - Build and verification references
89 lines
2.2 KiB
Markdown
89 lines
2.2 KiB
Markdown
# C# 5.0 Syntax Requirements
|
|
|
|
You are working on a .NET Framework 4.8 project that MUST use C# 5.0 syntax only.
|
|
|
|
## Forbidden C# 6+ Features
|
|
|
|
### String Interpolation (C# 6)
|
|
❌ NEVER use: `$"Order {orderId} at {price}"`
|
|
✅ ALWAYS use: `string.Format("Order {0} at {1}", orderId, price)`
|
|
|
|
### Null-Conditional Operators (C# 6)
|
|
❌ NEVER use: `var name = order?.Name`
|
|
❌ NEVER use: `var value = dict?[key]`
|
|
✅ ALWAYS use explicit null checks:
|
|
```csharp
|
|
var name = order != null ? order.Name : null;
|
|
if (dict != null && dict.ContainsKey(key)) { }
|
|
```
|
|
|
|
### Null-Coalescing Assignment (C# 8)
|
|
❌ NEVER use: `value ??= defaultValue;`
|
|
✅ ALWAYS use: `if (value == null) value = defaultValue;`
|
|
|
|
### Expression-Bodied Members (C# 6)
|
|
❌ NEVER use: `public int Property => value;`
|
|
❌ NEVER use: `public void Method() => DoSomething();`
|
|
✅ ALWAYS use full syntax:
|
|
```csharp
|
|
public int Property
|
|
{
|
|
get { return value; }
|
|
}
|
|
|
|
public void Method()
|
|
{
|
|
DoSomething();
|
|
}
|
|
```
|
|
|
|
### nameof Operator (C# 6)
|
|
❌ NEVER use: `throw new ArgumentNullException(nameof(param));`
|
|
✅ ALWAYS use: `throw new ArgumentNullException("param");`
|
|
|
|
### Auto-Property Initializers (C# 6)
|
|
❌ NEVER use: `public int Property { get; set; } = 10;`
|
|
✅ ALWAYS use constructor initialization:
|
|
```csharp
|
|
public int Property { get; set; }
|
|
|
|
public ClassName()
|
|
{
|
|
Property = 10;
|
|
}
|
|
```
|
|
|
|
### Using Static (C# 6)
|
|
❌ NEVER use: `using static System.Math;`
|
|
✅ ALWAYS use: `System.Math.Floor(...)`
|
|
|
|
### Tuple Syntax (C# 7)
|
|
❌ NEVER use: `var tuple = (name: "test", value: 1);`
|
|
✅ ALWAYS use: `Tuple<string, int>` or custom classes
|
|
|
|
### Pattern Matching (C# 7+)
|
|
❌ NEVER use: `if (obj is string str)`
|
|
✅ ALWAYS use: `if (obj is string) { var str = (string)obj; }`
|
|
|
|
### Local Functions (C# 7)
|
|
❌ NEVER use functions inside methods
|
|
✅ ALWAYS use private methods
|
|
|
|
### Out Variables (C# 7)
|
|
❌ NEVER use: `if (dict.TryGetValue(key, out var value))`
|
|
✅ ALWAYS use:
|
|
```csharp
|
|
OrderStatus value;
|
|
if (dict.TryGetValue(key, out value))
|
|
{
|
|
// Use value
|
|
}
|
|
```
|
|
|
|
## Verification
|
|
After writing ANY code, verify C# 5.0 compliance:
|
|
- No `$` signs except in string literals
|
|
- No `?.` or `?[` operators
|
|
- No `=>` except in lambda expressions
|
|
- No inline variable declarations in out parameters
|