File: README.md

package info (click to toggle)
libeconf 0.7.7%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,636 kB
  • sloc: ansic: 7,440; python: 1,204; cs: 651; sh: 214; xml: 182; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# `LibEConf.NET`
`LibEConf.NET` is a .NET wrapper for `libeconf` written in C#. It is memory safe and uses P/Invoke to talk to the native library. The core library has no external dependencies besides the native binary for `libeconf`.

# Usage
The bindings are split into two classes: `EConf` is a static class which only contains static methods. All method calls have the same naming scheme,
if you want to access a function `econf_<functionName>`, the C# equivalent would be `EConf.<FunctionName>`.

`EConfFile` is an instance class, which contains all instance methods which work on a file. `EConfFile` also implements `IDisposable`, so you can use it inside of `using` scopes.

You can find more information about each method [here](methods.md).

## Example
_foo.ini_
```ini
[MyGroup]
MyKey=MyValue # This is a comment.
MyOtherKey=5
```
The following code reads a file, modifies both values and saves it again.
```cs
using LibEConf.NET; // Import the bindings.

EConfErr err = EConf.ReadFile(out EConfFile myFile, "foo.ini", "=", "#");   // Open the file for reading.
int result = myFile.GetValueInt("MyGroup", "MyOtherKey");                   // Get the value for "MyOtherKey" from the file.
myFile.SetValue("MyGroup", "MyOtherKey", result + 5);                       // Set the value for "MyOtherKey" to 5 + 5.
myFile.SetValue("MyGroup", "MyKey", "foobar");                              // Set "MyKey" to "foobar".
myFile.WriteFile("foo.ini");                                                // Save the file.
```
_foo.ini_ will then look like this:
```ini
[MyGroup]
MyKey=foobar
MyOtherKey=10
```

# Building from Source
To build from source open up the `LibEConf.NET.csproj` file in the .NET IDE of your choice and press _Build_.
If you're using the `dotnet CLI`, open up the folder where the project file is located in and run `dotnet build`.
You will also need to build `libeconf` and copy the resulting binaries (`.so`/`.dll`) to the output directory.