|
| 1 | +# Contributing to ThunderDesign.Net-PCL.Threading |
| 2 | + |
| 3 | +Thank you for your interest in contributing to ThunderDesign.Net-PCL.Threading! We welcome contributions from the community and are grateful for your help in making this library better. |
| 4 | + |
| 5 | +## 🚀 Quick Start |
| 6 | + |
| 7 | +1. Fork the repository |
| 8 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 9 | +3. Make your changes |
| 10 | +4. Run tests (`dotnet test`) |
| 11 | +5. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 12 | +6. Push to the branch (`git push origin feature/amazing-feature`) |
| 13 | +7. Open a Pull Request |
| 14 | + |
| 15 | +## 📋 Table of Contents |
| 16 | + |
| 17 | +- [Code of Conduct](#code-of-conduct) |
| 18 | +- [How Can I Contribute?](#how-can-i-contribute) |
| 19 | +- [Development Setup](#development-setup) |
| 20 | +- [Coding Standards](#coding-standards) |
| 21 | +- [Testing Guidelines](#testing-guidelines) |
| 22 | +- [Source Generator Development](#source-generator-development) |
| 23 | +- [Pull Request Process](#pull-request-process) |
| 24 | +- [Issue Reporting](#issue-reporting) |
| 25 | + |
| 26 | +## 🤝 Code of Conduct |
| 27 | + |
| 28 | +This project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [project maintainer email]. |
| 29 | + |
| 30 | +## 🛠 How Can I Contribute? |
| 31 | + |
| 32 | +### Reporting Bugs |
| 33 | + |
| 34 | +Before creating bug reports, please check the [existing issues](https://github.com/ThunderDesign/ThunderDesign.Net-PCL.Threading/issues) to avoid duplicates. |
| 35 | + |
| 36 | +When filing a bug report, please include: |
| 37 | +- **Clear title and description** |
| 38 | +- **Steps to reproduce** the behavior |
| 39 | +- **Expected vs actual behavior** |
| 40 | +- **Environment details** (.NET version, OS, etc.) |
| 41 | +- **Sample code** if applicable |
| 42 | + |
| 43 | +### Suggesting Enhancements |
| 44 | + |
| 45 | +Enhancement suggestions are welcome! Please: |
| 46 | +- Use a clear and descriptive title |
| 47 | +- Provide a detailed description of the proposed enhancement |
| 48 | +- Explain why this enhancement would be useful |
| 49 | +- Include code examples if applicable |
| 50 | + |
| 51 | +### Contributing Code |
| 52 | + |
| 53 | +We welcome the following types of contributions: |
| 54 | +- Bug fixes |
| 55 | +- New thread-safe collection types |
| 56 | +- Performance improvements |
| 57 | +- Source generator enhancements |
| 58 | +- Documentation improvements |
| 59 | +- Test coverage improvements |
| 60 | + |
| 61 | +## 🔧 Development Setup |
| 62 | + |
| 63 | +### Prerequisites |
| 64 | + |
| 65 | +- [.NET SDK 8.0](https://dotnet.microsoft.com/download) (latest) |
| 66 | +- [Visual Studio 2022](https://visualstudio.microsoft.com/) or [Visual Studio Code](https://code.visualstudio.com/) |
| 67 | +- [Git](https://git-scm.com/) |
| 68 | + |
| 69 | +### Setting Up Your Development Environment |
| 70 | + |
| 71 | +1. **Fork and clone the repository:** |
| 72 | + |
| 73 | +```console |
| 74 | +git clone https://github.com/YOUR_USERNAME/ThunderDesign.Net-PCL.Threading.git cd ThunderDesign.Net-PCL.Threading |
| 75 | +``` |
| 76 | + |
| 77 | +2. **Restore dependencies:** |
| 78 | + |
| 79 | +```console |
| 80 | +dotnet restore |
| 81 | +``` |
| 82 | + |
| 83 | +3. **Build the solution:** |
| 84 | + |
| 85 | +```console |
| 86 | +dotnet build |
| 87 | +``` |
| 88 | + |
| 89 | +4. **Run tests:** |
| 90 | + |
| 91 | +```console |
| 92 | +dotnet test |
| 93 | +``` |
| 94 | + |
| 95 | +### Project Structure |
| 96 | + |
| 97 | +├── ThunderDesign.Net-PCL.Threading/ # Main library |
| 98 | +├── ThunderDesign.Net-PCL.Threading.Shared/ # Shared components |
| 99 | +├── ThunderDesign.Net-PCL.SourceGenerators/ # Source generators |
| 100 | +├── ThunderDesign.Net-PCL.Threading.Tests/ # Unit tests |
| 101 | +└── samples/ # Example projects |
| 102 | + |
| 103 | +## 📝 Coding Standards |
| 104 | + |
| 105 | +### General Guidelines |
| 106 | + |
| 107 | +- Follow [Microsoft's C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions) |
| 108 | +- Use meaningful names for variables, methods, and classes |
| 109 | +- Write self-documenting code with clear comments where necessary |
| 110 | +- Keep methods focused and concise |
| 111 | + |
| 112 | +### Naming Conventions |
| 113 | + |
| 114 | +- **Classes**: PascalCase (`ThreadSafeCollection`) |
| 115 | +- **Methods**: PascalCase (`GetProperty`) |
| 116 | +- **Properties**: PascalCase (`IsThreadSafe`) |
| 117 | +- **Fields**: camelCase with underscore prefix (`_lockObject`) |
| 118 | +- **Constants**: PascalCase (`DefaultTimeout`) |
| 119 | +- **Interfaces**: PascalCase with 'I' prefix (`IThreadSafe`) |
| 120 | + |
| 121 | +### Threading Considerations |
| 122 | + |
| 123 | +Since this is a threading library, please ensure: |
| 124 | +- All public members are thread-safe unless explicitly documented otherwise |
| 125 | +- Use appropriate locking mechanisms (prefer `lock` statements) |
| 126 | +- Consider performance implications of synchronization |
| 127 | +- Document thread-safety guarantees in XML comments |
| 128 | + |
| 129 | +### XML Documentation |
| 130 | + |
| 131 | +All public APIs must include XML documentation: |
| 132 | + |
| 133 | +```csharp |
| 134 | +/// <summary> |
| 135 | +/// Provides thread-safe access to a collection of items. |
| 136 | +/// </summary> |
| 137 | +/// <typeparam name="T">The type of elements in the collection.</typeparam> |
| 138 | +public class ThreadSafeCollection<T> : ICollection<T> |
| 139 | +{ |
| 140 | + /// <summary> |
| 141 | + /// Gets the number of elements in the collection in a thread-safe manner. |
| 142 | + /// </summary> |
| 143 | + /// <returns>The number of elements in the collection.</returns> |
| 144 | + public int Count |
| 145 | + { |
| 146 | + get; |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +## 🧪 Testing Guidelines |
| 152 | + |
| 153 | +### Writing Tests |
| 154 | + |
| 155 | +- Use [xUnit](https://xunit.net/) for unit tests |
| 156 | +- Follow the Arrange-Act-Assert pattern |
| 157 | +- Test both success and failure scenarios |
| 158 | +- Include thread-safety tests where applicable |
| 159 | +- Aim for high code coverage |
| 160 | + |
| 161 | +### Test Organization |
| 162 | + |
| 163 | +```csharp |
| 164 | +public class ThreadSafeCollectionTests |
| 165 | +{ |
| 166 | + [Fact] |
| 167 | + public void Add_SingleItem_IncreasesCount() |
| 168 | + { |
| 169 | + // Arrange var collection = new ThreadSafeCollection<int>(); |
| 170 | + // Act |
| 171 | + collection.Add(1); |
| 172 | + |
| 173 | + // Assert |
| 174 | + Assert.Equal(1, collection.Count); |
| 175 | + } |
| 176 | + |
| 177 | + [Fact] |
| 178 | + public void ConcurrentAccess_MultipleThreads_MaintainsConsistency() |
| 179 | + { |
| 180 | + // Test concurrent operations |
| 181 | + } |
| 182 | +} |
| 183 | +``` |
| 184 | + |
| 185 | +### Running Tests |
| 186 | + |
| 187 | +Run all tests |
| 188 | +```console |
| 189 | +dotnet test |
| 190 | +``` |
| 191 | +Run tests with coverage |
| 192 | +```console |
| 193 | +dotnet test --collect:"XPlat Code Coverage" |
| 194 | +``` |
| 195 | +Run specific test project |
| 196 | +```console |
| 197 | +dotnet test ThunderDesign.Net-PCL.Threading.Tests/ |
| 198 | +``` |
| 199 | + |
| 200 | +## ⚙️ Source Generator Development |
| 201 | + |
| 202 | +When working on source generators: |
| 203 | + |
| 204 | +### Guidelines |
| 205 | + |
| 206 | +- Follow the [Source Generator Cookbook](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md) |
| 207 | +- Ensure generators are deterministic |
| 208 | +- Handle edge cases gracefully |
| 209 | +- Provide meaningful error messages |
| 210 | +- Test with various input scenarios |
| 211 | + |
| 212 | +### Testing Source Generators |
| 213 | + |
| 214 | +```csharp |
| 215 | +[Fact] |
| 216 | +public void PropertyGenerator_WithValidField_GeneratesExpectedCode() |
| 217 | +{ |
| 218 | + var source = @" public partial class TestClass |
| 219 | + { |
| 220 | + [Property] private string _name; |
| 221 | + }"; |
| 222 | + var expected = @" |
| 223 | +
|
| 224 | + public partial class TestClass |
| 225 | + { |
| 226 | + public string Name |
| 227 | + { |
| 228 | + get { return this.GetProperty(ref _name, _Locker); } |
| 229 | + set { this.SetProperty(ref _name, value, _Locker); } |
| 230 | + } |
| 231 | + }"; |
| 232 | + |
| 233 | + // Test the generator |
| 234 | + VerifyGenerator(source, expected); |
| 235 | +} |
| 236 | +``` |
| 237 | + |
| 238 | +## 📬 Pull Request Process |
| 239 | + |
| 240 | +### Before Submitting |
| 241 | + |
| 242 | +1. **Update documentation** if you've changed APIs |
| 243 | +2. **Add or update tests** for your changes |
| 244 | +3. **Ensure all tests pass** locally |
| 245 | +4. **Follow the coding standards** |
| 246 | +5. **Update the changelog** if applicable |
| 247 | + |
| 248 | +### Pull Request Template |
| 249 | + |
| 250 | +When creating a pull request, please: |
| 251 | + |
| 252 | +1. **Use a clear title** that describes the change |
| 253 | +2. **Reference any related issues** (`Fixes #123`) |
| 254 | +3. **Describe your changes** in detail |
| 255 | +4. **List any breaking changes** |
| 256 | +5. **Include screenshots** for UI-related changes |
| 257 | + |
| 258 | +### Review Process |
| 259 | + |
| 260 | +1. At least one maintainer will review your PR |
| 261 | +2. Address any feedback promptly |
| 262 | +3. Keep your branch up to date with main |
| 263 | +4. Once approved, a maintainer will merge your PR |
| 264 | + |
| 265 | +## 🐛 Issue Reporting |
| 266 | + |
| 267 | +### Bug Reports |
| 268 | + |
| 269 | +Use the bug report template and include: |
| 270 | +- Clear reproduction steps |
| 271 | +- Expected vs actual behavior |
| 272 | +- Environment information |
| 273 | +- Minimal code sample |
| 274 | + |
| 275 | +### Feature Requests |
| 276 | + |
| 277 | +Use the feature request template and include: |
| 278 | +- Clear description of the feature |
| 279 | +- Use cases and benefits |
| 280 | +- Possible implementation approach |
| 281 | + |
| 282 | +## 📞 Getting Help |
| 283 | + |
| 284 | +- **GitHub Issues**: For bugs and feature requests |
| 285 | +- **Discussions**: For questions and general discussion |
| 286 | +- **Discord/Slack**: [Add community chat links if available] |
| 287 | + |
| 288 | +## 🏷️ Versioning |
| 289 | + |
| 290 | +We use [Semantic Versioning](http://semver.org/) (SemVer): |
| 291 | +- **MAJOR**: Breaking changes |
| 292 | +- **MINOR**: New features (backward compatible) |
| 293 | +- **PATCH**: Bug fixes (backward compatible) |
| 294 | + |
| 295 | +## 📄 License |
| 296 | + |
| 297 | +By contributing, you agree that your contributions will be licensed under the same license as the project. |
| 298 | + |
| 299 | +--- |
| 300 | + |
| 301 | +Thank you for contributing to ThunderDesign.Net-PCL.Threading! 🎉 |
0 commit comments