diff options
| author | mo <mo.khan@gmail.com> | 2018-11-04 15:22:16 -0700 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2018-11-04 15:22:16 -0700 |
| commit | 5ee1f55497a4e30322a56f133f897ecde1612967 (patch) | |
| tree | bf544e0879234c3623869627d8786776cb19b8e9 /src/Notepad/Infrastructure/Extensions | |
Diffstat (limited to 'src/Notepad/Infrastructure/Extensions')
5 files changed, 75 insertions, 0 deletions
diff --git a/src/Notepad/Infrastructure/Extensions/ConversionExtensions.cs b/src/Notepad/Infrastructure/Extensions/ConversionExtensions.cs new file mode 100644 index 0000000..0266e58 --- /dev/null +++ b/src/Notepad/Infrastructure/Extensions/ConversionExtensions.cs @@ -0,0 +1,7 @@ +namespace Notepad.Infrastructure.Extensions {
+ public static class ConversionExtensions {
+ public static T DowncastTo<T>(this object objectToCast) {
+ return (T) objectToCast;
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Infrastructure/Extensions/EnumerableExtensions.cs b/src/Notepad/Infrastructure/Extensions/EnumerableExtensions.cs new file mode 100644 index 0000000..d57c0e1 --- /dev/null +++ b/src/Notepad/Infrastructure/Extensions/EnumerableExtensions.cs @@ -0,0 +1,24 @@ +using System;
+using System.Collections.Generic;
+
+namespace Notepad.Infrastructure.Extensions {
+ public static class EnumerableExtensions {
+ public static void Walk<T>(this IEnumerable<T> itemsToWalk) {
+ foreach (var item in itemsToWalk) {}
+ }
+
+ public static IEnumerable<T> ThatSatisfy<T>(this IEnumerable<T> itemsToPeekInto, Predicate<T> criteriaToSatisfy) {
+ foreach (var item in itemsToPeekInto) {
+ if (item.Satisfies(criteriaToSatisfy)) {
+ yield return item;
+ }
+ }
+ }
+
+ public static IEnumerable<T> SortedUsing<T>(this IEnumerable<T> itemsToSort, IComparer<T> sortingAlgorithm) {
+ var sortedItems = new List<T>(itemsToSort);
+ sortedItems.Sort(sortingAlgorithm);
+ return sortedItems;
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Infrastructure/Extensions/LoggingExtensions.cs b/src/Notepad/Infrastructure/Extensions/LoggingExtensions.cs new file mode 100644 index 0000000..a05e2fc --- /dev/null +++ b/src/Notepad/Infrastructure/Extensions/LoggingExtensions.cs @@ -0,0 +1,17 @@ +using System;
+using Notepad.Infrastructure.Logging;
+
+namespace Notepad.Infrastructure.Extensions {
+ public static class LoggingExtensions {
+ public static void LogError(this Exception errorToLog) {
+ Log.For(errorToLog).Error(errorToLog);
+ }
+
+ public static void LogInformational<T>(
+ this T typeToCreateLoggerFor,
+ string formattedMessage,
+ params object[] arguments) {
+ Log.For(typeToCreateLoggerFor).Informational(formattedMessage, arguments);
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Infrastructure/Extensions/SpecificationExtensions.cs b/src/Notepad/Infrastructure/Extensions/SpecificationExtensions.cs new file mode 100644 index 0000000..c7ed7dc --- /dev/null +++ b/src/Notepad/Infrastructure/Extensions/SpecificationExtensions.cs @@ -0,0 +1,14 @@ +using System;
+using Notepad.Infrastructure.Core;
+
+namespace Notepad.Infrastructure.Extensions {
+ public static class SpecificationExtensions {
+ public static bool Satisfies<T>(this T itemToValidate, Predicate<T> criteriaToSatisfy) {
+ return criteriaToSatisfy(itemToValidate);
+ }
+
+ public static bool Satisfies<T>(this T itemToValidate, ISpecification<T> criteriaToSatisfy) {
+ return itemToValidate.Satisfies(criteriaToSatisfy.IsSatisfiedBy);
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Infrastructure/Extensions/StringExtensions.cs b/src/Notepad/Infrastructure/Extensions/StringExtensions.cs new file mode 100644 index 0000000..9c19f97 --- /dev/null +++ b/src/Notepad/Infrastructure/Extensions/StringExtensions.cs @@ -0,0 +1,13 @@ +using Notepad.Domain.FileSystem;
+
+namespace Notepad.Infrastructure.Extensions {
+ public static class StringExtensions {
+ public static string FormatWith(this string formattedString, params object[] arguments) {
+ return string.Format(formattedString, arguments);
+ }
+
+ public static IFilePath AsAnAbsoluteFilePath(this string rawFilePath) {
+ return new AbsoluteFilePath(rawFilePath);
+ }
+ }
+}
\ No newline at end of file |
