Skip to content

POCO2TS default options

zijianhuang edited this page Apr 8, 2017 · 4 revisions

While by default POCO2TS will do cherry picking according to DataContractAttribute and DataMemberAttribute, it supports other options of development processes.

When you run the program without any argument, you will get a simple help screen.

Poco2Ts.exe generates TypeScript data model interfaces from POCO classes.
Example:
For classes decorated by DataContractAttribute:
  Fonlow.Poco2Ts.exe MyAssemblyWithPOCO.dll MyOutputTS.ts
For classes decorated by Newtonsoft.Json.JsonObjectAttribute:
  Fonlow.Poco2Ts.exe MyAssemblyWithPOCO.dll MyOutputTS.ts /2
For classes decorated by SerializableAttribute:
  Fonlow.Poco2Ts.exe MyAssemblyWithPOCO.dll MyOutputTS.ts /4
For public classes, properties and properties,  and use System.ComponentModel.DataAnnotations.RequiredAttribute:
  Fonlow.Poco2Ts.exe MyAssemblyWithPOCO.dll MyOutputTS.ts /8
For all classes, properties and fields
  Fonlow.Poco2Ts.exe MyAssemblyWithPOCO.dll MyOutputTS.ts /0

And the options could be described by this enum type:

    /// <summary>
    /// Flagged options for cherry picking in various development processes.
    /// </summary>
    [Flags](Flags)
    public enum CherryPickingMethods
    {
        /// <summary>
        /// Include all public classes, properties and properties.
        /// </summary>
        All = 0,

        /// <summary>
        /// Include all public classes decorated by DataContractAttribute, and public properties or fields decorated by DataMemberAttribute. 
        /// And use DataMemberAttribute.IsRequired
        /// </summary>
        DataContract =1,

        /// <summary>
        /// Include all public classes decorated by JsonObjectAttribute, and public properties or fields decorated by JsonPropertyAttribute.  
        /// And use JsonPropertyAttribute.Required
        /// </summary>
        NewtonsoftJson = 2,

        /// <summary>
        /// Include all public classes decorated by SerializableAttribute, and all public properties or fields but excluding those decorated by NonSerializedAttribute.
        /// And use System.ComponentModel.DataAnnotations.RequiredAttribute.
        /// </summary>
        Serializable = 4,

        /// <summary>
        /// Include all public classes, properties and properties. 
        /// And use System.ComponentModel.DataAnnotations.RequiredAttribute.
        /// </summary>
        AspNet = 8,
    }

DataContract is the default option in POCO2TS.

So if you somehow have some classes decorated by DataContractAttribute and others by JsonObjectAttribute, and you want to include both sets, then the option is /3. And DataMemberAttribute and JsonPropertyAttribute will be handled accordingly.

Remarks

While POCO2TS.exe can handle Newtonsoft.Json attributes, it does not have static binding with Newtonsoft.Json. It is your data model assembly has binding with Newtonsoft.Json.dll. When you use the NewtonsoftJson option, .NET runtime will try to locate it. If the runtime fails to locate it, POCO2TS will resolve through checking the folder where the data model assembly is located. This resolution is also useful when your data model assembly has dependency on the other data model assembly.

Clone this wiki locally