SHARED UTILS: Making C# Quick, Easy and Safe
April 12, 2022 · View on GitHub
NOW MAUI READY !!!
SHARED UTILS: Making C# Quick, Easy and Safe
Programs Should Not Be Redundant In Any Way
SOLID and DRY guidance declare that we should keep our C# code simple, narrow, and non-redundant. For instance, simple code like this:
var areSame =
string.Compare(mainStr, otherStr, CurrentCulture.CurrentCultureIgnoreCase) == 0;
... is both ungainly and unnecessary. DRY does not refer to copying code like this, though it is certainly illegal:
var areSameCheckedAgainRedundantly =
string.Compare(mainStr, otherStr, CurrentCulture.CurrentCultureIgnoreCase) == 0;
DRY means: no redundancy whatsoever, regardless of where it lurks. In this example, a parameter is redundant, and the check for 0 is both static (not a variable but also not even a constant!) and redundant. The fix is easy -- just use our SharedUtils extensions to code this quickly and safely:
using Com.MarcusTS.SharedUtils;
if (mainStr.isSameAs(otherStr))
{
}
If you are looking for "not same as", then use this:
using Com.MarcusTS.SharedUtils;
if (mainStr.isDifferentThan(otherStr))
{
}
SharedUtils provides similar comparison extensions for many C# types, including DateTime, numbers, and even IEnumerables!
SharedUtils also offers:
- A BetterObservableCollection that manages events more safely than in the C# version.
- A FlexibleStack that allows manipulation of a common stack.
- Reflection helpers
- Thread helpers,including a thread-safe Boolean
- Task helpers
- Numeric rounding
SharedUtils Is Open Source; Enjoy Our Other Offerings
Shared Utils (MAUI Ready!)
The Smart DI Container (MAUI Ready!)
Responsive Tasks (MAUI Ready!)
PlatformIndependentShared (MAUI Ready!)
UI.XamForms
The Modern App Demo
