PowerUp is an extension methods library for .Net CORE, it add usefull functionalities to the framework.
PowerupCore Nuget
PowerupCore Azure Nuget
⏩ Lightweight: the goal is not to contains 5k methods, but to only have everyday useful methods (in my opinion )
.Net CORE compatible
Unit tested
100% documented
All the extension method are explained and a Raison d'être is provided in the following documentation.
Simplify the syntax necessary to verify wehather the string content is an inter or not.
Why?
To remove repetitive code
if("42".IsInteger())
Foo();Removes from a string the content of the parameter string.
Why?
To remove repetitive code
"My text".Remove("My") // result: " text"
// instead of
"My text".Replace("My", string.Empty); // result: " text"
Foo();Gives a shorter syntax for the string's method Format.
Why?
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);Allows to easily convert a tring to an enum.
Why?
To remove repetitive code
private enum TestEnum
{
Val1,
Val2,
Val3
}
var enumVar = "Val1".ToEnum<TestEnum>();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();Helps to remove more elements at once from a collection.
Why?
To provide a usefull addidional features to collections
sourceList.RemoveRange(deleteList);Performs a deep copy frim a collection of ICloneable objects.
var testList = _fixture.Create<List<clonableObj>>();
var clone = testList.Clone();
clone.First() != testList.First()Gets the last index of a collection.
Why?
To remove repetitive code
sourceList.GetLastIndex() == (sourceList.Count - 1)Throws ArgumentNullException if the given argument is null.
Why?
To replace the Guard.ArgumentNotNull in .net CORE
objectShouldNotBeNUll.ThrowIfNull(nameof(objectShouldNotBeNUll));
// Inspired on Microsoft.Practices.EnterpriseLibrary.Common.Utility
Guard.ArgumentNotNull(objectShouldNotBeNUll, nameof(objectShouldNotBeNUll));Verify that a object is null or not null.
Why?
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();Verify that the object value is between the lower and upper bound.
Why?
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();Allows to simply log information about the calling method.
Why?
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
The storage access keys in Azure are used in authentication for accessing the storage account.
When you create a storage account you are provided with two storage access keys i.e. Primary and Secondary access keys.
See more https://blogs.msdn.microsoft.com/mast/2013/11/06/why-does-an-azure-storage-account-have-two-access-keys/
Why?
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"]);