https://github.com/feifeid47/kvfile
key-value文件存储,能将任何可序列化的数据按键值对的方式存储,简单易用,跨平台。适用于配置文件、游戏存档等等
https://github.com/feifeid47/kvfile
csharp dotnet file
Last synced: 4 months ago
JSON representation
key-value文件存储,能将任何可序列化的数据按键值对的方式存储,简单易用,跨平台。适用于配置文件、游戏存档等等
- Host: GitHub
- URL: https://github.com/feifeid47/kvfile
- Owner: feifeid47
- License: apache-2.0
- Created: 2023-02-15T12:42:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-27T03:42:23.000Z (over 3 years ago)
- Last Synced: 2025-04-19T16:23:11.692Z (about 1 year ago)
- Topics: csharp, dotnet, file
- Language: C#
- Homepage:
- Size: 11.7 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 介绍
key-value文件存储,能将任何可序列化的数据按键值对的方式存储,简单易用,跨平台。
依赖Newtonsoft.Json。(附Nuget地址:[https://www.nuget.org/packages/Newtonsoft.Json](https://gitee.com/link?target=https%3A%2F%2Fwww.nuget.org%2Fpackages%2FNewtonsoft.Json))
### 存储
```C#
// public enum Color
// {
// Red,
// Blue,
// }
// public class Person
// {
// public string name;
// public int age;
// }
// public struct Point
// {
// public int x;
// public int y;
// }
var file = new KVFile(@"D:\data.dat");
// 存储int数据
file.Set("IntValue", 1);
// 存储float数据
file.Set("FloatValue", 3.14f);
// 存储double数据
file.Set("DoubleValue", 3.14);
// 存储string数据
file.Set("StringValue", "Hello");
// 存储枚举
file.Set("EnumValue", Color.Red);
// 存储对象
file.Set("ObjectValue", new Person()
{
name = "Nick",
age = 18
});
// 存储结构体
file.Set("StructValue", new Point());
// 保存文件
file.Save();
```
### 读取
```C#
var file = KVFile.Open(@"D:\data.dat");
// 读取int数据
int intValue = file.Get("IntValue");
// 读取float数据
float floatValue = file.Get("FloatValue");
// 读取double数据
double doubleValue = file.Get("DoubleValue");
// 读取string数据
string stringValue = file.Get("StringValue");
// 读取枚举
Color enumValue = file.Get("EnumValue");
// 读取对象
Person objectValue = file.Get("ObjectValue");
// 读取结构体
Point structValue = file.Get("StructValue");
```