Repository navigation
Expand file tree
/
Copy pathTargetValues.cs
More file actions
108 lines (93 loc) · 3.76 KB
/
Copy pathTargetValues.cs
File metadata and controls
108 lines (93 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//*********************************************************************************************************************
// File Name: TargetValues.cs
// Description: Implementation of the target value options
//
// Copyright (c) 2023 Mike Pullen
// Licensed under the MIT License. See LICENSE in the repository root.
//
// Revision History:
//====================================================================================================================
// 2023/12/02 - Mike Pullen - Original implementation.
//*********************************************************************************************************************
using System;
namespace RandomNumberGenerator
{
/// <summary>
/// Representation of the target value options
/// </summary>
public static class TargetValues
{
/// <summary>
/// Gets the string for the specified value
/// </summary>
/// <param name="iTargetValue">IN - The value for which to get the string</param>
/// <returns>String for value if found; otherwise, null</returns>
public static string ToString(int iTargetValue)
{
// Default the return to null object
string sResult = null;
// Attempt to find the specified value
int iIndex = Array.FindIndex(m_sTargetValues, iCurrentValue => (iCurrentValue == iTargetValue));
if (0 <= iIndex)
{
// Get the result from the string array
sResult = TargetStrings[iIndex];
}
return sResult;
}
/// <summary>
/// Gets the value for the specified string
/// </summary>
/// <param name="sTargetValue">IN - The string for which to get the value</param>
/// <returns>Value for string if found; otherwise, NO_VALUE_SET</returns>
public static int ToInt(string sTargetValue)
{
int iResult = NO_VALUE_SET;
// Attempt to find the specified string
int iIndex = Array.FindIndex(TargetStrings, sCurrentValue => (sCurrentValue == sTargetValue));
if (0 <= iIndex)
{
// Get the result from the value array
iResult = m_sTargetValues[iIndex];
}
return iResult;
}
/// <summary>
/// Gets the string at the specified index
/// </summary>
/// <param name="iIndex">IN - Index for the string to get</param>
/// <returns>String if index is valid; otherwise, null</returns>
public static string GetStringAt(uint iIndex)
{
string sResult = null;
if (TargetStrings.Length > iIndex)
{
sResult = TargetStrings[iIndex];
}
return sResult;
}
/// <summary>
/// Gets the value at the specified index
/// </summary>
/// <param name="iIndex">IN - Index for the value to get</param>
/// <returns>Value if index is valid; otherwise, NO_VALUE_SET</returns>
public static int GetValueAt(uint iIndex)
{
int iResult = NO_VALUE_SET;
if (m_sTargetValues.Length > iIndex)
{
iResult = m_sTargetValues[iIndex];
}
return iResult;
}
/// <summary>
/// The list of string representations of the possible values set
/// </summary>
public static string[] TargetStrings { get; } = { "None", "0", "1" }; // string representation of possible targets
/// <summary>
/// Constant used when no value has been set
/// </summary>
public const int NO_VALUE_SET = -2;
private static readonly int[] m_sTargetValues = { -1, 0, 1 }; // Possible target values
}
}