static void Main(string[] args) { // Test t = new Test(); // t.Key.Add(1); // t.Key.Add(2); // string json = JsonConvert.SerializeObject(t); // // var ne = JsonConvert.DeserializeObject<Test>(json); ObjectValue obj = new ObjectValue(); obj.Add("key", new StringValue("123")); MapValue map = new MapValue(); map.Add(new NumberValue("456"), new StringValue("hhhh")); map.Add(new NumberValue("4567"), new StringValue("hh222")); obj.Add("map", map); ObjectValue obj1 = new ObjectValue(); obj1.Add("key", new StringValue("123")); obj1.Add("map", map); ListValue list = new ListValue(); list.Add(obj1); list.Add(obj1); list.Add(obj1); obj.Add("list", list); File.WriteAllText("test.json", obj.ToJson(0)); File.WriteAllText("test.lua", obj.ToLua(0)); }
private void GenerateGlobal(ObjectValue exports, dynamic klass) { string name = FixClassName((string)klass["name"]); ObjectValue value = new BuiltinObjectValue( exports.ProjectEntry, ParseDocumentation((string)klass["desc"]) ); exports.Add(name, value.Proxy); if (klass.ContainsKey("methods")) { foreach (var method in klass["methods"]) { GenerateMethod( value, null, method ); } } Dictionary <string, PropertySpecializer> specializers; _propertySpecializations.TryGetValue(name, out specializers); GenerateProperties(klass, value, specializers); }
private void GenerateClass(ObjectValue exports, dynamic klass) { string className = (string)klass["name"]; List <OverloadResult> overloads = new List <OverloadResult>(); var fixedClassName = FixClassName(className); dynamic signatures; if (klass.TryGetValue("signatures", out signatures)) { foreach (var sig in signatures) { var parameters = GetParameters(sig["params"]); var doc = ParseDocumentation((string)sig["desc"]); overloads.Add(new SimpleOverloadResult(fixedClassName, doc, parameters)); } } BuiltinFunctionValue klassValue = new ClassBuiltinFunctionValue( exports.ProjectEntry, fixedClassName, overloads.ToArray(), ParseDocumentation((string)klass["desc"]) ); exports.Add(klassValue); if (klass.ContainsKey("methods")) { var prototype = (PrototypeValue)klassValue.Descriptors["prototype"].Values.Types.First().Value; Dictionary <string, FunctionSpecializer> classSpecializations; _classSpecializations.TryGetValue(className, out classSpecializations); foreach (var method in klass["methods"]) { GenerateMethod( prototype, classSpecializations, method ); } } if (klass.ContainsKey("classMethods")) { foreach (var method in klass["classMethods"]) { GenerateMethod( klassValue, null, method ); } } if (klass.ContainsKey("properties")) { var prototype = (PrototypeValue)klassValue.Descriptors["prototype"].Values.Types.First().Value; GenerateProperties(klass, prototype, null); } }
public override Task <SerializableValue> Execute(PluginExecuteContext context) { var result = new ObjectValue(); foreach (var(key, value) in context.Parameters) { result.Add(key, value); } return(Task.FromResult <SerializableValue>(result)); }
private ObjectValue GetObjectValue() { bool foundEof = false; var objectValue = new ObjectValue(); while (true) { // grab the next line string line = _reader.ReadLine(); if (line == null) { foundEof = true; break; } // retrieve the object type EntryType entryType = GetEntryType(line); // Console.WriteLine("--- DEBUG: entryType: {0}", entryType); if (entryType == EntryType.EndBraces) { var dataTypeMatch = _dataTypeRegex.Match(line); if (dataTypeMatch.Success) { objectValue.DataType = dataTypeMatch.Groups[1].Value; // Console.WriteLine("DEBUG: data type: {0}", dataTypeMatch.Groups[1].Value); } break; } switch (entryType) { case EntryType.ObjectKeyValue: objectValue.Add(GetObjectKeyValue(line)); break; case EntryType.ListObjectKeyValue: objectValue.Add(GetListObjectKeyValue(line)); break; case EntryType.StringKeyValue: objectValue.Add(GetStringKeyValue(line)); break; case EntryType.DigitKeyValue: objectValue.Add(GetDigitKeyValue(line)); break; case EntryType.UndefKeyValue: objectValue.Add(GetUndefKeyValue(line)); break; case EntryType.ReferenceStringKeyValue: objectValue.Add(GetReferenceKeyValue(line)); break; case EntryType.EmptyListKeyValue: objectValue.Add(GetEmptyListKeyValue(line)); break; case EntryType.EmptyValueKeyValue: objectValue.Add(GetEmptyValueKeyValue(line)); break; case EntryType.BinaryKeyValue: objectValue.Add(GetBinaryKeyValue(line)); break; case EntryType.MultiLineKeyValue: objectValue.Add(GetMultiLineKeyValue(line)); break; default: throw new GeneralException( $"Unhandled entry type encountered in GetObjectValue: {entryType}"); } } if (foundEof) { throw new GeneralException("Found an EOF before finding the ending curly braces for the current object value"); } return(objectValue); }
private void GenerateProperties(dynamic klass, ObjectValue value, Dictionary <string, PropertySpecializer> specializers) { if (klass.ContainsKey("properties")) { foreach (var prop in klass["properties"]) { string propName = prop["name"]; string desc = ParseDocumentation(prop["desc"]); string textRaw = ""; if (prop.ContainsKey("textRaw")) { textRaw = prop["textRaw"]; } PropertySpecializer specializer; AnalysisValue propValue = null; if (specializers != null && specializers.TryGetValue(propName, out specializer)) { propValue = specializer.Specialize(value.ProjectEntry, propName); } else if (desc.IndexOf("<code>Boolean</code>") != -1) { propValue = value.ProjectEntry.Analyzer._trueInst; } else if (desc.IndexOf("<code>Number</code>") != -1) { propValue = value.ProjectEntry.Analyzer._zeroIntValue; } else if (desc.IndexOf("<code>Readable Stream</code>") != -1) { propValue = _readableStream; } else if (desc.IndexOf("<code>Writable Stream</code>") != -1 || textRaw == "process.stderr") { propValue = _writableStream; } else if (!String.IsNullOrWhiteSpace(textRaw)) { int start, end; if ((start = textRaw.IndexOf('{')) != -1 && (end = textRaw.IndexOf('}')) != -1 && start < end) { string typeName = textRaw.Substring(start, end - start); switch (typeName) { case "Boolean": propValue = value.ProjectEntry.Analyzer._trueInst; break; case "Number": propValue = value.ProjectEntry.Analyzer._zeroIntValue; break; } } } if (propValue == null) { propValue = new BuiltinObjectValue(value.ProjectEntry); } value.Add( new MemberAddInfo( propName, propValue, desc, true ) ); } } }