# NT8 SDK Code Style Guide ## Required Patterns for AI Agents ### Class Declaration Pattern ```csharp using System; using System.Collections.Generic; namespace NT8.Core.SomeModule { /// /// Class description /// public class ClassName { private readonly Type _field; /// /// Property description /// public Type PropertyName { get; set; } /// /// Constructor description /// public ClassName(Type parameter) { if (parameter == null) throw new ArgumentNullException("parameter"); _field = parameter; } /// /// Method description /// public ReturnType MethodName(Type parameter) { // Implementation } } } ``` ### Interface Implementation Pattern ```csharp /// /// Interface description /// public interface IInterfaceName { /// /// Method description /// ReturnType MethodName(Type parameter); } /// /// Implementation description /// public class Implementation : IInterfaceName { public ReturnType MethodName(Type parameter) { // Implementation } } ``` ### Dictionary Initialization Pattern (C# 5.0) ```csharp // ✅ REQUIRED Pattern var dictionary = new Dictionary(); dictionary.Add("key1", value1); dictionary.Add("key2", value2); // ❌ FORBIDDEN Pattern var dictionary = new Dictionary { ["key1"] = value1, ["key2"] = value2 }; ``` ### String Formatting Pattern (C# 5.0) ```csharp // ✅ REQUIRED Pattern var message = String.Format("Processing {0} with value {1:F2}", name, amount); _logger.LogInformation("Order {0} status: {1}", orderId, status); // ❌ FORBIDDEN Pattern var message = $"Processing {name} with value {amount:F2}"; _logger.LogInformation($"Order {orderId} status: {status}"); ``` ### Async Method Pattern (C# 5.0) ```csharp /// /// Async method description /// public async Task MethodNameAsync(Type parameter) { // Async implementation var result = await SomeAsyncOperation(); return result; } ``` ### Error Handling Pattern ```csharp public ReturnType MethodName(Type parameter) { if (parameter == null) throw new ArgumentNullException("parameter"); try { // Implementation return result; } catch (SpecificException ex) { _logger.LogError("Specific error occurred: {0}", ex.Message); throw; // or handle appropriately } catch (Exception ex) { _logger.LogError("Unexpected error: {0}", ex.Message); throw; } } ``` ### Test Class Pattern (MSTest) ```csharp using Microsoft.VisualStudio.TestTools.UnitTesting; using NT8.Core.SomeModule; namespace NT8.Core.Tests.SomeModule { [TestClass] public class ClassNameTests { private ClassName _target; [TestInitialize] public void TestInitialize() { _target = new ClassName(/* parameters */); } [TestMethod] public void MethodName_Condition_ExpectedResult() { // Arrange var input = /* test data */; // Act var result = _target.MethodName(input); // Assert Assert.IsTrue(result.Success); Assert.AreEqual(expected, result.Value); } [TestMethod] public void MethodName_InvalidInput_ThrowsException() { // Act & Assert Assert.ThrowsException(() => _target.MethodName(null)); } } } ``` ### Configuration Class Pattern ```csharp /// /// Configuration class description /// public class ConfigurationClass { /// /// Property description /// public Type PropertyName { get; set; } /// /// Constructor with all required parameters /// public ConfigurationClass(Type parameter1, Type parameter2) { PropertyName1 = parameter1; PropertyName2 = parameter2; } } ``` ### Enum Pattern ```csharp /// /// Enum description /// public enum EnumName { /// /// First value description /// FirstValue, /// /// Second value description /// SecondValue } ``` ## Naming Conventions ### Classes and Interfaces - **Classes**: PascalCase (`RiskManager`, `PositionSizer`) - **Interfaces**: IPascalCase (`IRiskManager`, `IPositionSizer`) ### Methods and Properties - **Methods**: PascalCase (`ValidateOrder`, `CalculateSize`) - **Properties**: PascalCase (`Symbol`, `Quantity`) ### Fields and Variables - **Private fields**: _camelCase (`_logger`, `_riskConfig`) - **Local variables**: camelCase (`riskAmount`, `contracts`) - **Constants**: UPPER_CASE (`MAX_CONTRACTS`, `DEFAULT_TIMEOUT`) ### Parameters - **Parameters**: camelCase (`intent`, `context`, `config`) ## File Organization ### Using Statements Order ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NT8.Core.Common.Models; using NT8.Core.Logging; ``` ### Namespace and Class Structure ```csharp namespace NT8.Core.ModuleName { /// /// Class documentation /// public class ClassName { // 1. Private fields private readonly Type _field; // 2. Public properties public Type Property { get; set; } // 3. Constructor(s) public ClassName() { } // 4. Public methods public void PublicMethod() { } // 5. Private methods private void PrivateMethod() { } } } ``` These patterns MUST be followed by all AI agents to ensure consistency and compatibility.