PowerupCore 1.0.3
dotnet add package PowerupCore --version 1.0.3
NuGet\Install-Package PowerupCore -Version 1.0.3
<PackageReference Include="PowerupCore" Version="1.0.3" />
paket add PowerupCore --version 1.0.3
#r "nuget: PowerupCore, 1.0.3"
// Install PowerupCore as a Cake Addin
#addin nuget:?package=PowerupCore&version=1.0.3
// Install PowerupCore as a Cake Tool
#tool nuget:?package=PowerupCore&version=1.0.3
PowerUp, extension methods library for .Net CORE
PowerUp is an extension methods library for .Net CORE, it add usefull functionalities to the framework.<br />
Download
PowerupCore Nuget<br /> PowerupCore Azure Nuget<br />
What is different about this library?
β© Lightweight: the goal is not to contains 5k methods, but to only have everyday useful methods (in my opinion π)<br /> π .Net CORE compatible<br /> π₯ Unit tested<br /> π€ 100% documented<br />
All the extension method are explained and a Raison d'Γͺtre is provided in the following documentation.
Contents
StringExtensions
IsInteger
Simplify the syntax necessary to verify wehather the string content is an inter or not.<br> Why?<br> To remove repetitive code
if("42".IsInteger())
Foo();
Remove
Removes from a string the content of the parameter string.<br> Why?<br> To remove repetitive code
"My text".Remove("My") // result: " text"
// instead of
"My text".Replace("My", string.Empty); // result: " text"
Foo();
Format
Gives a shorter syntax for the string's method Format.<br> Why?<br> To make the code shorter
// .net syntax
string.Format("Debug Level: {0} \"{1}\" {3}", DebugLevel.Info, "Everything is awesome!", DateTime.Now);
// PowerUp syntax
"Debug Level: {0} \"{1}\" {3}".Format(DebugLevel.Info, "Everything is awesome!", DateTime.Now);
ToEnum<>
Allows to easily convert a tring to an enum.<br> Why?<br> To remove repetitive code
private enum TestEnum
{
Val1,
Val2,
Val3
}
var enumVar = "Val1".ToEnum<TestEnum>();
EnumExtensions
GetDescription<>
Allows to get the readable description of the enum value.
private enum TestEnum
{
[Description("Value with description")]
ValWithDesc = 1,
ValNoDesc = 2,
AnotherNoDesc =3
}
var testObject = TestEnum.ValWithDesc;
string description = testObject.GetDescription();
CollectionExtensions
RemoveRange<>
Helps to remove more elements at once from a collection.<br> Why?<br> To provide a usefull addidional features to collections
sourceList.RemoveRange(deleteList);
Clone<>
Performs a deep copy frim a collection of ICloneable objects.
var testList = _fixture.Create<List<clonableObj>>();
var clone = testList.Clone();
clone.First() != testList.First()
GetLastIndex<>
Gets the last index of a collection.<br> Why?<br> To remove repetitive code
sourceList.GetLastIndex() == (sourceList.Count - 1)
GenericExtensions
ThrowIfNull<>
Throws ArgumentNullException if the given argument is null.<br> Why?<br> To replace the Guard.ArgumentNotNull in .net CORE
objectShouldNotBeNUll.ThrowIfNull(nameof(objectShouldNotBeNUll));
// Inspired on Microsoft.Practices.EnterpriseLibrary.Common.Utility
Guard.ArgumentNotNull(objectShouldNotBeNUll, nameof(objectShouldNotBeNUll));
IsNull<> and IsNotNull<>
Verify that a object is null or not null.<br> Why?<br> To make the syntax to verify null cleaner and more human readable
var someObject = new object();
//Before
if(someObject!=null)
Foo();
//PowerUp
if(someObject.isNull())
Foo();
Between<>
Verify that the object value is between the lower and upper bound.<br> Why?<br> To simplify the syntax to verify that an onbject value is between a certain range
if(5.Between(2, 8))
Foo();
if(7.Between(7, 12, BetweenOptions.Inclusive))
Foo();
LoggerExtensions
LogThisMethod
Allows to simply log information about the calling method.<br> Why?<br> To avoid boring code, and copy paste problem the tipical scenario is at the beginning of a Controller method like:
[HttpPut]
[Route("[action]")]
[Produces("application/json")]
[ProducesResponseType(typeof(Product), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> AddProduct([FromBody] NewProduct newProduct)
{
_logger.LogDebug($"{DateTime.UtcNow:dd/MMM/yyyy} | 32: CatalogController.AddProduct()}");
if (!ModelState.IsValid)
return BadRequest(ModelState);
....
the logging method can now be simply:
...
public async Task<IActionResult> AddProduct([FromBody] NewProduct newProduct)
{
_logger.LogThisMethod();
...
It's easy from the example to see how much it can reduce the ammount of code and the possibility of errors
AzureExtensions
RedundantParse
The storage access keys in Azure are used in authentication for accessing the storage account.<br> When you create a storage account you are provided with two storage access keys i.e. Primary and Secondary access keys.<br> See more https://blogs.msdn.microsoft.com/mast/2013/11/06/why-does-an-azure-storage-account-have-two-access-keys/ <br> Why?<br> RedundantParse allowes you redundantly connect using the primary key or automatically switch to the seconday.
<add key="QueueConnectionString1" value="DefaultEndpointsProtocol=https;AccountName=weu##########" />
<add key="QueueConnectionString2" value="DefaultEndpointsProtocol=https;AccountName=weu##########" />
<add key="QueueReference" value="myQueueReference" />
var storageAccount = CloudStorageAccountHelper.RedundantParse(
CloudConfigurationManager.GetSetting("QueueConnectionString1"),
CloudConfigurationManager.GetSetting("QueueConnectionString2"));
var queueClient = storageAccount.CreateCloudQueueClient();
var myQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["QueueReference"]);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.1
- JetBrains.Annotations (>= 10.2.1)
- Microsoft.Extensions.Logging.Abstractions (>= 2.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.