-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to serialize again? #19
Comments
I'll address each part of your question separately:
Ideally it would. However, this is a fairly complex feature and serialization is generally a less common use case than deserialization. So it hasn't been implemented so far. However, it's a planned feature for the long term. In addition, there's the hacky solution as shown in part 3.
In short, a Since VDF files always have a VObject rootValue = new VObject();
rootValue.Add("hello", new VValue("world"));
rootValue.Add("hello2", new VValue("world2"));
Console.WriteLine(VdfConvert.Serialize(new VProperty("RootName", rootValue)));
// Prints:
// "RootName"
// {
// "hello" "world"
// "hello2" "world2"
// }
Yes, using the Mount someMount = new Mount { Hello = "world", Hello2 = "world2" };
VObject rootValue = JObject.FromObject(someMount).ToVdf();
Console.WriteLine(VdfConvert.Serialize(new VProperty("RootName", rootValue)));
// Prints the same output as above. This solution is a little simpler in that you can use models again, however, it requires an intermediate conversion to |
How about a list? |
VDF doesn't support lists. The |
I strongly suggest you read how Json.NET works and how to obtain |
This stuff is becoming increasingly more difficult. I already hated documents, elements and nodes from C#'s XML crap. Just to make this clear in my head now, are you saying that it's impossible to get the VDF file representation from a seemingly "random" class? Or are you just not willing to show the steps needed because it gets too complicated? Don't get my wrong, i appreciate all the effort in making a lib that helps with this but i'm just used of the simplicity of throwing literally anything at the JSONparser and it just spits out the result. not more than one line required I'm so glad there are smart people on the C# discord that help with more generic problems :3 |
There may exist some single-line way to get the VDF representation of a generic object, but I don't know it. If it does exist, you'll find it by learning more about the I'm saying that I can only provide you with the resources to help you do what you want. I can't write your code for you.
I'm confident there doesn't exist any library to do this for you. You'll either have to write it yourself or understand how to use an existing library. |
Damn, that's too sad. I'll probably try to hack something together with a stringbuilder until a usable way is found, thanks |
I'm closing this issue for now since adding support for serializing generic objects is not a planned feature. One alternative I've since learned is to obtain a |
i have a
public List<Mount> Mounts { get; set; }
and i want to write that back to a vdf file, how would i do that? i believe it's something withVdfConvert.Serialize()
but that requires a VToken, how do i get that?The text was updated successfully, but these errors were encountered: