Skip to content

Elorucov/PrefsLite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrefsLite

NuGet version (ELOR.PrefsLite)

Yet another lightweight library for saving preferences and settings into a file.

Usage

using static ELOR.PrefsLite.PrefsLite; // for methods "Deserialize" and "SerializeToXML"

// Initialize dictionary
Dictionary<string, object> settings = new Dictionary<string, object>();

// Reading settings file
var file = new FileStream("/path/to/settings.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096);
byte[] fileBytes = new byte[file.Length];
file.Read(fileBytes, 0, fileBytes.Length);

UTF8Encoding enc = new UTF8Encoding(true);
string content = enc.GetString(fileBytes);

if (content.Length == 0) return;

// Deserialize file content
settings = Deserialize(content);

// Add some parameter
settings.Add("answer", 42);

// Update settings file
content = SerializeToXML(settings);
byte[] bytes = Encoding.UTF8.GetBytes(content);
file.Position = 0;
file.SetLength(bytes.Length);
await file.WriteAsync(bytes);
await file.FlushAsync();

You can see full example here.

About

Yet another lightweight library for saving preferences and settings into a file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages