用文件持久化數據

在軟件開發過程中發現一些數據用數據庫存儲很不方便,除此之外,數據庫的安裝也是一件很麻煩的事。於是就想到了利用文件來保存軟件運行過程中的數據。然後發現了FileHelpers。通過它可以很方便的對文件中的數據進行讀寫。

FileHelpers是一個免費且易於使用的.NET庫,用於從文件,字符串或流中的固定長度或分隔記錄中導入或導出數據。

您可以通過簡單地描述映射到每個記錄的類,然後將您的文件作爲強類型.NET數組讀取或寫入來強類型化您的平面文件(固定或分隔)。

該庫還支持從不同的數據存儲類型(如Excel,Access,SqlServer等)導入或導出數據。

FileHelpers is a free and easy to use .NET library to import or export data from fixed length or delimited records in files, strings or streams.

You can strongly type your flat file (fixed or delimited) by simply describing a class that maps to each record and later read or write your file as a strongly typed .NET array.

The library also has support to import or export data from different data storage types like Excel, Access, SqlServer, etc.

官方文檔及示例代碼已經很詳細的介紹了該項目的使用方法,在這裏就不過多敘述。

github地址:https://github.com/MarcosMeli/FileHelpers
官網:https://www.filehelpers.net/

在這裏插入圖片描述

在這裏插入圖片描述