Saving Feature Help
I got a list I use in my app want to add a saving feature but don't know which filetype to use besides txt whats your recommendation?
21 Replies
It depends heavily on the file's content encoding
.dat/.bin for Binary files
.config/.cfg/.env for environmental configuration (generaly in plain text)
.json/.xml/.html for structured readable information (commonly serializable)
NO EXTENSION for special files like lockfile
What do you think? @naber top
probably i will use .json
im trying to learn how to use it actually rn
Take a look on how to use json with a Newtonsoft.json (library) @naber top
if you want a prettified json output you can use Formatting.Idented
would this work this the observable collections?
newtonsoft.json is more or less obsolete
system.text.json is what you should be using unless it can't do what you want for some reason
And please don't use anonymous objects
you could use
System.Text.Json
to save content (should be able to install it through nuget)For netfx yes, for .net it comes as a part of the bcl
for whatever reason it wasn't included by default in my .net project
If it doesn't work with the observable collections and you don't want to implement it manually I don't see anything wrong with extracting the collection content to an array then serializing to the file, you can after retrieve the objects when deserializing and recreating the collection from the start
I use anonymous types when desserializing responses from client's APIs, they can be pretty gigantic, creating classes to them would be a waste of time just for a single piece of information needed.
you don't need to model every property, just the ones you need
there is no reason to use an anonymous type for ths, it just makes the code more error prone
what do you mean by modeling
mvvm?
:oh:
no, i mean making a class that matches the shape of the json
oh
would be the safe way to do james's example
the code is actually shorter than the "convenient" anonymous method 😛
what is anonymous in this context i still don't understand :Smadge:
is an anonymous object, because it isn't a named type
YEA! Records. SCIENCE!
is it normal that stuff kind of overwhelms me to get it together
am I in the wrong path or its just a part of the process
depends how much experience you have with C#, if not a lot then it's understandable
well im a beginner I just know the foundational c# stuff (the only thing I completed as a course)