PowerupCore.Web 1.0.2

PowerUp extension methods library for .Net CORE

Install-Package PowerupCore.Web -Version 1.0.2
dotnet add package PowerupCore.Web --version 1.0.2
<PackageReference Include="PowerupCore.Web" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PowerupCore.Web --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

  1. StringExtensions
  2. EnumExtensions
  3. CollectionExtensions
  4. GenericExtensions
  5. AzureExtensions

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"]);

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

  1. StringExtensions
  2. EnumExtensions
  3. CollectionExtensions
  4. GenericExtensions
  5. AzureExtensions

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"]);

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 116 10/31/2018