Skip to content

Commit f9d3c3b

Browse files
committed
Add schema reflection and sample models to Program.cs
Introduced usage of Reflector to generate and print argument and return schemas for a sample method. Added sample classes, structs, and enums (Data, Result, EnumFlag, GeoPoint, PlayerProfile, GameState<T>) to demonstrate schema generation, including recursive and generic types.
1 parent af82c75 commit f9d3c3b

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

ConsoleApp/Program.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,80 @@
99
using com.IvanMurzak.ReflectorNet.Model;
1010
using com.IvanMurzak.ReflectorNet.Tests;
1111
using com.IvanMurzak.ReflectorNet.Tests.Model;
12+
using System.ComponentModel;
1213
using System.Reflection;
1314

1415
Console.WriteLine($"Do nothing");
16+
17+
var reflector = new Reflector();
18+
var methodInfo = typeof(Sample).GetMethod(nameof(Sample.Command));
19+
20+
var argumentsSchema = reflector.GetArgumentsSchema(methodInfo);
21+
var outputSchema = reflector.GetReturnSchema(methodInfo);
22+
23+
Console.WriteLine("Arguments Schema:");
24+
Console.WriteLine(argumentsSchema.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
25+
Console.WriteLine("Output Schema:");
26+
Console.WriteLine(outputSchema.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
27+
28+
var schemaJson = reflector.GetSchema<GameState<PlayerProfile>>();
29+
30+
Console.WriteLine("Generic Schema:");
31+
Console.WriteLine(schemaJson.ToJsonString(new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
32+
33+
public static class Sample
34+
{
35+
// [McpServerTool]
36+
public static Result Command(List<Data> dataList, EnumFlag flag, Data? optionalData = null)
37+
{
38+
return new Result();
39+
}
40+
}
41+
42+
43+
public class Data
44+
{
45+
public int? optionalInt;
46+
[Description("THIS IS THE DEMO DESCRIPTION.")]
47+
public string address;
48+
public List<Data> list; // recursive
49+
}
50+
51+
public struct Result
52+
{
53+
public bool isDone;
54+
public string? errorMessage;
55+
}
56+
57+
[Description("DEMO ENUM DESCRIPTION.")]
58+
public enum EnumFlag { red, green, yellow }
59+
60+
61+
62+
63+
64+
65+
66+
// A simple value type
67+
public struct GeoPoint
68+
{
69+
public double Latitude;
70+
public double Longitude;
71+
}
72+
73+
// A complex entity
74+
public class PlayerProfile
75+
{
76+
public Guid Id { get; set; }
77+
public string Username { get; set; }
78+
public string[] Badges { get; set; } // Array
79+
public Dictionary<string, int> Stats { get; set; } // Dictionary
80+
}
81+
82+
// A generic wrapper (common in Game State or API responses)
83+
public class GameState<T>
84+
{
85+
public long Timestamp { get; set; }
86+
public T Player { get; set; }
87+
public List<GeoPoint> Checkpoints { get; set; } // List of Structs
88+
}

0 commit comments

Comments
 (0)