Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricardoboss/dartlang.pubspec
A library to read/write Dart pubspec.yaml files
https://github.com/ricardoboss/dartlang.pubspec
dart deserialization dotnet pubspec pubspec-yaml serialization
Last synced: about 2 months ago
JSON representation
A library to read/write Dart pubspec.yaml files
- Host: GitHub
- URL: https://github.com/ricardoboss/dartlang.pubspec
- Owner: ricardoboss
- License: mit
- Created: 2024-06-01T13:02:42.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-07T15:01:18.000Z (about 2 months ago)
- Last Synced: 2024-11-07T15:16:05.873Z (about 2 months ago)
- Topics: dart, deserialization, dotnet, pubspec, pubspec-yaml, serialization
- Language: C#
- Homepage: https://nuget.org/packages/DartLang.PubSpec
- Size: 99.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# DartLang.PubSpec
A library to serialize and deserialize Dart pubspec.yaml files.
## Usage
```csharp
var yaml = File.ReadAllText("pubspec.yaml");
var pubspec = PubSpecYamlSerializer.Deserialize(yaml);Console.WriteLine($"Name: {pubspec.Name}");
Console.WriteLine($"Version: {pubspec.Version}");
```You can also use the JSON serializer:
```csharp
var json = File.ReadAllText("pubspec.json");
var pubspec = PubSpecJsonSerializer.Deserialize(json);
```### Custom Deserializer
#### YAML
You can also build your own deserializer using [`YamlDotNet`] directly:
```csharp
var deserializer = new DeserializerBuilder()
.IgnoreUnmatchedProperties() // pub.dev will ignore other properties
.WithNamingConvention(UnderscoredNamingConvention.Instance) // dart uses underscores for properties
.WithPubSpecConverters() // converters for custom types
.Build();return deserializer.Deserialize(reader);
```#### JSON
In case you need to use custom `JsonSerializerOptions`, you can reuse the converters from `DartLang.PubSpec.Serialization.Json`:
```csharp
var json = File.ReadAllText("pubspec.json");
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters =
{
new SemVersionJsonConverter(),
new SemVersionRangeJsonConverter(),
new DependencyMapJsonConverter(),
new PlatformsJsonConverter(),
},
};return JsonSerializer.Deserialize(json, options);
```### Serialization
Serialization is currently not supported, but should not be hard to implement yourself.
## License
MIT
[`YamlDotNet`]: https://github.com/aaubry/YamlDotNet