Пример #1
0
        public void Save()
        {
            var unityPackageManifestPath = Path.Combine(Project.UnityProjectRoot, "Packages", "manifest.json");
            var factory = new JsonFactory <UnityPackageManifest>();

            factory.Serialize(unityPackageManifestPath, this);
        }
Пример #2
0
        public Task SendAsync <ValueT>(string message, ValueT value, ISerializer <ValueT> serializer)
        {
            if (serializer is null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            OnDebug($"Send: {value} => {message}");
            var data          = serializer.Serialize(value);
            var dataMessage   = new DataMessage(message, data);
            var msgSerializer = new JsonFactory <DataMessage>();

            return(SendAsync(msgSerializer.Serialize(dataMessage)));
        }
Пример #3
0
        public static void Save(IEnumerable <Connection> connections)
        {
            if (connections is null)
            {
                throw new ArgumentNullException(nameof(connections));
            }

            ConnectionsFile.Directory.Create();
            var saver = new JsonFactory <Connection[]>();

            using var stream = ConnectionsFile.Open(FileMode.Create, FileAccess.Write, FileShare.None);
            saver.Serialize(stream, connections.ToArray());
            foreach (var connection in connections)
            {
                connection.Commit();
            }
        }
Пример #4
0
        public void SerializeToFile()
        {
            const string fileName = "testSerializationToFile.json";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var factory = new JsonFactory <string[]>();
            var values  = new[]
            {
                "asdf",
                "qwer",
                "zxcv"
            };

            factory.Serialize(fileName, values);

            Assert.IsTrue(File.Exists(fileName));
        }