deniszykov / msgpack-unity3d

MessagePack and JSON serializer for Unity3D
MIT License
102 stars 14 forks source link

Ignore Getters #12

Open koprivajakub opened 7 years ago

koprivajakub commented 7 years ago

Hi, is possible to add flag which would ignore all getters in the class?

I have class:

    /// <summary>
    /// DTO class which is used to login a player via HTTP request to OAuth server (Lonely Backend).
    /// </summary>
    public class PlayerLoginRequestDTO : AbstractRequestDTO
    {
        /// <summary>
        /// Grant type for the OAuth server
        /// </summary>
        public readonly string grant_type;

        /// <summary>
        /// Login name of the user / player
        /// </summary>
        public readonly string username;

        /// <summary>
        /// Password in plain text of the user / player
        /// </summary>
        public readonly string password;

        /// <summary>
        /// Constructor creates a player login DTO which is serialized to JSON before the HTTP request is send.
        /// </summary>
        /// <param name="username">Login name of the user / player</param>
        /// <param name="password">Password in plain text of the user / player</param>
        /// <param name="grantType">The type of the credentials used. Currently supported only "password"</param>
        public PlayerLoginRequestDTO(string username, string password, string grantType)
        {
            this.username = username;
            this.grant_type = grantType;
            this.password = password;
        }

        /// <summary>
        /// Grant type for the OAuth server
        /// </summary>
        public string GrantType
        {
            get { return grant_type; }
        }

        /// <summary>
        /// Login name of the user / player
        /// </summary>
        public string Username
        {
            get { return username; }
        }

        /// <summary>
        /// Password in plain text of the user / player
        /// </summary>
        public string Password
        {
            get { return password; }
        }
    }

Which resutl in json:

{
  "grant_type": "passwod",
  "username": "uname",
  "password": "pass",
  "GrantType": "password",
  "Username": "uname",
  "Password": "pass"
}
deniszykov commented 7 years ago

Hi! You can hide Properties by making them private or marking with IgnoreDataMember attribute. As alternative you can refactor them as GetXXX methods,