Skip to content

Commit a05a0af

Browse files
authored
Merge pull request #2 from astar-development/features/initial-port-of-code
Features/initial port of code
2 parents 7fe17e9 + efc650e commit a05a0af

File tree

13 files changed

+334
-12
lines changed

13 files changed

+334
-12
lines changed

Readme.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
# AStar.Dev.Utilities
1+
# AStar Utilities
22

3-
## GitHub build
3+
A collection of useful utilities. At the moment, the collection is small but will grow as time and need permits.
44

5-
[![Build and test solution](https://github.com/jbarden/astar-dev-utilities/actions/workflows/dotnet.yml/badge.svg)](https://github.com/jbarden/astar-dev-utilities/actions/workflows/dotnet.yml)
5+
## Utilities
66

7-
## SonarCloud Analysis Results
7+
### String Utilities
8+
9+
* IsNull - as you might expect, checks whether the string is, in fact, null.
10+
* IsNotNull - as you might expect, checks whether the string is not null.
11+
* IsNullOrWhiteSpace - as you might expect, checks whether the string is, in fact, null, empty or whitespace. *new*
12+
* IsNotNullOrWhiteSpace - as you might expect, checks whether the string is not null, empty or whitespace. *new*
13+
* FromJson - as you might expect, converts the JSON representation to the requested Type.
14+
15+
### String Utilities
816

9-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
17+
* ToJson - as you might expect, converts the object to the appropriate JSON representation.
18+
19+
## GitHub build
20+
[![Build and test solution](https://github.com/astar-development/astar-dev-utilities/actions/workflows/dotnet.yml/badge.svg)](https://github.com/astar-development/astar-dev-utilities/actions/workflows/dotnet.yml)
21+
22+
## SonarCloud Analysis Results
1023

11-
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=bugs)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
24+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)
1225

13-
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
26+
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=bugs)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)
1427

15-
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
28+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)
1629

17-
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=coverage)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
30+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)
1831

19-
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=jbarden_astar-dev-utilities&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=jbarden_astar-dev-utilities)
32+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=coverage)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)
2033

34+
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=astar-development_astar-dev-utilities&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=astar-development_astar-dev-utilities)

src/AStar.Dev.Utilities/AStar.Dev.Utilities.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
<RepositoryType>git</RepositoryType>
3030
<PackageProjectUrl>https://github.com/jbarden/astar-dev-utilities</PackageProjectUrl>
3131
<Description>A collection of useful utilities.</Description>
32-
<Version>1.4.0</Version>
32+
<Version>1.5.0</Version>
3333
<Authors>AStar Development, Jason Barden</Authors>
3434
<DocumentationFile>$(AssemblyName).xml</DocumentationFile>
3535
<PackageIcon>AStar.png</PackageIcon>
3636
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
37-
<PackageReleaseNotes>version 1.4.0, no changes - version increased as part of the migration to the new AStar NuGet / GitHub organisations.</PackageReleaseNotes>
37+
<PackageReleaseNotes>version 1.5.0 contains the initial code port from the jbarden NuGet / GitHub organisations.</PackageReleaseNotes>
3838
</PropertyGroup>
3939

4040
<ItemGroup>

src/AStar.Dev.Utilities/AStar.Dev.Utilities.xml

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text.Json;
2+
3+
namespace AStar.Utilities;
4+
5+
/// <summary>
6+
/// The <see href="Constants"></see>see> class contains static / constant properties to simplify and centralise various settings.
7+
/// </summary>
8+
public static class Constants
9+
{
10+
/// <summary>
11+
/// Returns an instance of <see href="JsonSerializerOptions"></see> configured with the Web defaults.
12+
/// </summary>
13+
public static JsonSerializerOptions WebDeserialisationSettings => new(JsonSerializerDefaults.Web);
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace AStar.Utilities;
2+
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public static class EnumExtensions
7+
{
8+
/// <summary>
9+
///
10+
/// </summary>
11+
/// <typeparam name="T"></typeparam>
12+
/// <param name="value"></param>
13+
/// <returns></returns>
14+
public static T ParseEnum<T>(this string value) => (T)Enum.Parse(typeof(T), value, true);
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Text.Json;
2+
3+
namespace AStar.Utilities;
4+
5+
/// <summary>
6+
/// The <see cref="ObjectExtensions" /> class contains some useful methods to enable various tasks
7+
/// to be performed in a more fluid, English sentence, style.
8+
/// </summary>
9+
public static class ObjectExtensions
10+
{
11+
/// <summary>
12+
/// The ToJson method, as you might expect, converts the supplied object to its JSON equivalent.
13+
/// </summary>
14+
/// <param name="object">The object to convert to JSON.</param>
15+
/// <returns>The JSON string of the object supplied.</returns>
16+
public static string ToJson<T>(this T @object) => JsonSerializer.Serialize(@object);
17+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Text.Json;
2+
3+
namespace AStar.Utilities;
4+
5+
/// <summary>
6+
/// The <see cref="StringExtensions" /> class contains some useful methods to enable checks to be
7+
/// performed in a more fluid, English sentence, style.
8+
/// </summary>
9+
public static class StringExtensions
10+
{
11+
/// <summary>
12+
/// The IsNull method, as you might expect, checks whether the string is, in fact, null.
13+
/// </summary>
14+
/// <param name="value">The string to check for being null.</param>
15+
/// <returns>True if the string is null, False otherwise.</returns>
16+
public static bool IsNull(this string? value) => value is null;
17+
18+
/// <summary>
19+
/// The IsNotNull method, as you might expect, checks whether the string is not null.
20+
/// </summary>
21+
/// <param name="value">The string to check for being not null.</param>
22+
/// <returns>True if the string is not null, False otherwise.</returns>
23+
public static bool IsNotNull(this string? value) => !value.IsNull();
24+
25+
/// <summary>
26+
/// The IsNullOrWhiteSpace method, as you might expect, checks whether the string is, in fact, null, empty or whitespace.
27+
/// </summary>
28+
/// <param name="value">The string to check for being null, empty or whitespace.</param>
29+
/// <returns>True if the string is null, empty or whitespace, False otherwise.</returns>
30+
public static bool IsNullOrWhiteSpace(this string? value) => string.IsNullOrWhiteSpace(value);
31+
32+
/// <summary>
33+
/// The IsNotNullOrWhiteSpace method, as you might expect, checks whether the string is not null, empty or whitespace.
34+
/// </summary>
35+
/// <param name="value">The string to check for being not null, empty or whitespace.</param>
36+
/// <returns>True if the string is not null, empty or whitespace, False otherwise.</returns>
37+
public static bool IsNotNullOrWhiteSpace(this string? value) => !value.IsNullOrWhiteSpace();
38+
39+
/// <summary>
40+
/// The FromJson method, as you might expect, converts the supplied JSON to the specified object.
41+
/// </summary>
42+
/// <typeparam name="T">The required type of the object to deserialise to.</typeparam>
43+
/// <param name="json">The JSON representation of the object.</param>
44+
/// <returns>A deserialised object based on the original JSON.</returns>
45+
public static T FromJson<T>(this string json) => JsonSerializer.Deserialize<T>(json)!;
46+
47+
/// <summary>
48+
/// The FromJson method, as you might expect, converts the supplied JSON to the specified object.
49+
/// </summary>
50+
/// <typeparam name="T">The required type of the object to deserialise to.</typeparam>
51+
/// <param name="json">The JSON representation of the object.</param>
52+
/// <param name="options">Allows the specific <see href="JsonSerializerOptions">options</see> to be set to control deserialisation.</param>
53+
/// <returns>A deserialised object based on the original JSON.</returns>
54+
public static T FromJson<T>(this string json, JsonSerializerOptions options) => JsonSerializer.Deserialize<T>(json, options)!;
55+
}

tests/unit/AStar.Dev.Utilities.Unit.Tests/AStar.Dev.Utilities.Unit.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
</PackageReference>
2323
</ItemGroup>
2424

25+
<ItemGroup>
26+
<ProjectReference Include="..\..\..\src\AStar.Dev.Utilities\AStar.Dev.Utilities.csproj" />
27+
</ItemGroup>
28+
2529
<ItemGroup>
2630
<Using Include="Xunit" />
2731
</ItemGroup>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
13+
<NoWarn>1701;1702;IDE0058;</NoWarn>
14+
</PropertyGroup>
15+
16+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
17+
<NoWarn>1701;1702;IDE0058;</NoWarn>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="FluentAssertions" Version="6.12.1" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
23+
<PackageReference Include="xunit" Version="2.9.2" />
24+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
<PrivateAssets>all</PrivateAssets>
27+
</PackageReference>
28+
<PackageReference Include="coverlet.collector" Version="6.0.2">
29+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
30+
<PrivateAssets>all</PrivateAssets>
31+
</PackageReference>
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<ProjectReference Include="..\..\..\src\AStar.Utilities\AStar.Utilities.csproj" />
36+
</ItemGroup>
37+
38+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using FluentAssertions;
2+
global using Xunit;

0 commit comments

Comments
 (0)