Skip to content

Commit 6e0e952

Browse files
committed
Added exception documentation
1 parent de4feec commit 6e0e952

36 files changed

+153
-87
lines changed

src/MADE.Collections/CollectionExtensions.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public static class CollectionExtensions
1919
/// <param name="item">The item to add.</param>
2020
/// <param name="condition">The condition required to add the item.</param>
2121
/// <typeparam name="T">The type of item within the collection.</typeparam>
22+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
23+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
2224
public static void AddIf<T>(this IList<T> collection, T item, Func<bool> condition)
2325
{
2426
if (collection == null)
@@ -37,6 +39,33 @@ public static void AddIf<T>(this IList<T> collection, T item, Func<bool> conditi
3739
}
3840
}
3941

42+
/// <summary>
43+
/// Removes the specified item from the collection based on the specified condition being true.
44+
/// </summary>
45+
/// <param name="collection">The collection to remove the item from.</param>
46+
/// <param name="item">The item to remove.</param>
47+
/// <param name="condition">The condition required to remove the item.</param>
48+
/// <typeparam name="T">The type of item within the collection.</typeparam>
49+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
50+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
51+
public static void RemoveIf<T>(this IList<T> collection, T item, Func<bool> condition)
52+
{
53+
if (collection == null)
54+
{
55+
throw new ArgumentNullException(nameof(collection));
56+
}
57+
58+
if (condition == null)
59+
{
60+
throw new ArgumentNullException(nameof(condition));
61+
}
62+
63+
if (condition())
64+
{
65+
collection.Remove(item);
66+
}
67+
}
68+
4069
/// <summary>
4170
/// Updates an item within the collection.
4271
/// </summary>
@@ -146,6 +175,8 @@ public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> it
146175
/// <param name="itemsToAdd">The items to add.</param>
147176
/// <param name="condition">The condition required to add the items.</param>
148177
/// <typeparam name="T">The type of item within the collection.</typeparam>
178+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/>, <paramref name="itemsToAdd"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
179+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
149180
public static void AddRangeIf<T>(
150181
this ICollection<T> collection,
151182
IEnumerable<T> itemsToAdd,
@@ -203,6 +234,8 @@ public static void RemoveRange<T>(this ICollection<T> collection, IEnumerable<T>
203234
/// <param name="itemsToRemove">The items to remove.</param>
204235
/// <param name="condition">The condition required to remove the items.</param>
205236
/// <typeparam name="T">The type of item within the collection.</typeparam>
237+
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="collection"/>, <paramref name="itemsToRemove"/> or <paramref name="condition"/> is <see langword="null"/>.</exception>
238+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
206239
public static void RemoveRangeIf<T>(
207240
this ICollection<T> collection,
208241
IEnumerable<T> itemsToRemove,
@@ -290,6 +323,7 @@ public static IEnumerable<T> TakeFrom<T>(this List<T> list, int startingIndex, i
290323
/// <param name="action">
291324
/// The action to perform.
292325
/// </param>
326+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
293327
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
294328
{
295329
foreach (T item in collection)
@@ -308,7 +342,7 @@ public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
308342
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunkSize = 25)
309343
{
310344
return source
311-
.Select((v, i) => new {Index = i, Value = v})
345+
.Select((v, i) => new { Index = i, Value = v })
312346
.GroupBy(x => x.Index / chunkSize)
313347
.Select(x => x.Select(v => v.Value));
314348
}
@@ -333,6 +367,7 @@ public static int InsertAtPotentialIndex<T>(this IList<T> source, T value, Func<
333367
/// <param name="predicate">The action to run to determine the position of the item based on the provided <paramref name="value"/> and an item in the collection.</param>
334368
/// <typeparam name="T">The type of items in the collection.</typeparam>
335369
/// <returns>The potential index of the item.</returns>
370+
/// <exception cref="Exception">Potentially thrown by the delegate callback.</exception>
336371
public static int PotentialIndexOf<T>(this IList<T> source, T value, Func<T, T, bool> predicate)
337372
{
338373
var result = 0;

src/MADE.Collections/ObjectModel/ObservableItemCollection{T}.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ObservableItemCollection<T> : ObservableCollection<T>, IDisposable
2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="ObservableItemCollection{T}"/> class that is empty and has a default initial capacity.
2929
/// </summary>
30+
/// <exception cref="Exception">Potentially thrown by the <see cref="CollectionChanged"/> callback.</exception>
3031
public ObservableItemCollection()
3132
{
3233
base.CollectionChanged += (s, e) =>
@@ -46,6 +47,7 @@ public ObservableItemCollection()
4647
/// The collection whose elements are copied to the new list.
4748
/// </param>
4849
/// <exception cref="T:System.ArgumentNullException">The <paramref name="collection">collection</paramref> parameter cannot be null.</exception>
50+
/// <exception cref="Exception">Potentially thrown by the <see cref="CollectionChanged"/> callback.</exception>
4951
public ObservableItemCollection(IEnumerable<T> collection)
5052
: base(collection)
5153
{
@@ -65,6 +67,7 @@ public ObservableItemCollection(IEnumerable<T> collection)
6567
/// The list whose elements are copied to the new list.
6668
/// </param>
6769
/// <exception cref="T:System.ArgumentNullException">The <paramref name="list">list</paramref> parameter cannot be null.</exception>
70+
/// <exception cref="Exception">Potentially thrown by the <see cref="CollectionChanged"/> callback.</exception>
6871
public ObservableItemCollection(List<T> list)
6972
: base(list)
7073
{
@@ -93,6 +96,7 @@ public ObservableItemCollection(List<T> list)
9396
/// <param name="items">
9497
/// The objects to add to the end of the collection.
9598
/// </param>
99+
/// <exception cref="Exception">Potentially thrown by the <see cref="CollectionChanged"/> callback.</exception>
96100
public void AddRange(IEnumerable<T> items)
97101
{
98102
this.CheckDisposed();
@@ -117,6 +121,7 @@ public void AddRange(IEnumerable<T> items)
117121
/// <param name="items">
118122
/// The objects to remove from the collection.
119123
/// </param>
124+
/// <exception cref="Exception">Potentially thrown by the <see cref="CollectionChanged"/> callback.</exception>
120125
public void RemoveRange(IEnumerable<T> items)
121126
{
122127
this.CheckDisposed();

src/MADE.Data.Converters/BooleanToStringValueConverter.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public object Convert(object value, Type targetType, object parameter, string la
8080
/// <returns>The converted <see cref="bool"/> object.</returns>
8181
public object ConvertBack(object value, Type targetType, object parameter, string language)
8282
{
83-
if (!(value is string b))
83+
if (value is not string b)
8484
{
8585
return value;
8686
}

src/MADE.Data.Converters/Constants/DateTimeConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace MADE.Data.Converters.Constants
77
/// </summary>
88
public static class DateTimeConstants
99
{
10+
/// <summary>
11+
/// Defines the minimum value for a <see cref="DateTime"/> object determined by Unix.
12+
/// </summary>
13+
public static readonly DateTime UnixEpoch = new(1970, 1, 1, 0, 0, 0);
14+
1015
/// <summary>
1116
/// Defines the time at the end of a day.
1217
/// </summary>

src/MADE.Data.Converters/Extensions/DateTimeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public static DateTime EndOfYear(this DateTime dateTime)
230230
/// </returns>
231231
public static DateTime? SetTime(this DateTime? dateTime, int hours, int minutes, int seconds, int milliseconds)
232232
{
233-
return dateTime == null ? (DateTime?)null : SetTime(dateTime.Value, hours, minutes, seconds, milliseconds);
233+
return dateTime == null ? null : SetTime(dateTime.Value, hours, minutes, seconds, milliseconds);
234234
}
235235

236236
/// <summary>

src/MADE.Data.Converters/Extensions/StringExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static int ToInt(this string value)
166166
}
167167

168168
bool parsed = int.TryParse(value, out int intValue);
169-
return parsed ? (int?)intValue : null;
169+
return parsed ? intValue : null;
170170
}
171171

172172
/// <summary>
@@ -226,7 +226,7 @@ public static float ToFloat(this string value)
226226
}
227227

228228
bool parsed = float.TryParse(value, out float floatValue);
229-
return parsed ? (float?)floatValue : null;
229+
return parsed ? floatValue : null;
230230
}
231231

232232
/// <summary>
@@ -266,7 +266,7 @@ public static double ToDouble(this string value)
266266
}
267267

268268
bool parsed = double.TryParse(value, out double doubleValue);
269-
return parsed ? (double?)doubleValue : null;
269+
return parsed ? doubleValue : null;
270270
}
271271
}
272272
}

src/MADE.Data.EFCore/Converters/UtcDateTimeConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace MADE.Data.EFCore.Converters
1212
public static class UtcDateTimeConverter
1313
{
1414
internal static readonly ValueConverter<DateTime, DateTime> UtcConverter =
15-
new ValueConverter<DateTime, DateTime>(
15+
new(
1616
value => value,
1717
value => DateTime.SpecifyKind(value, DateTimeKind.Utc));
1818

src/MADE.Data.EFCore/Extensions/DbContextExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static class DbContextExtensions
2626
/// <exception cref="DbUpdateConcurrencyException">A concurrency violation is encountered while saving to the database.
2727
/// A concurrency violation occurs when an unexpected number of rows are affected during save.
2828
/// This is usually because the data in the database has been modified since it was loaded into memory.</exception>
29+
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
2930
public static async Task UpdateAsync<T>(
3031
this DbContext context,
3132
T entity,
@@ -61,7 +62,7 @@ public static void SetEntityDates(this DbContext context)
6162
.Entries()
6263
.Where(
6364
entry => entry.Entity is IEntityBase &&
64-
(entry.State == EntityState.Added || entry.State == EntityState.Modified));
65+
entry.State is EntityState.Added or EntityState.Modified);
6566

6667
DateTime now = DateTime.UtcNow;
6768

@@ -86,6 +87,8 @@ public static void SetEntityDates(this DbContext context)
8687
/// <returns>
8788
/// True if the changes saved successfully; otherwise, false.
8889
/// </returns>
90+
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
91+
/// <exception cref="Exception">Potentially thrown by the <paramref name="onError"/> delegate callback.</exception>
8992
public static async Task<bool> TrySaveChangesAsync(
9093
this DbContext context,
9194
Action<Exception> onError = null,
@@ -112,6 +115,7 @@ public static async Task<bool> TrySaveChangesAsync(
112115
/// <param name="onError">An exception for handling the exception thrown, for example, event logging.</param>
113116
/// <typeparam name="TContext">The type of data context.</typeparam>
114117
/// <returns>True if the action ran successfully; otherwise, false.</returns>
118+
/// <exception cref="Exception">Potentially thrown by the <paramref name="onError"/> delegate callback.</exception>
115119
public static async Task<bool> TryAsync<TContext>(
116120
this TContext context,
117121
Func<TContext, Task> action,

src/MADE.Data.Validation/Extensions/DateTimeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static bool IsInRange(this DateTime date, DateTime from, DateTime to)
2626
/// <returns>True if the day of week is between Monday and Friday; otherwise, false.</returns>
2727
public static bool IsWeekday(this DateTime date)
2828
{
29-
return date.DayOfWeek >= DayOfWeek.Monday && date.DayOfWeek <= DayOfWeek.Friday;
29+
return date.DayOfWeek is >= DayOfWeek.Monday and <= DayOfWeek.Friday;
3030
}
3131

3232
/// <summary>
@@ -36,7 +36,7 @@ public static bool IsWeekday(this DateTime date)
3636
/// <returns>True if the day of week is Saturday or Sunday; otherwise, false.</returns>
3737
public static bool IsWeekend(this DateTime date)
3838
{
39-
return date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday;
39+
return date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
4040
}
4141
}
4242
}

src/MADE.Data.Validation/Extensions/MathExtensions.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace MADE.Data.Validation.Extensions
55
{
6+
using System;
67
using MADE.Data.Validation.Exceptions;
78

89
/// <summary>
@@ -26,7 +27,7 @@ public static class MathExtensions
2627
/// </returns>
2728
public static bool IsZero(this double value)
2829
{
29-
return System.Math.Abs(value) < Epsilon;
30+
return Math.Abs(value) < Epsilon;
3031
}
3132

3233
/// <summary>
@@ -40,7 +41,7 @@ public static bool IsZero(this double value)
4041
/// </returns>
4142
public static bool IsZero(this float value)
4243
{
43-
return System.Math.Abs(value) < Epsilon;
44+
return Math.Abs(value) < Epsilon;
4445
}
4546

4647
/// <summary>
@@ -55,14 +56,15 @@ public static bool IsZero(this float value)
5556
/// <returns>
5657
/// True if the values are close; otherwise, false.
5758
/// </returns>
59+
/// <exception cref="OverflowException">Thrown if the value equals <see cref="int.MinValue"></see>.</exception>
5860
public static bool IsCloseTo(this int value, int compare)
5961
{
60-
if (System.Math.Abs(value - compare) < 1)
62+
if (Math.Abs(value - compare) < 1)
6163
{
6264
return true;
6365
}
6466

65-
double a = (System.Math.Abs(value) + System.Math.Abs(compare) + 10.0) * Epsilon;
67+
double a = (Math.Abs(value) + Math.Abs(compare) + 10.0) * Epsilon;
6668
int b = value - compare;
6769
return -a < b && a > b;
6870
}
@@ -81,12 +83,12 @@ public static bool IsCloseTo(this int value, int compare)
8183
/// </returns>
8284
public static bool IsCloseTo(this double value, double compare)
8385
{
84-
if (System.Math.Abs(value - compare) < Epsilon)
86+
if (Math.Abs(value - compare) < Epsilon)
8587
{
8688
return true;
8789
}
8890

89-
double a = (System.Math.Abs(value) + System.Math.Abs(compare) + 10.0) * Epsilon;
91+
double a = (Math.Abs(value) + Math.Abs(compare) + 10.0) * Epsilon;
9092
double b = value - compare;
9193
return -a < b && a > b;
9294
}
@@ -110,12 +112,12 @@ public static bool IsCloseTo(this double? value, double? compare)
110112
return false;
111113
}
112114

113-
if (System.Math.Abs(value.Value - compare.Value) < Epsilon)
115+
if (Math.Abs(value.Value - compare.Value) < Epsilon)
114116
{
115117
return true;
116118
}
117119

118-
double a = (System.Math.Abs(value.Value) + System.Math.Abs(compare.Value) + 10.0) * Epsilon;
120+
double a = (Math.Abs(value.Value) + Math.Abs(compare.Value) + 10.0) * Epsilon;
119121
double? b = value - compare;
120122
return -a < b && a > b;
121123
}
@@ -134,12 +136,12 @@ public static bool IsCloseTo(this double? value, double? compare)
134136
/// </returns>
135137
public static bool IsCloseTo(this float value, float compare)
136138
{
137-
if (System.Math.Abs(value - compare) < Epsilon)
139+
if (Math.Abs(value - compare) < Epsilon)
138140
{
139141
return true;
140142
}
141143

142-
double a = (System.Math.Abs(value) + System.Math.Abs(compare) + 10.0) * Epsilon;
144+
double a = (Math.Abs(value) + Math.Abs(compare) + 10.0) * Epsilon;
143145
float b = value - compare;
144146
return -a < b && a > b;
145147
}
@@ -163,12 +165,12 @@ public static bool IsCloseTo(this float? value, float? compare)
163165
return false;
164166
}
165167

166-
if (System.Math.Abs(value.Value - compare.Value) < Epsilon)
168+
if (Math.Abs(value.Value - compare.Value) < Epsilon)
167169
{
168170
return true;
169171
}
170172

171-
double a = (System.Math.Abs(value.Value) + System.Math.Abs(compare.Value) + 10.0) * Epsilon;
173+
double a = (Math.Abs(value.Value) + Math.Abs(compare.Value) + 10.0) * Epsilon;
172174
float? b = value - compare;
173175
return -a < b && a > b;
174176
}

0 commit comments

Comments
 (0)