Skip to content

Commit

Permalink
Upgraded packages and removed ToString extension methods duplicated b…
Browse files Browse the repository at this point in the history
…y the primitives library. Bumped csproj for 3.0.0-beta09 release.
  • Loading branch information
Chris3606 committed Dec 6, 2023
1 parent 559c07b commit 7f16000
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 239 deletions.
2 changes: 1 addition & 1 deletion GoRogue.Debugger/GoRogue.Debugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<ItemGroup>
<!-- ReSharper disable once VulnerablePackage -->
<PackageReference Include="dotnet-curses" Version="1.0.2" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1">
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion GoRogue.PerformanceTests/GoRogue.PerformanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions GoRogue.UnitTests/GoRogue.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1">
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
1 change: 1 addition & 0 deletions GoRogue/DisjointSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using SadRogue.Primitives;

namespace GoRogue
{
Expand Down
1 change: 1 addition & 0 deletions GoRogue/Effects/EffectTriggerBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using SadRogue.Primitives;

namespace GoRogue.Effects
{
Expand Down
6 changes: 3 additions & 3 deletions GoRogue/GoRogue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Configure versioning information, making sure to append "debug" to Debug version to allow publishing
to NuGet seperately from Release version.
-->
<Version>3.0.0-beta08</Version>
<Version>3.0.0-beta09</Version>
<Version Condition="'$(Configuration)'=='Debug'">$(Version)-debug</Version>

<!-- More nuget package settings-->
Expand Down Expand Up @@ -79,10 +79,10 @@

<!-- Dependencies -->
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1">
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
232 changes: 0 additions & 232 deletions GoRogue/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,238 +28,6 @@ public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(
where TKey : notnull
=> new ReadOnlyDictionary<TKey, TValue>(dictionary);

/// <summary>
/// Extension method for <see cref="IEnumerable{T}" /> that allows retrieving a string
/// representing the contents.
/// </summary>
/// <remarks>
/// Built-in C# data structures like <see cref="List{T}" /> implement <see cref="IEnumerable{T}" />,
/// and as such this method can be used to stringify the contents of C# built-in data structures.
/// When no customization parameters are specified, it defaults to a representation looking something
/// like [elem1, elem2, elem3].
/// </remarks>
/// <typeparam name="T" />
/// <param name="enumerable" />
/// <param name="begin">Character(s) that should precede the string representation of the IEnumerable's elements.</param>
/// <param name="elementStringifier">
/// Function to use to get the string representation of each element. Specifying null uses the ToString
/// function of type T.
/// </param>
/// <param name="separator">Characters to separate the IEnumerable's elements by.</param>
/// <param name="end">Character(s) that should follow the string representation of the IEnumerable's elements.</param>
/// <returns>A string representation of the IEnumerable.</returns>
public static string ExtendToString<T>(this IEnumerable<T> enumerable, string begin = "[",
Func<T, string>? elementStringifier = null, string separator = ", ",
string end = "]")
{
elementStringifier ??= obj => obj?.ToString() ?? "null";

var result = new StringBuilder(begin);
var first = true;
foreach (var item in enumerable)
{
if (first)
first = false;
else
result.Append(separator);

result.Append(elementStringifier(item));
}

result.Append(end);

return result.ToString();
}

/// <summary>
/// Extension method for <see cref="ISet{T}" /> that allows retrieving a string representing the
/// contents.
/// </summary>
/// <remarks>
/// Built-in C# data structures like <see cref="HashSet{T}" /> implement <see cref="ISet{T}" />,
/// and as such this method can be used to stringify the contents of C# built-in set structures.
/// When no customization parameters are specified, it defaults to a representation looking something
/// like set(elem1, elem2, elem3).
/// </remarks>
/// <typeparam name="T" />
/// <param name="set" />
/// <param name="begin">Character(s) that should precede the string representation of the set's elements.</param>
/// <param name="elementStringifier">
/// Function to use to get the string representation of each element. Specifying null uses the ToString
/// function of type T.
/// </param>
/// <param name="separator">Characters to separate the set's items by.</param>
/// <param name="end">Character(s) that should follow the string representation of the set's elements.</param>
/// <returns>A string representation of the ISet.</returns>
public static string ExtendToString<T>(this ISet<T> set, string begin = "set(",
Func<T, string>? elementStringifier = null, string separator = ", ",
string end = ")")
=> ExtendToString((IEnumerable<T>)set, begin, elementStringifier, separator, end);

/// <summary>
/// Extension method for dictionaries that allows retrieving a string representing the dictionary's contents.
/// </summary>
/// <remarks>
/// Built-in C# data structures like <see cref="Dictionary{T, V}" /> implement <see cref="IDictionary{T, V}" />,
/// and as such this method can be used to stringify the contents of C# built-in dictionary structures.
/// When no customization parameters are specified, it defaults to a representation looking something
/// like {key1 : value, key2 : value}.
/// </remarks>
/// <typeparam name="TKey" />
/// <typeparam name="TValue" />
/// <param name="dictionary" />
/// <param name="begin">Character(s) that should precede the string representation of the dictionary's elements.</param>
/// <param name="keyStringifier">
/// Function to use to get the string representation of each key. Specifying null uses the ToString
/// function of type K.
/// </param>
/// <param name="valueStringifier">
/// Function to use to get the string representation of each value. Specifying null uses the ToString
/// function of type V.
/// </param>
/// <param name="kvSeparator">Characters used to separate each value from its key.</param>
/// <param name="pairSeparator">Characters used to separate each key-value pair from the next.</param>
/// <param name="end">Character(s) that should follow the string representation of the dictionary's elements.</param>
/// <returns>A string representation of the IDictionary.</returns>
public static string ExtendToString<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, string begin = "{",
Func<TKey, string>? keyStringifier = null,
Func<TValue, string>? valueStringifier = null,
string kvSeparator = " : ", string pairSeparator = ", ",
string end = "}")
where TKey : notnull
{
keyStringifier ??= obj => obj.ToString() ?? "null";

valueStringifier ??= obj => obj?.ToString() ?? "null";

var result = new StringBuilder(begin);
var first = true;
foreach (var (key, value) in dictionary)
{
if (first)
first = false;
else
result.Append(pairSeparator);

result.Append(keyStringifier(key) + kvSeparator + valueStringifier(value));
}

result.Append(end);

return result.ToString();
}

/// <summary>
/// Extension method for 2D arrays that allows retrieving a string representing the contents.
/// </summary>
/// <typeparam name="T" />
/// <param name="array" />
/// <param name="begin">Character(s) that should precede the string representation of the 2D array.</param>
/// <param name="beginRow">Character(s) that should precede the string representation of each row.</param>
/// <param name="elementStringifier">
/// Function to use to get the string representation of each value. Specifying null uses the ToString
/// function of type T.
/// </param>
/// <param name="rowSeparator">Character(s) used to separate each row from the next.</param>
/// <param name="elementSeparator">Character(s) used to separate each element from the next.</param>
/// <param name="endRow">Character(s) that should follow the string representation of each row.</param>
/// <param name="end">Character(s) that should follow the string representation of the 2D array.</param>
/// <returns>A string representation of the 2D array.</returns>
public static string ExtendToString<T>(this T[,] array, string begin = "[\n", string beginRow = "\t[",
Func<T, string>? elementStringifier = null,
string rowSeparator = ",\n", string elementSeparator = ", ",
string endRow = "]", string end = "\n]")
{
elementStringifier ??= obj => obj?.ToString() ?? "null";

var result = new StringBuilder(begin);
for (var x = 0; x < array.GetLength(0); x++)
{
result.Append(beginRow);
for (var y = 0; y < array.GetLength(1); y++)
{
result.Append(elementStringifier(array[x, y]));
if (y != array.GetLength(1) - 1) result.Append(elementSeparator);
}

result.Append(endRow);
if (x != array.GetLength(0) - 1) result.Append(rowSeparator);
}

result.Append(end);
return result.ToString();
}

/// <summary>
/// Extension method for 2D arrays that allows retrieving a string representing the contents,
/// formatted as if the 2D array represents a coordinate plane/grid.
/// </summary>
/// <remarks>
/// This differs from
/// <see cref="ExtendToString{T}(T[,], string, string, Func{T, string}, string, string, string, string)" />
/// in that this method prints the array
/// such that array[x+1, y] is printed to the RIGHT of array[x, y], rather than BELOW it.
/// Effectively it assumes the indexes being used are grid/coordinate plane coordinates.
/// </remarks>
/// <typeparam name="T" />
/// <param name="array" />
/// <param name="begin">Character(s) that should precede the string representation of the 2D array.</param>
/// <param name="beginRow">Character(s) that should precede the string representation of each row.</param>
/// <param name="elementStringifier">
/// Function to use to get the string representation of each value. Specifying null uses the ToString
/// function of type T.
/// </param>
/// <param name="rowSeparator">Character(s) used to separate each row from the next.</param>
/// <param name="elementSeparator">Character(s) used to separate each element from the next.</param>
/// <param name="endRow">Character(s) that should follow the string representation of each row.</param>
/// <param name="end">Character(s) that should follow the string representation of the 2D array.</param>
/// <returns>
/// A string representation of the 2D array, formatted as if the array represents a 2D coordinate plane/grid map.
/// </returns>
public static string ExtendToStringGrid<T>(this T[,] array, string begin = "", string beginRow = "",
Func<T, string>? elementStringifier = null,
string rowSeparator = "\n", string elementSeparator = " ",
string endRow = "", string end = "")
=> new ArrayView2D<T>(array).ExtendToString(begin, beginRow, elementStringifier, rowSeparator,
elementSeparator, endRow, end);

/// <summary>
/// Extension method for 2D arrays that allows retrieving a string representing the contents,
/// formatted as if the 2D array represents a coordinate plane/grid.
/// </summary>
/// <remarks>
/// This differs from
/// <see cref="ExtendToString{T}(T[,], string, string, Func{T, string}, string, string, string, string)" />
/// in that this method prints the array such that array[x+1, y] is printed to the RIGHT of array[x, y], rather than BELOW
/// it.
/// Effectively it assumes the indexes being used are grid/coordinate plane coordinates.
/// </remarks>
/// <typeparam name="T" />
/// <param name="array" />
/// <param name="fieldSize">
/// The amount of space each element should take up in characters. A positive number aligns
/// the text to the right of the space, while a negative number aligns the text to the left.
/// </param>
/// <param name="begin">Character(s) that should precede the string representation of the 2D array.</param>
/// <param name="beginRow">Character(s) that should precede the string representation of each row.</param>
/// <param name="elementStringifier">
/// Function to use to get the string representation of each value. Specifying null uses the ToString
/// function of type T.
/// </param>
/// <param name="rowSeparator">Character(s) used to separate each row from the next.</param>
/// <param name="elementSeparator">Character(s) used to separate each element from the next.</param>
/// <param name="endRow">Character(s) that should follow the string representation of each row.</param>
/// <param name="end">Character(s) that should follow the string representation of the 2D array.</param>
/// <returns>
/// A string representation of the 2D array, formatted as if the array represents a 2D coordinate plane/grid map.
/// </returns>
public static string ExtendToStringGrid<T>(this T[,] array, int fieldSize, string begin = "",
string beginRow = "", Func<T, string>? elementStringifier = null,
string rowSeparator = "\n", string elementSeparator = " ",
string endRow = "", string end = "")
=> new ArrayView2D<T>(array).ExtendToString(fieldSize, begin, beginRow, elementStringifier, rowSeparator,
elementSeparator, endRow, end);

/// <summary>
/// "Multiplies", aka repeats, a string the given number of times.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- None

## [3.0.0-beta09] - 2023-12-05
### Removed
- `ExtendToString` and `ExtendToStringGrid` extension methods from `Utility` class are removed (they now exist in the primitives library instead)

## [3.0.0-beta08] - 2023-07-12

### Added
Expand Down

0 comments on commit 7f16000

Please sign in to comment.