I'm creating a restfull application that uses the Newtonsoft library to send information through controllers . In my application, I have numerous classes like for example the user:
public class UsuarioModel
{
public int Id { get; set; }
public string Login { get; set; }
public string Senha { get; set; }
public string Email { get; set; }
public bool Visivel { get; set; }
public DateTime? CriadoEm { get; set; }
public DateTime? AtualizadoEm { get; set; }
}
In order to not send null
or default
properties I want to override the static property method within the JObject.FromObject
class like this:
public class JObject
{
public static JObject FromObject(object o)
{
return FromObject(o, new JsonSerializer()
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
});
}
}
The intention to do this is that I can write less code and standardize the entire application to always use this setting when calling the method.
The problem is that (as far as I know) it can not do a override
of a static method within an extension class .
What should I do to implement this method?