SamboyCoding / Tomlet

Zero-Dependency, model-based TOML De/Serializer for .NET
MIT License
155 stars 29 forks source link

Attribute mapping added #13

Closed Wulfheart closed 2 years ago

Wulfheart commented 2 years ago

Hello, I wanted to map specific properties. For example a name = "Something" should be mapped to public string Name. This can be achieved like this:

[user]
name = "User1"
password = "PW"
using Tomlet;
public class Config
{
    [TomlProperty("user")]
    public User User { get; set; }
}

public class User
{
    [TomlProperty("name")]
    public string Name { get; set; }
    [TomlProperty("password")]
    public string Password { get; set; }
} 

Currently I made it available under https://www.nuget.org/packages/Wulfheart.Tomlet/2.1.0 until it gets eventually merged.

SamboyCoding commented 2 years ago

Looks good, the only question I would have is if you could possibly add some unit tests to validate this behaviour? Then I will gladly merge this.

SamboyCoding commented 2 years ago

Actually, ignore that, the test failed, you need to use FirstOrDefault instead of First

Wulfheart commented 2 years ago

Thanks for your comments.

How can I run the tests locally with the CLI or Rider? Anywhere to look?

SamboyCoding commented 2 years ago

Rider should pick up the tests automatically, if you go to the Unit Tests tool window (View -> Tool Windows -> Unit Tests). Alternatively, the command is dotnet test from the solution folder

Wulfheart commented 2 years ago

@SamboyCoding Added tests and serialization also works now.

SamboyCoding commented 2 years ago

The build is failing because the resx file hasn't been recompiled, but I'll trust you if you say it works now, and the changes look like they make sense, I'll merge this in a bit and recompile the resx myself, then push to nuget.

Wulfheart commented 2 years ago

image

😉

Thank you! I'm looking forward to it.

Wulfheart commented 2 years ago

Thanks for merging. Is there already a release on Nuget?

SamboyCoding commented 2 years ago

Not yet, but I'm working on it now. Got one issue to fix then I'll publish and update you here

SamboyCoding commented 2 years ago

@Wulfheart The build is now validating on nuget - I anticipate it becoming available within 5-10 minutes.