DevPossible.Ton
0.1.8
dotnet add package DevPossible.Ton --version 0.1.8
NuGet\Install-Package DevPossible.Ton -Version 0.1.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DevPossible.Ton" Version="0.1.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DevPossible.Ton" Version="0.1.8" />
<PackageReference Include="DevPossible.Ton" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DevPossible.Ton --version 0.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DevPossible.Ton, 0.1.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DevPossible.Ton@0.1.8
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DevPossible.Ton&version=0.1.8
#tool nuget:?package=DevPossible.Ton&version=0.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DevPossible.Ton - C# / .NET Library
Developed by DevPossible, LLC
Contact: support@devpossible.com
.NET Standard 2.1 implementation of the TON (Text Object Notation) parser, serializer, formatter, and validator.
Installation
Via NuGet Package Manager
dotnet add package DevPossible.Ton
Via Package Manager Console
Install-Package DevPossible.Ton
Via PackageReference
<PackageReference Include="DevPossible.Ton" Version="0.1.8" />
Quick Start
using DevPossible.Ton;
// Parse a TON file
var parser = new TonParser();
var document = parser.ParseFile("config.ton");
// Access properties
string name = document.RootObject.GetProperty("name")?.ToString();
int port = document.RootObject.GetProperty("port")?.ToInt32() ?? 8080;
// Create a new document
var newDoc = new TonDocument();
newDoc.RootObject.SetProperty("name", TonValue.From("My App"));
newDoc.RootObject.SetProperty("port", TonValue.From(8080));
// Add nested object
var database = new TonObject { ClassName = "database" };
database.SetProperty("host", TonValue.From("localhost"));
newDoc.RootObject.AddChild(database);
// Serialize and save
var serializer = new TonSerializer();
string tonContent = serializer.SerializeDocument(newDoc, TonSerializeOptions.Pretty);
await serializer.SerializeToFileAsync(newDoc, "config.ton", TonSerializeOptions.Pretty);
Features
- ✅ Full TON specification parser with async support
- ✅ Comprehensive schema validation with 30+ validation rule types
- ✅ Code formatter with compact and pretty styles
- ✅ Type annotations and hints
- ✅ Enum and EnumSet support
- ✅ Array support with mixed types
- ✅ Pretty and compact serialization
- ✅ Async file operations
- ✅ Schema collections and definitions
- ✅ Path-based schema validation
- ✅ Object conversion (C# ↔ TON)
Advanced Usage
Schema Validation
using DevPossible.Ton;
// Define schema
var schemas = new TonSchemaCollection();
var userSchema = new TonSchemaDefinition("user");
// Add property validations
var nameSchema = new TonPropertySchema("/name", "string");
nameSchema.AddValidation(new TonValidationRule(ValidationRuleType.Required));
nameSchema.AddValidation(new TonValidationRule(ValidationRuleType.MaxLength, 100));
userSchema.AddProperty("/name", nameSchema);
var emailSchema = new TonPropertySchema("/email", "string");
emailSchema.AddValidation(new TonValidationRule(ValidationRuleType.Format, "email"));
userSchema.AddProperty("/email", emailSchema);
schemas.AddSchema(userSchema);
// Validate document
var validator = new TonValidator();
var document = parser.Parse("{ (user) name = 'John', email = 'john@example.com' }");
document.Schemas = schemas;
var results = validator.Validate(document);
if (!results.IsValid)
{
foreach (var error in results.Errors)
Console.WriteLine($"Error at {error.Path}: {error.Message}");
}
Formatting
using DevPossible.Ton;
// Format a TON string with pretty formatting (default)
string unformattedTon = "{name='MyApp',version=1.0,enabled=true}";
string prettyFormatted = TonFormatter.FormatString(unformattedTon);
// Format with compact formatting
string compactFormatted = TonFormatter.FormatString(unformattedTon, TonFormatStyle.Compact);
// Format files
TonFormatter.FormatFileInPlace("config.ton", TonFormatStyle.Pretty);
// Async formatting
string formatted = await TonFormatter.FormatStringAsync(unformattedTon, TonFormatStyle.Pretty);
Serialization Options
// Compact format - minimal size
var compact = TonSerializeOptions.Compact;
// Pretty format - human readable with all features
var pretty = TonSerializeOptions.Pretty;
// Custom options
var custom = new TonSerializeOptions
{
// Formatting
Indentation = " ", // Two spaces
Pretty = true, // Enable formatting
SortProperties = true, // Alphabetical property order
// Content control
IncludeHeader = true, // Include #@ header
IncludeSchema = true, // Include #! schema
IncludeTypeHints = true, // Add type hints ($, %, etc.)
// Value handling
OmitNullValues = false, // Include null values
OmitUndefinedValues = true, // Skip undefined values
OmitEmptyCollections = false, // Include empty arrays
// Formatting preferences
UseAtPrefix = true, // Use @ for properties
QuoteChar = '\'', // Use single quotes
UseMultiLineStrings = true, // Enable multi-line string format
MultiLineStringThreshold = 2, // Min lines to use multi-line format
LowercaseHex = true, // 0xff instead of 0xFF
LowercaseGuids = true, // Lowercase GUID format
PreferEnumNames = true // Use names over indices
};
var serializer = new TonSerializer();
string output = serializer.SerializeDocument(document, custom);
Object Conversion
// Convert C# object to TON
public class Configuration
{
public string Name { get; set; }
public int Port { get; set; }
public bool Enabled { get; set; }
public string[] Tags { get; set; }
}
var config = new Configuration
{
Name = "MyApp",
Port = 8080,
Enabled = true,
Tags = new[] { "production", "web" }
};
var tonObject = TonObject.FromObject(config);
var document = new TonDocument(tonObject);
// Convert TON to C# object
var parsedConfig = document.RootObject.ToObject<Configuration>();
API Reference
Core Classes
TonDocument- Represents a complete TON document with header, root object, and schemasTonObject- Represents an object with properties and child objectsTonValue- Represents a typed value with conversion methodsTonParser- Parses TON content from various sourcesTonSerializer- Serializes TON objects to string formatTonFormatter- Formats existing TON content with different stylesTonValidator- Validates TON documents against schemas
Key Interfaces
ITonValue- Interface for TON valuesITonSerializable- Interface for serializable TON elements
Enumerations
TonValueType- Types of TON values (String, Integer, Float, Boolean, etc.)TonTokenType- Token types used by the lexerTonValidationRuleType- Types of validation rulesTonFormatStyle- Formatting styles (Compact, Pretty)
Requirements
- .NET Standard 2.1 or later
- Compatible with .NET Core 3.0+, .NET 5+, .NET 6+, .NET 7+, .NET 8+, .NET 9+
License
MIT License - Copyright © 2024 DevPossible, LLC
Support
DevPossible, LLC
Website: devpossible.com
Email: support@devpossible.com
TON Specification: tonspec.com
© 2024 DevPossible, LLC. All rights reserved.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.