Skip to content

Commit 8e04cb6

Browse files
committed
Feat: Import from InfiniLore
1 parent 714ff71 commit 8e04cb6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/CodeOfChaos.Extensions.EntityFrameworkCore/LinqExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ public static IQueryable<TSource> ConditionalOrderByNotNull<TSource, TKey>(this
4444
orderBy is not null
4545
? source.OrderBy(orderBy)
4646
: source;
47+
48+
49+
public static IQueryable<TSource> ConditionalQueryable<TSource>(this IQueryable<TSource> source, bool condition, Func<IQueryable<TSource>, IQueryable<TSource>> queryableFunc) =>
50+
condition
51+
? queryableFunc(source)
52+
: source;
4753
}

src/CodeOfChaos.Extensions/StringExtensions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Diagnostics;
45
using System.Diagnostics.CodeAnalysis;
56

67
// ReSharper disable once CheckNamespace
@@ -19,5 +20,14 @@ public static class StringExtensions {
1920

2021
public static string Truncate(this string input, int maxLength) => input.Length <= maxLength ? input : input[..maxLength];
2122

22-
public static Guid ToGuid(this string input) => Guid.Parse(input);
23+
public static Guid ToGuid(this string input) {
24+
#if DEBUG
25+
if (Guid.TryParse(input, out Guid output)) return output;
26+
Debug.Fail("Failed to parse Guid");
27+
return Guid.Empty;
28+
#else
29+
// Because "testing" of the input is done during debug, we can just "blindly" parse during release.
30+
return Guid.Parse(input);
31+
#endif
32+
}
2333
}

0 commit comments

Comments
 (0)