SamboyCoding / Tomlet

Zero-Dependency, model-based TOML De/Serializer for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: How to Ignore specific properties? Or Opt-In/Opt-Out?

gismofx opened this issue · comments

I would like to skip properties from being written to file. Is there an "opt-in" or "opt-out" attribute or a way to skip them when writing to file?

I have a private variable in my class that is getting written out to file and causing some issues e.g.:
private string _SettingsFilePath;

I'm writing like so:

using (var writer = new System.IO.StreamWriter(_SettingsFilePath))
            {
                writer.Write(TomletMain.TomlStringFrom(settingsClass));
            }

The built-in system NonSerialized attribute allows you to opt out on a per-field or per-property basis. This is detailed in the readme.

The built-in system NonSerialized attribute allows you to opt out on a per-field or per-property basis. This is detailed in the readme.

Thanks! I may suggest adding some keywords to the readme. Would you accept a PR on the readme in the section regarding this?

Also:
[NonSerialized] works on variables, but not properties..

e.g.

        [NonSerialized] //works 
        private string SettingsFilePath;

        [NonSerialized] //CS0592 Error
        public int MyProperty { get; set; }  

Would you be open to adding a new attribute into your library? Something like "[TomlNonSerialized]"

Oh that's just silly. Why microsoft, why. If you want to PR both the readme and attribute at once, I'll take it, but generally speaking if it's a documentation-only change I'd rather just do it myself.

I can do both at once... Will take me a little while to get to dig into the attributes...Maybe by end of the week. Thanks for the quick replies!