BadScript 2
Loading...
Searching...
No Matches
BadMetaData.cs
Go to the documentation of this file.
1using System.Text;
2
6
11
15public class BadMetaData : BadObject
16{
20 public static readonly BadMetaData Empty =
21 new BadMetaData("", "", "any", new Dictionary<string, BadParameterMetaData>());
22
26 public readonly string Description;
27
31 public readonly Dictionary<string, BadParameterMetaData> ParameterDescriptions;
32
36 public readonly string ReturnDescription;
37
41 public readonly string ReturnType;
42
51 string description,
52 string returnDescription,
53 string returnType,
54 Dictionary<string, BadParameterMetaData> parameterDescriptions)
55 {
56 Description = description;
57 ReturnDescription = returnDescription;
58 ParameterDescriptions = parameterDescriptions;
59 ReturnType = returnType;
60 }
61
64 {
65 throw new NotSupportedException();
66 }
67
69 public override bool HasProperty(string propName, BadScope? caller = null)
70 {
71 return propName is "Description" or "Return" or "Parameters" ||
72 base.HasProperty(propName, caller);
73 }
74
76 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
77 {
78 switch (propName)
79 {
80 case "Description":
81 return BadObjectReference.Make("BadMetaData.Description", () => Description);
82 case "Return":
84 "BadMetaData.Return",
85 () => new BadTable(
86 new Dictionary<string, BadObject>
87 {
88 {
89 "Type", ReturnType
90 },
91 {
92 "Description", ReturnDescription
93 },
94 }
95 )
96 );
97 case "Parameters":
99 "BadMetaData.Parameters",
100 () => new BadTable(
101 ParameterDescriptions.ToDictionary(
102 x => x.Key,
103 x => (BadObject)new BadTable(
104 new Dictionary<string, BadObject>
105 {
106 {
107 "Type", x.Value.Type
108 },
109 {
110 "Description", x.Value.Description
111 },
112 }
113 )
114 )
115 )
116 );
117 }
118
119 return base.GetProperty(propName, caller);
120 }
121
123 public override string ToSafeString(List<BadObject> done)
124 {
125 StringBuilder sb = new StringBuilder();
126
127 sb.AppendLine(Description);
128
129 foreach (KeyValuePair<string, BadParameterMetaData> kv in ParameterDescriptions)
130 {
131 sb.AppendLine($"Parameter {kv.Key} {kv.Value.Type}: {kv.Value.Description}");
132 }
133
134 sb.AppendLine("Returns: " + ReturnDescription);
135
136 return sb.ToString();
137 }
138}
Implements a Meta Data container for an expression.
override BadClassPrototype GetPrototype()
BadMetaData(string description, string returnDescription, string returnType, Dictionary< string, BadParameterMetaData > parameterDescriptions)
Creates a new Meta Data Object.
readonly string ReturnDescription
The Description of the Return Value.
override string ToSafeString(List< BadObject > done)
readonly string Description
The Description of the Expression.
readonly string ReturnType
The Return Type of the Expression.
readonly Dictionary< string, BadParameterMetaData > ParameterDescriptions
The Description of the Function Parameters.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
static readonly BadMetaData Empty
An empty Meta Data object.
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:129
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadObject > getter, Action< BadObject, BadPropertyInfo?>? setter=null, Action? delete=null)
Creates a new Reference Object.
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Implements a Class Prototype for the BadScript Language.
Contains the Parser for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.