Skip to content

Commit f6ad663

Browse files
authored
Clean up JoinRpg.Helpers yet again (#1373)
Shaving of some not required thing in helpers
1 parent f74cbe4 commit f6ad663

File tree

7 files changed

+11
-116
lines changed

7 files changed

+11
-116
lines changed

src/JoinRpg.Helpers.Web/IdListUrlExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static string MagicJoin([NotNull] this IEnumerable<int> list)
8989

9090
if (needSep)
9191
{
92-
_ = builder.Append(",");
92+
_ = builder.Append(',');
9393
}
9494
_ = builder.Append(next - 25);
9595
needSep = true;

src/JoinRpg.Helpers/EntityFrameworkExtensions.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,5 @@ public static void AddLinkList<T>(this ICollection<T> target, IEnumerable<T> new
3030
}
3131

3232
public static void CleanLinksList<T>(this ICollection<T> target) => target.AssignLinksList(new List<T>());
33-
34-
public static void RemoveFromLinkList<T>(this ICollection<T> target,
35-
IEnumerable<T> linksToRemove)
36-
{
37-
foreach (var value in linksToRemove.Intersect(target).ToList())
38-
{
39-
_ = target.Remove(value);
40-
}
41-
}
4233
}
4334
}

src/JoinRpg.Helpers/LambdaHelpers.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/JoinRpg.Helpers/StaticCollectionHelpers.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Collections.Specialized;
43
using System.Linq;
54
using JetBrains.Annotations;
65

@@ -10,8 +9,6 @@ public static class StaticCollectionHelpers
109
{
1110
private static readonly Random Rng = new();
1211

13-
public static Dictionary<string, string> ToDictionary(this NameValueCollection collection) => collection.AllKeys.ToDictionary(key => key, key => collection[key]);
14-
1512
[NotNull, ItemNotNull]
1613
public static ISet<T> FlatTree<T>(this T obj,
1714
Func<T, IEnumerable<T>> parentSelectorFunc,
@@ -50,9 +47,11 @@ public static IEnumerable<T> UnionIf<T>(this IEnumerable<T> source,
5047
bool add)
5148
=> source.Union(add ? enumerable : Enumerable.Empty<T>());
5249

50+
[Obsolete("Use Append()")]
5351
public static IEnumerable<T> Union<T>(this IEnumerable<T> source, T t) => source.Union(new[] { t });
5452

55-
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class
53+
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
54+
where T : class
5655
{
5756
foreach (var i in source)
5857
{
@@ -63,18 +62,19 @@ public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where
6362
}
6463
}
6564

66-
public static IEnumerable<int> WhereNotNull(this IEnumerable<int?> source)
65+
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
66+
where T : struct
6767
{
6868
foreach (var i in source)
6969
{
70-
if (i is int v)
70+
if (i is T v)
7171
{
7272
yield return v;
7373
}
7474
}
7575
}
7676

77-
public static IEnumerable<T> OrEmptyList<T>(this IEnumerable<T> collection) => collection ?? Enumerable.Empty<T>();
77+
public static IEnumerable<T> OrEmptyList<T>(this IEnumerable<T>? collection) => collection ?? Enumerable.Empty<T>();
7878

7979
public static IEnumerable<T> Shuffle<T>([NotNull]
8080
this IEnumerable<T> source) => Shuffle(source, Rng);
@@ -120,13 +120,5 @@ public static IEnumerable<T> UnionUntilTotalCount<T>([NotNull]
120120
.Except(alreadyTaken)
121121
.Take(Math.Max(0, totalLimit - alreadyTaken.Count)));
122122
}
123-
124-
public static IEnumerable<int> GetRandomSource(this Random random)
125-
{
126-
while (true)
127-
{
128-
yield return random.Next();
129-
}
130-
}
131123
}
132124
}

src/JoinRpg.Helpers/StaticEnumHelpers.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ public static class StaticEnumHelpers
1616
.GetField(enumValue.ToString())?
1717
.GetCustomAttribute<TAttribute>();
1818
}
19-
20-
[PublicAPI]
21-
public static IEnumerable<T> GetValues<T>() => Enum.GetValues(typeof(T)).Cast<T>();
2219
}
2320
}

src/JoinRpg.Helpers/StaticStringHelpers.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static IEnumerable<int> UnprefixNumbers([NotNull, ItemNotNull]
7373
string prefix)
7474
{
7575
return number.StartsWith(prefix)
76-
? (int?)int.Parse(number.Substring(prefix.Length))
76+
? int.Parse(number.Substring(prefix.Length))
7777
: null;
7878
}
7979

@@ -190,46 +190,17 @@ public static string ToHexHash(this string str, HashAlgorithm hashAlgorithm)
190190
return hashAlgorithm.ComputeHash(bytes).ToHexString();
191191
}
192192

193-
public static string AfterSeparator(this string str, char separator) => str.SkipWhile(c => c != separator).Skip(1).AsString();
194-
195-
public static string BeforeSeparator(this string str, char separator) => str.TakeWhile(c => c != separator).AsString();
196-
197193
[NotNull]
198-
public static int[] ToIntList([CanBeNull]
199-
this string? claimIds)
194+
public static int[] ToIntList(this string? claimIds)
200195
{
201-
if (string.IsNullOrWhiteSpace(claimIds))
196+
if (claimIds is null)
202197
{
203198
return Array.Empty<int>();
204199
}
205200

206201
return claimIds.Split(',').WhereNotNullOrWhiteSpace().Select(int.Parse).ToArray();
207202
}
208203

209-
[NotNull]
210-
public static IEnumerable<byte> AsUtf8BytesWithLimit([NotNull]
211-
this string formattableString,
212-
int bytesLimit)
213-
{
214-
if (formattableString == null)
215-
{
216-
throw new ArgumentNullException(nameof(formattableString));
217-
}
218-
219-
var ch = formattableString.ToCharArray();
220-
var epilogue = Encoding.UTF8.GetBytes("…");
221-
for (var i = ch.Length; i > 0; i--)
222-
{
223-
var chunkBytes = Encoding.UTF8.GetByteCount(ch, 0, i);
224-
if (chunkBytes + epilogue.Length <= bytesLimit)
225-
{
226-
return Encoding.UTF8.GetBytes(ch, 0, i).Concat(epilogue);
227-
}
228-
}
229-
230-
return Enumerable.Empty<byte>();
231-
}
232-
233204
[NotNull]
234205
public static string WithDefaultStringValue([CanBeNull]
235206
this string value,

src/JoinRpg.Helpers/UnixTime.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)