-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
62 lines (54 loc) · 2.13 KB
/
Program.cs
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
using System;
using System.Linq;
using System.Reflection;
namespace CodingRange
{
internal class Program
{
private static void Main()
{
Workspace workspace = new();
// all this reflection is done so we can hide visiblity modifiers from new students for the time being
var method = typeof(Workspace).GetMethod("Method", (BindingFlags)(-1));
var problemNumber = (int)typeof(Workspace)
.GetField("problemNumber", (BindingFlags)(-1))
.GetValue(workspace);
var displayProblem = (bool)typeof(Workspace)
.GetField("displayProblem", (BindingFlags)(-1))
.GetValue(workspace);
var evaluateAnswer = (bool)typeof(Workspace)
.GetField("evaluateAnswer", (BindingFlags)(-1))
.GetValue(workspace);
if (problemNumber == ProblemList.List.Count)
{
Console.WriteLine("It seems you've completed all available problems! Ask Ben if you want more.");
return;
}
else if (problemNumber < 0
|| problemNumber > ProblemList.List.Count)
{
Console.WriteLine($"Invalid problem number added! Problems range from (0-{ProblemList.List.Count - 1})");
return;
}
if (displayProblem)
{
ProblemList.List[problemNumber].Display();
}
if (evaluateAnswer)
{
ProblemList.List[problemNumber].Evaluate(method);
}
else if (ProblemList.List[problemNumber].IsInteractive)
{
Console.WriteLine("Running in INTERACTIVE mode.");
var types = ProblemList.List[problemNumber].GetParameterTypes();
var parameters = (from t in types select Activator.CreateInstance(t)).ToArray();
method.Invoke(workspace, parameters);
}
if (!displayProblem && !evaluateAnswer)
{
Console.WriteLine("Nothing to display. Enable either displayProblem or evaluateAnswer.");
}
}
}
}