Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ var serializedTomlText = Encoding.UTF8.GetString(serializedText.ByteSpan);
// Name = "Mixed"
```

#### Spec

`Spec` can enable features in TOML v1.1.0.
#### Spec
`Spec` can enable features in TOML v1.1.0.
For more information, please click [TOML v1.1.0 features overview](#toml-v110-features-overview).

Built-in support type
Expand Down Expand Up @@ -914,7 +914,7 @@ It may be used to add optional features in the future.
T Deserialize<T>(ReadOnlySpan<byte> tomlText, CsTomlSerializerOptions? options = null)
T Deserialize<T>(ReadOnlySequence<byte> tomlSequence, CsTomlSerializerOptions? options = null)
T Deserialize<T>(Stream stream, CsTomlSerializerOptions? options = null)
DeserializeAsync<T>(Stream stream, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default)
ValueTask<T> DeserializeAsync<T>(Stream stream, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default)
```

Asynchronous API is available as `CsTomlSerializer.DeserializeAsync`.
Expand All @@ -940,7 +940,7 @@ var dict2 = CsTomlSerializer.Deserialize<IDictionary<object, object>>(tomlText);
```

If a syntax error is found during deserialization, an `CsTomlSerializeException` is thrown after deserialization.
The contents of the thrown exception can be viewed at `CsTomlException.ParseExceptions`.
The contents of the thrown exception can be viewed at `CsTomlSerializeException.ParseExceptions`.

```csharp
var tomlText = @"
Expand All @@ -957,7 +957,7 @@ catch (CsTomlSerializeException ctse)
{
foreach (var cte in ctse.ParseExceptions!)
{
// A syntax error (CsTomlException) was thrown during the parsing line 3.
// A syntax error (CsTomlException) was thrown while parsing line 3.
var e = cte.InnerException; // CsToml.Error.CsTomlException: Escape characters 13 were included.
var lineNumber = cte.LineNumber;
}
Expand All @@ -967,13 +967,13 @@ catch (CsTomlSerializeException ctse)
Serialize API
---

`Serialize` has three overloads, including synchronous and asynchronous APIs.
`Serialize` has four overloads, including synchronous and asynchronous APIs.

```csharp
ByteMemoryResult Serialize<T>(T target, CsTomlSerializerOptions? options = null)
void Serialize<TBufferWriter, T>(ref TBufferWriter bufferWriter, T target, CsTomlSerializerOptions? options = null)
void Serialize<T>(Stream stream, T value, CsTomlSerializerOptions? options = null)
async ValueTask SerializeAsync<T>(Stream stream, T value, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default)
ValueTask SerializeAsync<T>(Stream stream, T value, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default)
```

`IBufferWriter<byte>` serializes directly into the buffer.
Expand Down Expand Up @@ -1382,9 +1382,9 @@ var arrayIndex2 = document.RootNode["array"u8]["of"u8]["tables"u8][2]["array"u8]

### Complex samples.

```TOML
dotted.keys = "value"
configurations = [1, {key = [ { key2 = ["VALUE"]}]}]
```TOML
dotted.keys = "value"
configurations = [1, {key = [ { key2 = ["VALUE"]}]}]
```

```csharp
Expand Down Expand Up @@ -1464,8 +1464,8 @@ public enum TomlValueType
`TomlDocumentNode.GetValue<T>` and `TomlDocumentNode.TryGetValue<T>` can be used to obtain a value converted from a Toml value type to a specified type.
The type that can be specified for `T` is [Built-in support type](#built-in-support-type).

```TOML
key = "https://github.com/prozolic/CsToml"
```TOML
key = "https://github.com/prozolic/CsToml"
```

```csharp
Expand Down Expand Up @@ -1552,19 +1552,19 @@ var document = CsTomlSerializer.Deserialize<TomlDocument>(tomlText, v110Options)
This feature permits newline characters after key/value pairs within inline tables.
For example:

```toml
name = {
first = "CsToml",
last = "prozolic" }
```toml
name = {
first = "CsToml",
last = "prozolic" }
```

### AllowTrailingCommaInInlineTables

This feature supports an optional trailing comma after the last key/value pair in inline tables.
For example:

```toml
name = { first = "CsToml", last = "prozolic", }
```toml
name = { first = "CsToml", last = "prozolic", }
```

### AllowSecondsOmissionInTime
Expand Down Expand Up @@ -1634,6 +1634,30 @@ await CsTomlFileSerializer.SerializeAsync("test.toml", document);
`CsTomlFileSerializer.Deserialize` and `CsTomlFileSerializer.DeserializeAsync` deserialize UTF8 strings in TOML files into `TomlDocument`.
`CsTomlFileSerializer.Serialize` and `CsTomlFileSerializer.SerializeAsync` serialize the UTF8 string of `TomlDocument` to the TOML file.

By default, a `FormatException` will be thrown if the file extension is not `.toml`.
If you want to relax the file extension restriction, please use the overload that accepts `TomlFileExtensionPolicy.Relaxed`.
This overload will be available starting from v1.8.3.

```csharp
public partial class CsTomlFileSerializer
{
public static T Deserialize<T>(string tomlFilePath, CsTomlSerializerOptions? options = null);
public static T Deserialize<T>(string tomlFilePath, CsTomlSerializerOptions? options, TomlFileExtensionPolicy extensionPolicy);
public static ValueTask<T> DeserializeAsync<T>(string tomlFilePath, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default);
public static ValueTask<T> DeserializeAsync<T>(string tomlFilePath, CsTomlSerializerOptions? options, TomlFileExtensionPolicy extensionPolicy, bool configureAwait = false, CancellationToken cancellationToken = default);
public static void Serialize<T>(string tomlFilePath, T value, CsTomlSerializerOptions? options = null);
public static void Serialize<T>(string tomlFilePath, T value, CsTomlSerializerOptions? options, TomlFileExtensionPolicy extensionPolicy);
public static ValueTask SerializeAsync<T>(string tomlFilePath, T value, CsTomlSerializerOptions? options = null, bool configureAwait = false, CancellationToken cancellationToken = default);
public static ValueTask SerializeAsync<T>(string tomlFilePath, T value, CsTomlSerializerOptions? options, TomlFileExtensionPolicy extensionPolicy, bool configureAwait = false, CancellationToken cancellationToken = default);
}

public enum TomlFileExtensionPolicy
{
Strict = 0,
Relaxed = 1
}
```

`CsToml.Extensions` uses [Cysharp/NativeMemoryArray](https://github.com/Cysharp/NativeMemoryArray) as a third party library.

Microsoft.Extensions.Configuration extensions (`CsToml.Extensions.Configuration`)
Expand Down Expand Up @@ -1668,8 +1692,10 @@ public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder build
public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, string path, bool optional);
public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, string path, bool optional, bool reloadOnChange);
public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider? provider, string path, bool optional, bool reloadOnChange);
public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider? provider, string path, bool optional, bool reloadOnChange, CsTomlSerializerOptions? serializerOptions);
public static IConfigurationBuilder AddTomlFile(this IConfigurationBuilder builder, Action<TomlFileConfigurationSource> configureSource);
public static IConfigurationBuilder AddTomlStream(this IConfigurationBuilder builder, System.IO.Stream stream);
public static IConfigurationBuilder AddTomlStream(this IConfigurationBuilder builder, System.IO.Stream stream, CsTomlSerializerOptions? serializerOptions);
```

UnitTest
Expand Down
2 changes: 1 addition & 1 deletion src/CsToml/CsToml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.IO.Hashing" Version="10.0.2" />
<PackageReference Include="System.IO.Hashing" Version="10.0.7" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<VersionPrefix>1.8.2</VersionPrefix>
<VersionPrefix>1.8.3</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down