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
50 public BadMetaData(string description,
51 string returnDescription,
52 string returnType,
53 Dictionary<string, BadParameterMetaData> parameterDescriptions)
54 {
55 Description = description;
56 ReturnDescription = returnDescription;
57 ParameterDescriptions = parameterDescriptions;
58 ReturnType = returnType;
59 }
60
63 {
64 throw new NotSupportedException();
65 }
66
68 public override bool HasProperty(string propName, BadScope? caller = null)
69 {
70 return propName is "Description" or "Return" or "Parameters" ||
71 base.HasProperty(propName, caller);
72 }
73
75 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
76 {
77 switch (propName)
78 {
79 case "Description":
80 return BadObjectReference.Make("BadMetaData.Description", (p) => Description);
81 case "Return":
82 return BadObjectReference.Make("BadMetaData.Return",
83 (p) => new BadTable(new Dictionary<string, BadObject>
84 {
85 { "Type", ReturnType },
86 { "Description", ReturnDescription },
87 }
88 )
89 );
90 case "Parameters":
91 return BadObjectReference.Make("BadMetaData.Parameters",
92 (p) => new BadTable(ParameterDescriptions.ToDictionary(x => x.Key,
93 x => (BadObject)
94 new BadTable(new Dictionary<string,
96 {
97 { "Type", x.Value.Type },
98 {
99 "Description",
100 x.Value.Description
101 },
102 }
103 )
104 )
105 )
106 );
107 }
108
109 return base.GetProperty(propName, caller);
110 }
111
113 public override string ToSafeString(List<BadObject> done)
114 {
115 StringBuilder sb = new StringBuilder();
116
117 sb.AppendLine(Description);
118
119 foreach (KeyValuePair<string, BadParameterMetaData> kv in ParameterDescriptions)
120 {
121 sb.AppendLine($"Parameter {kv.Key} {kv.Value.Type}: {kv.Value.Description}");
122 }
123
124 sb.AppendLine("Returns: " + ReturnDescription);
125
126 return sb.ToString();
127 }
128}
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:16
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:141
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadSourcePosition?, BadObject > getter, Action< BadObject, BadSourcePosition?, BadPropertyInfo?>? setter=null, Action< BadSourcePosition?>? 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.