ra0o0f / arangoclient.net

ArangoDB .NET Client with LINQ support
Apache License 2.0
99 stars 37 forks source link

Support private setter #129

Open endeffects opened 5 years ago

endeffects commented 5 years ago

I need to deserialize a document into a domain type where the properties have only private setters and no constructor is available.

In your implementation you don't allow to override the DefaultContractResolver because you recreate it each time the db connection is used, so i'm not able to resolve this by my own without creating new models.

So would you please allow overriding the DefaultContractResolver or add the following workaround to the current implementation?

Pull request: https://github.com/ra0o0f/arangoclient.net/pull/130

    public class NonPublicPropertiesResolver : DefaultContractResolver
    {
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var prop = base.CreateProperty(member, memberSerialization);
            if (!(member is PropertyInfo pi)) { return prop; }

            prop.Readable = (pi.GetMethod != null);
            prop.Writable = (pi.SetMethod != null);

            return prop;
        }
    }