moh-hassan/odata2poco

Not Null Members

darinvanatta opened this issue · 8 comments

Hi,

Currently members that cannot be null have the "not null" comment beside them:

image

I have to programatically determine not nulls members to ensure my users enter a value for them but I don't see a way to do it with the comment.

Could a "[Not Null]" annotation or something similar be added that could be used to programatically determine if a member cannot be null?

Thanks

It appears there is a "JsonPropertyAttribute required" which might be a good option

image

Here's a good explanation of adding custom attributes and then verifying them with reflection:

https://www.c-sharpcorner.com/article/creating-and-using-custom-attributes-in-C-Sharp/

You can add the required attribute: [Required] by the option:

            -a req

There are 8 attributes you can add by the option -a

              -a, --attribute     Attributes, Allowed values: key, req,  json, tab, dm, proto, db, display        

Try it and let me if it achieve what you want.

Perfect! I should have known you had already thought of everything.

Thanks and Welcome.

There is option that add '?' to the type for nullable data type:

         -b, --nullable      Add nullable data types

Which can generate for nullable data types:

            public double? Price {get;set;}

This option help for programmatically determine nullable members

Very cool! Thanks