ランキングに戻る

rickyah/ini-parser

C#

Read/Write an INI file the easy way!

c-sharpunity3dinimonocliconfigurationconfigconfiguration-managementconfiguration-fileconfig-managementiniparserini-parser
スター成長
スター
1k
フォーク
250
週間成長
Issue
54
5001k
2013年1月2017年7月2022年1月2026年7月
README

INI File Parser

A .NET, Mono and Unity3d compatible(*) library for reading/writing INI data from IO streams, file streams, and strings written in C#.

Also implements merging operations, both for complete ini files, sections, or even just a subset of the keys contained by the files.

(*) This library is 100% .NET code and does not have any dependencies on Windows API calls in order to be portable.

Build Status

Get the latest version: https://github.com/rickyah/ini-parser/releases/latest Install it with NuGet: https://www.nuget.org/packages/ini-parser/

Version 2.0

Since the INI format isn't really a "standard", version 2 introduces a simpler way to customize INI parsing:

  • Pass a configuration object to an IniParser, specifying the behaviour of the parser. A default implementation is used if none is provided.

  • Derive from IniDataParser and override the fine-grained parsing methods.

Installation

The library is published to NuGet and can be installed on the command-line from the directory containing your solution.

> nuget install ini-parser

Or, from the Package Manager Console in Visual Studio

PM> Install-Package ini-parser

If you are using Visual Studio, you can download the NuGet Package Manager extension that will allow adding the NuGet dependency for your project.

If you use MonoDevelop / Xamarin Studio, you can install the MonoDevelop NuGet AddIn to also be able to add this library as dependency from the IDE.

Getting Started

All code examples expect the following using clauses:

using IniParser;
using IniParser.Model;

INI data is stored in nested dictionaries, so accessing the value associated to a key in a section is straightforward. Load the data using one of the provided methods.

var parser = new FileIniDataParser();
IniData data = parser.ReadFile("Configuration.ini");

Retrieve the value for a key inside of a named section. Values are always retrieved as strings.

string useFullScreenStr = data["UI"]["fullscreen"];
// useFullScreenStr contains "true"
bool useFullScreen = bool.Parse(useFullScreenStr);

Modify the value in the dictionary, not the value retrieved, and save to a new file or overwrite.

data["UI"]["fullscreen"] = "true";
parser.WriteFile("Configuration.ini", data);

Head to the wiki for more usage examples, or check out the code of the example project

Merging ini files

Merging ini files is a one-method operation:


   var parser = new IniParser.Parser.IniDataParser();

   IniData config = parser.Parse(File.ReadAllText("global_config.ini"));
   IniData user_config = parser.Parse(File.ReadAllText("user_config.ini"));
   config.Merge(user_config);

   // config now contains that data from both ini files, and the values of
   // the keys and sections are overwritten with the values of the keys and
   // sections that also existed in the user config file

Keep in mind that you can merge individual sections if you like:

config["user_settings"].Merge(user_config["user_settings"]);

Comments

The library allows modifying the comments from an ini file. However note than writing the file back to disk, the comments will be rearranged so comments are written before the element they refer to.

To query, add or remove comments, access the property Comments available both in SectionData and KeyData models.

var listOfCommentsForSection = config.["user_settings"].Comments;
var listOfCommentsForKey = config["user_settings"].GetKeyData("resolution").Comments;

Unity3D

You can easily use this library in your Unity3D projects. Just drop either the code or the DLL inside your project's Assets folder and you're ready to go!

ini-parser is actually being used in ProjectPrefs a free add-on available in the Unity Assets Store that allows you to set custom preferences for your project. I'm not affiliated with this project: Kudos to Garrafote for making this add-on.

Contributing

Do you have an idea to improve this library, or did you happen to run into a bug? Please share your idea or the bug you found in the issues page, or even better: feel free to fork and contribute to this project with a Pull Request.

関連リポジトリ
shadowsocks/shadowsocks-windows

A C# port of shadowsocks

C#Othershadowsocksc-sharp
59.6k16.2k
AvaloniaUI/Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The future of .NET UI

C#MIT Licensec-sharpxaml
avaloniaui.net
31.2k2.8k
google/flatbuffers

FlatBuffers: Memory Efficient Serialization Library

C++Apache License 2.0flatbuffersserialization
flatbuffers.dev
26.2k3.6k
icsharpcode/ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!

C#MIT Licensedecompilerdecompiler-engine
25.7k3.7k
CodeHubApp/CodeHub

CodeHub is an iOS application written using Xamarin

C#codehubc-sharp
codehub-app.com
22.6k609
QuantConnect/Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)

C#Apache License 2.0c-sharpalgorithmic-trading-engine
lean.io
20.6k5.1k
microsoft/CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit

C++Othercognitive-toolkitcntk
docs.microsoft.com/cognitive-toolkit/
17.6k4.2k
MaterialDesignInXAML/MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.

C#MIT Licensec-sharpmaterial
16.2k3.5k
duplicati/duplicati

Store securely encrypted backups in the cloud!

C#Otherduplicatibackup
14.8k1.1k
dotnet/efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.

C#MIT Licenseentity-frameworkdatabase
learn.microsoft.com/ef/
14.8k3.4k
abpframework/abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.

C#GNU Lesser General Public License v3.0abpcsharp
abp.io
14.4k3.7k
MonoGame/MonoGame

One framework for creating powerful cross-platform games.

C#Otherxnamonogame
monogame.net
14.2k3.1k