Skip to content

Commit

Permalink
Merge pull request #23 from calebjenkins/develop
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
calebjenkins committed Jan 2, 2024
2 parents f4d79a4 + 876dedd commit b8d191c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 4 deletions.
Binary file added Assets/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -3,9 +3,12 @@
[![NuGet](https://img.shields.io/nuget/dt/calebs.extensions.svg)](https://www.nuget.org/packages/calebs.extensions)
[![NuGet](https://img.shields.io/nuget/vpre/calebs.extensions.svg)](https://www.nuget.org/packages/calebs.extensions)
[![.github/workflows/ci.yml](https://github.com/calebjenkins/Calebs.Extensions/actions/workflows/ci.yml/badge.svg)](https://github.com/calebjenkins/Calebs.Extensions/actions/workflows/ci.yml)

![Extensions Logo](https://raw.githubusercontent.com/calebjenkins/Calebs.Extensions/develop/Assets/logo.png)
# Calebs.Extensions
Useful extension methods and attributes for working with enums, strings and lists. The majority of these extensions were born out of working with various models while building micro services.


### Installing Calebs.Extensions

You should install [Extensions with NuGet](https://www.nuget.org/packages/Calebs.Extensions):
Expand Down Expand Up @@ -63,6 +66,9 @@ To use this helper - register `IFileIO` is your `DI` with `FileIO` as the implme
- Compare
- string?.ValueOrEmpty()

## ObjectExtensions
- ToSafeString()

## ListExtensions
- ToDelimitedList
- ToUpper
Expand All @@ -87,3 +93,4 @@ Merges to `main` publish to nuget as a major release.
- 1.3.0 - added `IFileIO` - an interface + implementation for making common filesystem opperations easier to test
- 1.3.1 - suppressed some test warnings and updated the GH workflows
- 1.4.0 - added `CreatedDiretory` and `DeleteDirectory` to `IFileIO`
- 1.5.0 - Added package logo and `ToSafeString` for `ObjectExtensions`
24 changes: 24 additions & 0 deletions src/ExtensionTests/ObjectExtensionTests.cs
@@ -0,0 +1,24 @@

namespace ExtensionTests;

using Calebs.Extensions;

public class ObjectExtensionTests
{
[Fact]
public void Nullable_Objects_Should_Return_Empty_String()
{
ExampleModel m = null;
var result = m.ToSafeString();
result.IsNullOrEmpty().Should().BeTrue();
}

[Fact]
public void Int_Should_Return_String_Value()
{
int five = 5;
var result = five.ToSafeString();
result.Should().Be("5");
}
}

3 changes: 1 addition & 2 deletions src/ExtensionTests/StringExtensionTests.cs
Expand Up @@ -26,5 +26,4 @@ public void ShouldReturnValueIfNotNull()

v2.Should().Be(value);
}
}

}
20 changes: 20 additions & 0 deletions src/Extensions/Console/ConsoleExtensions.cs
@@ -0,0 +1,20 @@

namespace Calebs.Extensions.Console
{
public static class ConsoleExtensions
{
public static void WriteLine (this System.ConsoleColor color, string text)
{
color.Write(text);
System.Console.WriteLine();
}

public static void Write (this System.ConsoleColor color, string text)
{
var currentColor = System.Console.ForegroundColor;
System.Console.ForegroundColor = color;
System.Console.Write(text);
System.Console.ForegroundColor = currentColor;
}
}
}
8 changes: 6 additions & 2 deletions src/Extensions/Extensions.csproj
Expand Up @@ -10,7 +10,7 @@
<Configurations>Debug;Release;NET7</Configurations>
<RootNamespace>Calebs.Extensions</RootNamespace>
<AssemblyName>Calebs.Extensions</AssemblyName>
<Version>1.4.0</Version>
<Version>1.5.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Caleb Jenkins</Authors>
<Company>Caleb Jenkins</Company>
Expand All @@ -25,12 +25,16 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageId>Calebs.Extensions</PackageId>
<PackageIconUrl />
<PackageIcon>logo.png</PackageIcon>
<Product>Calebs.Extensions</Product>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<None Include="..\..\Assets\logo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
Expand Down
10 changes: 10 additions & 0 deletions src/Extensions/ObjectExtensions.cs
@@ -0,0 +1,10 @@
namespace Calebs.Extensions;

public static class ObjectExtensions
{
public static string ToSafeString(this object o)
{
return o?.ToString() ?? string.Empty;
}
}

1 change: 1 addition & 0 deletions src/Extensions/StringExtensions.cs
Expand Up @@ -36,3 +36,4 @@ public static string ValueOrEmpty(this string? value)
return value;
}
}

0 comments on commit b8d191c

Please sign in to comment.