public static void serialize(ModuleTree tree, LuaObject obj) { LuaObject size = obj.state.createTable(); size.set(tree.size.X, 1); size.set(tree.size.Y, 2); obj["size"] = size; LuaObject nodes = obj.state.createTable(); obj["nodes"] = nodes; int idx = 1; foreach (Module m in tree.moduleOrderedList()) { LuaObject mobj = obj.state.createTable(); SerializeModule ser = null; if (mySerializers.TryGetValue(m.myType, out ser) == true) { ser(m, mobj); nodes.set(mobj, idx++); } else { throw new Exception(String.Format("Failed to find creator {0}", m.myType)); } } obj.set(tree.output.myName, "output"); }
private IDescription ExtractDescription(object asset, Type assetType) { switch (asset) { case DescriptionAsset descriptionAsset: { return(descriptionAsset.GetDescription()); } case TextAsset textAsset: { ISerializer <string> serializer = SerializeModule.GetDefaultTextSerializer(); return((IDescription)serializer.Deserialize(assetType, textAsset.text)); } default: throw new ArgumentException($"Unexpected asset type: '{asset}'.", nameof(asset)); } }
private static ISerializeUtf8JsonModule CreateModule(ISerializeModuleDescription serializeModuleDescription, ISerializeUtf8JsonModuleDescription utf8JsonModuleDescription) { if (serializeModuleDescription == null) { throw new ArgumentNullException(nameof(serializeModuleDescription)); } if (utf8JsonModuleDescription == null) { throw new ArgumentNullException(nameof(utf8JsonModuleDescription)); } var serializeModule = new SerializeModule(serializeModuleDescription); var serializeUtf8JsonModule = new SerializeUtf8JsonModule(serializeModule, utf8JsonModuleDescription); using (new LogEnableScope(false)) { serializeModule.Initialize(); serializeUtf8JsonModule.Initialize(); } return(serializeUtf8JsonModule); }