Thank you for your interest in contributing to TagLibSharp2! This document provides guidelines for contributing to the project.
- Fork the repository
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/tagsharp.git - Create a branch:
git checkout -b feature/your-feature-name - Make your changes
- Run tests:
dotnet test - Commit and push
- Open a Pull Request
- .NET 8.0 SDK or later
- Your preferred IDE (VS Code, Visual Studio, Rider)
dotnet build # Build all targets
dotnet test # Run all tests
dotnet test --filter "ClassName~BinaryData" # Run specific testsSee docs/BUILDING.md for detailed build instructions.
We use .editorconfig to enforce consistent style. Key conventions:
- Indentation: Tabs (4-space width)
- Space before parentheses:
Method ()notMethod() - Braces: New line for types/methods only
- Line length: 120 characters max
// Correct
public void ProcessData (byte[] data)
{
if (data is null)
throw new ArgumentNullException (nameof (data));
foreach (var item in data) {
Process (item);
}
}| Element | Convention | Example |
|---|---|---|
| Classes | PascalCase | BinaryDataBuilder |
| Methods | PascalCase | AddUInt32BE |
| Parameters | camelCase | initialCapacity |
| Private fields | _camelCase | _buffer |
| Constants | PascalCase | DefaultCapacity |
- var: Use when type is apparent
- Null checks: Use
is null/is not null(not== null) - File-scoped namespaces: Yes
- Primary constructors: Yes, when appropriate
- No regions: Never use
#region
- Code compiles without warnings (
TreatWarningsAsErrorsis enabled) - All tests pass on all target frameworks (
dotnet test) - New code has tests
- Code follows project style (run
dotnet formatto check)
Use a clear, descriptive title:
Add BinaryDataBuilder for mutable binary constructionFix overflow in RemoveRange validationImprove AddString performance for netstandard2.0
Include:
- What: Brief description of changes
- Why: Motivation or issue being fixed
- Testing: How you tested the changes
We use MSTest. Tests should be:
- Focused: One behavior per test
- Named clearly:
MethodName_Scenario_ExpectedResult - Independent: No shared mutable state
[TestMethod]
public void AddUInt32BE_WritesCorrectBytes ()
{
var builder = new BinaryDataBuilder ();
builder.AddUInt32BE (0x12345678);
Assert.AreEqual (4, builder.Length);
Assert.AreEqual ((byte)0x12, builder[0]);
Assert.AreEqual ((byte)0x78, builder[3]);
}All public APIs should have tests covering:
- Happy path: Expected inputs and outputs
- Boundary conditions: Zero, max values, empty input
- Error conditions: Invalid inputs, expected exceptions
// Happy path
[TestMethod]
public void AddUInt24BE_WritesCorrectBytes () { ... }
// Boundary
[TestMethod]
public void AddUInt24BE_MaxValue_WritesCorrectBytes () { ... }
[TestMethod]
public void AddUInt24BE_ZeroValue_WritesCorrectBytes () { ... }
// Error condition
[TestMethod]
public void AddUInt24BE_ExceedsMax_ThrowsArgumentOutOfRange () { ... }TagLibSharp2 prioritizes performance. When contributing:
Benchmark when modifying:
- Methods with
[MethodImpl(AggressiveInlining)] - Loops processing data (>1KB)
- String encoding operations
- Buffer allocation strategies
- Avoid allocations in hot paths - Use
Span<T>andstackalloc - Use
[AggressiveInlining]- For small, frequently-called methods (allAdd*methods use this) - Pre-size builders - When final size is known
- Prefer
.Spanover.Slice()- Span is zero-copy; Slice allocates
For significant performance changes, benchmarks will be added to tests/TagLibSharp2.Benchmarks/:
[MemoryDiagnoser]
public class BinaryDataBenchmarks
{
[Benchmark]
public void ParseHeader_1KB () { ... }
}Run with: dotnet run -c Release --project tests/TagLibSharp2.Benchmarks
See docs/ARCHITECTURE.md for the overall design.
Key patterns:
- Immutable + Builder:
BinaryData(immutable) +BinaryDataBuilder(mutable) - Specification-driven: Follow official format specs (ID3, Xiph, etc.)
- Multi-target: Support netstandard2.0 through net10.0
When reporting bugs:
- Check existing issues first
- Include .NET version and OS
- Provide minimal reproduction steps
- Include relevant error messages/stack traces
- Open a GitHub Discussion for questions
- Open an Issue for bugs or feature requests
By contributing, you agree that your contributions will be licensed under the MIT License.