Wolfgang.Extensions.IEquatable
A lightweight .NET library that provides extension methods to simplify common equality comparison patterns.
🌟 Why Wolfgang.Extensions.IEquatable?
Writing clean, readable equality comparisons often involves repetitive boilerplate code. This library eliminates that repetition with simple, expressive extension methods.
Problems This Library Solves
- ❌ Verbose OR Chains:
if (x == a || x == b || x == c || x == d) - ❌ Verbose AND Chains:
if (x != a && x != b && x != c && x != d) - ❌ Null Reference Errors: Forgetting null checks in inequality comparisons
- ❌ Readability: Hard to parse complex conditional logic at a glance
Our Solution
- ✅ IsInSet: Check if a value matches any of a set of values
- ✅ IsNotInSet: Check if a value doesn't match any of a set of values
- ✅ NotEqual: Null-safe inequality comparison
📦 Installation
Choose your preferred installation method:
NuGet Package Manager
Install-Package Wolfgang.Extensions.IEquatable
.NET CLI
dotnet add package Wolfgang.Extensions.IEquatable
PackageReference
<PackageReference Include="Wolfgang.Extensions.IEquatable" Version="1.0.0" />
Note: Replace with the specific version you need. Check NuGet.org for available versions.
🎯 Requirements
Supported Frameworks:
- .NET Framework 4.6.2 or higher
- .NET Standard 2.0
- .NET 8.0
- .NET 10.0
Language Version:
- C# 7.3 or higher
The library is designed to work across a wide range of .NET platforms, making it suitable for both legacy and modern applications.
🚀 Quick Start
Example 1: IsInSet
using Wolfgang.Extensions.IEquatable;
// Before: Verbose OR chain
if (status == "active" || status == "pending" || status == "approved")
{
// Process valid status
}
// After: Clean and readable
if (status.IsInSet("active", "pending", "approved"))
{
// Process valid status
}
Example 2: IsNotInSet
using Wolfgang.Extensions.IEquatable;
// Before: Verbose AND chain
if (role != "admin" && role != "moderator" && role != "owner")
{
throw new UnauthorizedAccessException();
}
// After: Clean and readable
if (role.IsNotInSet("admin", "moderator", "owner"))
{
throw new UnauthorizedAccessException();
}
Example 3: NotEqual
using Wolfgang.Extensions.IEquatable;
// Null-safe inequality check
string? value1 = GetValue();
string? value2 = GetOtherValue();
if (value1.NotEqual(value2))
{
// Values are different (handles null safely)
}
🎯 Key Features
IsInSet Extension Methods
Check if a value matches any value in a set. Multiple overloads available:
- Single value:
item.IsInSet(value1) - Multiple values:
item.IsInSet(value1, value2, value3) - Collections:
item.IsInSet(array)oritem.IsInSet(collection)
IsNotInSet Extension Methods
Check if a value doesn't match any value in a set. Same overloads as IsInSet.
NotEqual Extension Method
Null-safe inequality comparison with proper reference equality checks.
Performance
- Minimal overhead with optimized implementations
- No allocations for simple value comparisons
- Efficient null checking
📚 Documentation
- Introduction: Learn about the library and its purpose
- Getting Started: Installation and basic usage
- Setup: Advanced configuration and customization
- API Reference: Detailed API documentation (generated by DocFX)
Project Structure
IEquatable-Extensions/
├── src/ # Source code
│ └── Wolfgang.Extensions.IEquatable/
├── tests/ # Unit tests
├── benchmarks/ # Performance benchmarks
├── examples/ # Usage examples
└── docs/ # Documentation
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide before submitting pull requests.
How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Inspired by common patterns in the .NET ecosystem
- Compatible with .NET Framework 4.6.2 through .NET 10
- Follows Microsoft's design guidelines for .NET libraries
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Online Docs
🌟 Show Your Support
If you find this library useful, please consider:
- ⭐ Starring the repository
- 📢 Sharing it with others
- 🐛 Reporting bugs or requesting features
- 🤝 Contributing to the codebase
Made with ❤️ by Chris Wolfgang