-
Notifications
You must be signed in to change notification settings - Fork 1
Why this Project exists
Projects, big or small, require casting or conversion of types in one way or another.
Aside the option of declaring specific conversion methods in a class as in ToSomeType()
, C# offers implicit and explicit operators,
and static extension methods for a given Type, which as a compiler trick is incredibly efficient.
This project attempts to provide a comprehensive, easy to use, well tested interface that follows best-practices of conversion through a centralized interface.
The problem with specific class declarations for type conversion is short and simple code maintainability.
Whilst custom conventions can be enforced through the use of interfaces, the level of enforcement is insufficient with the lack of declaring non-static methods
such as operators whilst offering nothing to prevent unnecessary code repetition, which implies additional code that needs to be maintained and tested.
Say you are implementing ToProtein()
in one class, an implicit operator in another
and whilst a peer declared an explicit conversion operator in a third class.
You may soon be left with the sobering conclusion that in another derived class that concept does
not scale anymore as you continuously fix bugs or get compiler errors, necessitating you to adapt the code.
Whilst this may be quickly facilitated at first, it is rarely done so in the required attentive fashion is desired to prevent new bugs.
The benefit of adopting this library into your project is the ability of
- scalability
- unburdening the programmer of unnecessary pitfalls
- plays well with interactive shells (REPLs)
- rapid prototyping
- drastically reduced code maintenance
- consistent strong typing
- consistent, assertive exceptions and consistent handling thereof as well as
- common conventions towards implementation,
Moreover a common conversion interface allows easier testing through integration, unit and mocking tests, with many pre-baked examples that one can copy and paste with few custom adaptations.
Ultimately several threads may concurrently interact with the converter collection instance at runtime.
To facilitate correct threading behavior a BlockingCollection
is used.
All library method: Cast
, Convert
and Transform
feature a sibling "Try"-method that follows the "Try" convention of .NET .
It accepts an object "value" and an out parameter of type T, "result". An attempt is made to cast the value into the result as type T.
If the process succeeds, true
is returned, else the converter sets result = default(T)
and returns false
.
Project Links
NuGet | MyGet| Appveyor | Twitter @sauerlo