quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

C# add support for more attributes

Open crfroehlich opened this issue 6 years ago • 0 comments

It would be a great time saver if users could select exactly which attributes they want to apply to the class members. For example:

using AM = ServiceStack.ApiMemberAttribute;
using DC = System.Runtime.Serialization.DataContractAttribute;
using DM = System.Runtime.Serialization.DataMemberAttribute;
using DV = System.ComponentModel.DefaultValueAttribute;
using DVH = Newtonsoft.Json.DefaultValueHandling;
using JP = Newtonsoft.Json.JsonPropertyAttribute;
using NVH = Newtonsoft.Json.NullValueHandling;
using R = ServiceStack.RouteAttribute;

namespace Typed.Settings
{
    [DC]
    public class Features
    {
        private const string enable_impersonation = "enable-impersonation";
        [DM(Name = enable_impersonation, EmitDefaultValue = true), DV(false), AM(Name = enable_impersonation), JP(enable_impersonation, DefaultValueHandling = DVH.Populate, NullValueHandling = NVH.Include)]
        public bool EnableImpersonation { get; set; }

        private const string enable_audit = "enable-audit";
        [DM(Name = enable_audit, EmitDefaultValue = true), DV(true), AM(Name = enable_audit), JP(enable_audit, DefaultValueHandling = DVH.Populate, NullValueHandling = NVH.Include)]
        public bool EnableAudit { get; set; }

        private const string enable_caching = "enable-caching";
        [DM(Name = enable_caching, EmitDefaultValue = true), DV(true), AM(Name = enable_caching), JP(enable_caching, DefaultValueHandling = DVH.Populate, NullValueHandling = NVH.Include)]
        public bool EnableCaching { get; set; }
    }
}
  • Pulling the member name out into a constant allows easily refactoring the members: private const string enable_impersonation = "enable-impersonation"
  • Options to include any or all of the ServiceStack, NewtonSoft, System.Runtime.Serialization and System.ComponentModel (and I'm sure there are others) would greatly speed up the conversion and reduce refactoring time when putting the code into place

crfroehlich avatar Jun 20 '19 13:06 crfroehlich