Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Duplicate Methods #325

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion GoRogue.Snippets/HowTos/FOV.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#region Usings
// ReSharper disable NotAccessedPositionalProperty.Local
#region Usings
using GoRogue.FOV;
using GoRogue.MapGeneration;
using SadRogue.Primitives;
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
10 changes: 0 additions & 10 deletions GoRogue/Factories/ItemNotDefinedException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;

namespace GoRogue.Factories
Expand Down Expand Up @@ -28,15 +27,6 @@ public ItemNotDefinedException(string message, Exception innerException)
: base(message, innerException)
{ }

/// <summary>
/// Creates an exception based on serialization context.
/// </summary>
/// <param name="info" />
/// <param name="context" />
protected ItemNotDefinedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }

/// <summary>
/// Creates an exception with a message based on the specified factory ID.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion GoRogue/GameFramework/MapIterators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public bool MoveNext()

if (_entitiesEnumerator.MoveNext())
{
_current = _entitiesEnumerator.Current;
// Suppression is required by .NET 8
// ReSharper disable once RedundantSuppressNullableWarningExpression
_current = _entitiesEnumerator.Current!;
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions GoRogue/GoRogue.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Basic package info -->
<TargetFrameworks>netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>GoRogue</RootNamespace>
<Authors>Chris3606</Authors>
<Copyright>Copyright © 2023 Christopher Ridley (Chris3606)</Copyright>
Expand All @@ -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
237 changes: 1 addition & 236 deletions GoRogue/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using SadRogue.Primitives.GridViews;

namespace GoRogue
{
Expand All @@ -28,238 +25,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