|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Text; |
5 | | -using System.Threading.Tasks; |
6 | | -using QuantumConcepts.Common.Extensions; |
| 3 | +using System.Globalization; |
7 | 4 |
|
8 | 5 | namespace QuantumConcepts.Formats.StereoLithography |
9 | 6 | { |
@@ -51,5 +48,72 @@ public static void Invert(this IEnumerable<Facet> facets) |
51 | 48 | { |
52 | 49 | facets.ForEach(f => f.Normal.Invert()); |
53 | 50 | } |
| 51 | + |
| 52 | + /// <summary>Iterates the provided enumerable, applying the provided action to each element.</summary> |
| 53 | + /// <param name="items">The items upon which to apply the action.</param> |
| 54 | + /// <param name="action">The action to apply to each item.</param> |
| 55 | + public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) |
| 56 | + { |
| 57 | + if (items != null) |
| 58 | + { |
| 59 | + foreach (var item in items) |
| 60 | + { |
| 61 | + action(item); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary>Iterates the provided enumerable, applying the provided action to each element.</summary> |
| 67 | + /// <param name="items">The items upon which to apply the action.</param> |
| 68 | + /// <param name="predicate">The action to apply to each item.</param> |
| 69 | + public static bool All<T>(this IEnumerable<T> items, Func<int, T, bool> predicate) |
| 70 | + { |
| 71 | + if (items != null) |
| 72 | + { |
| 73 | + var index = 0; |
| 74 | + |
| 75 | + foreach (var item in items) |
| 76 | + { |
| 77 | + if (!predicate(index, item)) |
| 78 | + { |
| 79 | + return false; |
| 80 | + } |
| 81 | + |
| 82 | + index++; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + return true; |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary>Checks if the provided value is null or empty.</summary> |
| 90 | + /// <param name="value">The value to check.</param> |
| 91 | + /// <returns>True if the provided value is null or empty.</returns> |
| 92 | + public static bool IsNullOrEmpty(this string value) |
| 93 | + { |
| 94 | + return string.IsNullOrEmpty(value); |
| 95 | + } |
| 96 | + |
| 97 | + /// <summary>Interpolates the provided formatted string with the provided args using the default culture.</summary> |
| 98 | + /// <param name="format">The formatted string.</param> |
| 99 | + /// <param name="args">The values to use for interpolation.</param> |
| 100 | + public static string Interpolate(this string format, params object[] args) |
| 101 | + { |
| 102 | + return format.Interpolate(CultureInfo.InvariantCulture, args); |
| 103 | + } |
| 104 | + |
| 105 | + /// <summary>Interpolates the provided formatted string with the provided args.</summary> |
| 106 | + /// <param name="format">The formatted string.</param> |
| 107 | + /// <param name="culture">The culture info to use.</param> |
| 108 | + /// <param name="args">The values to use for interpolation.</param> |
| 109 | + public static string Interpolate(this string format, CultureInfo culture, params object[] args) |
| 110 | + { |
| 111 | + if (format != null) |
| 112 | + { |
| 113 | + return string.Format(culture, format, args); |
| 114 | + } |
| 115 | + |
| 116 | + return null; |
| 117 | + } |
54 | 118 | } |
55 | 119 | } |
0 commit comments