-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (46 loc) · 1.49 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (46 loc) · 1.49 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
using System;
using System.Reflection;
public class Program
{
public static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage: dotnet run <method> <number_of_polygons>");
return;
}
string method = args[0];
int numberOfPolygons;
if (!int.TryParse(args[1], out numberOfPolygons))
{
Console.WriteLine("The number of polygons must be a valid integer.");
return;
}
ShapeGenerator generator = new ShapeGenerator();
try
{
var methodInfo = typeof(ShapeGenerator).GetMethod(method, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
if (methodInfo == null)
{
Console.WriteLine("Method not recognized. Use 'GeneratePolygons' or 'GeneratePolygon'.");
return;
}
object result;
if (methodInfo.IsStatic)
{
result = methodInfo.Invoke(null, new object[] { numberOfPolygons });
}
else
{
result = methodInfo.Invoke(generator, new object[] { });
}
Console.WriteLine(result);
Clipboard.SetText(result.ToString());
Console.WriteLine("Copied!");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}