Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ObjectContent.cs
1using System;
3using System.Reflection;
4using System.Threading.Tasks;
6
8{
13 {
18 : base()
19 {
20 }
21
25 public override Type[] Encodes => new Type[]
26 {
27 typeof(object)
28 };
29
33 public override bool IsStructuredContent => true;
34
41 public override async Task<Dictionary<string, object>> Encode(object Content)
42 {
43 Dictionary<string, object> Properties = new Dictionary<string, object>();
44 Dictionary<string, object> Result = new Dictionary<string, object>()
45 {
46 { "type", "object" },
47 { "properties", Properties }
48 };
49
50 this.Annotate(Result);
51
52 Type T = Content?.GetType() ?? typeof(object);
53
54 foreach (FieldInfo FI in T.GetFields(BindingFlags.Public | BindingFlags.Instance))
55 Properties[FI.Name] = await ScriptNode.WaitPossibleTask(FI.GetValue(Content));
56
57 foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Public | BindingFlags.Instance))
58 Properties[PI.Name] = await ScriptNode.WaitPossibleTask(PI.GetValue(Content));
59
60 return Result;
61 }
62 }
63}
Abstract base class for an MCP Content Block.
Definition: ContentBlock.cs:11
override void Annotate(Dictionary< string, object > Object)
Annotates an object.
Definition: ContentBlock.cs:57
override Type[] Encodes
What types the content block encodes.
override async Task< Dictionary< string, object > > Encode(object Content)
Encodes a content block, given the content to encode and available annotations and meta-data.
override bool IsStructuredContent
If the content block is encoded as structured content.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
static async Task< object > WaitPossibleTask(object Result)
Waits for any asynchronous process to terminate.
Definition: ScriptNode.cs:441