Appending JSON file

This commit is contained in:
Stedd 2021-08-01 12:36:42 +02:00
parent a08b729982
commit 755ffa610f
3 changed files with 40 additions and 1 deletions

View File

@ -6,4 +6,8 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="5.0.7" />
</ItemGroup>
</Project> </Project>

View File

@ -7,6 +7,7 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800">
<Grid> <Grid>
<Button x:Name="saveButton" Content="Save" HorizontalAlignment="Left" Margin="400,0,0,173" VerticalAlignment="Bottom" Height="216" Width="349" Click="saveButton_Click"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -12,6 +12,9 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
namespace CryptoCalc namespace CryptoCalc
{ {
@ -20,10 +23,41 @@ namespace CryptoCalc
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private readonly Random rand = new();
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
//asdf
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("asdf");
var weatherForecast = new WeatherForecast
{
Date = DateTime.Parse("2019-08-01"),
TemperatureCelsius = rand.Next(0,100),
Summary = "Hot"
};
string fileName = "asdf.json";
string jsonString = JsonSerializer.Serialize(weatherForecast);
File.AppendAllText(fileName, jsonString);
Debug.WriteLine(File.ReadAllText(fileName));
} }
} }
public class WeatherForecast
{
public DateTimeOffset Date { get; set; }
public int TemperatureCelsius { get; set; }
public string Summary { get; set; }
}
} }