| | 1 | | namespace Songhay.Extensions; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extensions of <see cref="ObservableCollection<T>" />. |
| | 5 | | /// </summary> |
| | 6 | | public static class ObservableCollectionExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Sets the collection with digits for <c>mantissaDigits = 2</c>. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="collectionOfByte">The collection of byte.</param> |
| | 12 | | /// <param name="digits">The digits.</param> |
| | 13 | | public static void SetCollectionWithDigits(this ObservableCollection<byte?> collectionOfByte, double digits) => |
| 2 | 14 | | collectionOfByte.SetCollectionWithDigits(digits, mantissaDigits: 2); |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Sets the collection with digits. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="collectionOfByte">The collection of byte.</param> |
| | 20 | | /// <param name="digits">The digits.</param> |
| | 21 | | /// <param name="mantissaDigits">The mantissa digits.</param> |
| | 22 | | public static void SetCollectionWithDigits(this ObservableCollection<byte?>? collectionOfByte, double digits, |
| | 23 | | int mantissaDigits) |
| 2 | 24 | | { |
| 2 | 25 | | if (collectionOfByte == null) return; |
| | 26 | |
|
| 2 | 27 | | var x = Convert.ToInt32(100 * MathUtility.GetMantissa(digits, mantissaDigits)); |
| 2 | 28 | | if (collectionOfByte.Count < mantissaDigits) return; |
| | 29 | |
|
| 2 | 30 | | collectionOfByte[0] = (x >= 1e0) ? MathUtility.GetDigitInNumber(x, 1) : 0; |
| 2 | 31 | | collectionOfByte[1] = (x >= 1e1) ? MathUtility.GetDigitInNumber(x, 2) : 0; |
| | 32 | |
|
| 2 | 33 | | x = Convert.ToInt32(MathUtility.TruncateNumber(digits)); |
| | 34 | |
|
| 28 | 35 | | for (int i = 2; i < collectionOfByte.Count; i++) |
| 12 | 36 | | { |
| 12 | 37 | | var place = i - 1; |
| 12 | 38 | | var y = i - 2; |
| | 39 | |
|
| 12 | 40 | | collectionOfByte[i] = (x < Math.Pow(10, y)) ? 0 : MathUtility.GetDigitInNumber(x, place); |
| 12 | 41 | | } |
| 2 | 42 | | } |
| | 43 | | } |