Introduction
The code generation parameters are accessible from the xsd2code interface. They are in the form of a PropertyGrid. All parameters are available through this interface.
Changing a value automatically triggers code generation. This option can be disabled if required:
If you want to generate your code using a command script, it is possible to automatically retrieve the parameters in the Command Line property.
Language
Determines the language to be used to generate the code. CSharp or VB.
NameSpace
Allows you to specify the NameSpace.
TargetFramework
The target framework must match the one of your project. xsd2code++ detects it on the first call. You can then change it if your project changes too. However this option allows xsd2code++ to enable or disable options depending on the target framework. For example with TargetFramework 2.0 which could be used to maintain an old application for example, the automatic properties will not be available.
Framework 2.0 | Framework 3.x to 4.x & .Net5 | |
---|---|---|
Automatic properties | ||
WCF Attributes | ||
JSon attributes | ||
INotifyPropertyChanged |
ExcludeImportedType
This setting allows you to ignore all elements from an imported schema. Only complex or simple elements from the schema itself will be taken into account. Otherwise, and by default the schema parser will browse all the included or imported schemas. When you want to generate all the classes of a schema set, you just have to generate the code from the root schema.
The schema below (PurchaseOrder.xsd) contains an imported schema (Product.xsd). The schema Product.xsd contains the definition of the Product element.
The target framework must match the one of your project.
In case the schemas are externalized (URL) they will be automatically downloaded and analyzed by the parser.
ExpandNestedAttributeGroup
GenerateUnusedComplexType
This option forces the generator to include the classes and properties of orphan complex elements. That is to say those which are not attached to the root element.
In the sample below, the complex type Product is never used in the root element tree. It is an "orphan" complex type in the sense that it is not used. By default xsd2code++ ignores it. It is therefore possible to force the generator to integrate them.
Here is the code generated by default, i.e. with the option GenerateUnusedComplexType=false
Here is the code generated with the option GenerateUnusedComplexType=true
GenerateUnusedSimpleType
This option is used to generate the classes and properties of single orphan elements. I.e. those which are not attached to the root element. This is the same principle as the GenerateUnusedComplexType option.
CustomUsing
The custom using parameter allows you to add additional directives.
GenerateCloneMethod
This parameter makes it possible to generate in each class a Clone() method allowing the cloning of an instance.
public virtual PurchaseOrderType Clone() { return ((PurchaseOrderType)(MemberwiseClone())); }
InitializeFields
This parameter définit la manière dont les object sont initialisés.
InitializeFields.All (Default)
Adds a constructor to your classes including the creation of instances of complex objects or collections.
InitializeFields.AllExceptOptional
If in your schema an element is marked as optional, the instance of this element will not be included in the constructor. An optional element is considered optional when it has a minOccurs="0". In the example below, the BillTo element is considered as an option because the minimum occurrence is 0.
<xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="ShipTo" type="USAddress" maxOccurs="unbounded"/> <xsd:element name="BillTo" type="USAddress" minOccurs="0" /> <xsd:element name="OrderDate" type="xsd:string" /> </xsd:sequence> </xsd:complexType>
InitializeFields.None
No object instance will be created.
Miscellaneous
CacheExternalSchames
When your XSD schema contains schemas imported from URL, xsd2code++ automatically downloads them so that it can analyze them and generate the corresponding classes. To optimize response time, it is possible to place the schemas in a local cache. The cache is physically located on your hard drive at the following folder.
%appdata%\xsd2code\
CleanupCode
This parameter is used to clean up the code and minify it. This allows you to reduce any namespace in particular.
For example,
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.google.com/schemas/sitemap-news/0.9")] [System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.google.com/schemas/sitemap-news/0.9", IsNullable=false)] public partial class news { ... }
Becomes
[GeneratedCode("System.Xml", "4.8.3752.0")] [Serializable] [DebuggerStepThrough] [DesignerCategory("code")] [XmlType(AnonymousType=true, Namespace="http://www.google.com/schemas/sitemap-news/0.9")] [XmlRoot(Namespace="http://www.google.com/schemas/sitemap-news/0.9", IsNullable=false)] public partial class news { ... }
EnableDebug
By default the generated classes are decorated with the [DebuggerStepThrough] attribute which prevents the debugger from entering into the generated code. However, if you want to disable this option, set EnableDebug to true.
EnableSummaryComment
This option allows you to retrieve element annotations for xsd schemas or description for JSon schemas into genrated code :
<xsd:element name="name" type="xsd:string" > <xsd:annotation> <xsd:documentation> Name of the customer that will be used for invoicing. </xsd:documentation> </xsd:annotation> </xsd:element>
/// <summary> /// Name of the customer that will be used for invoicing. /// </summary> public string name { ... }
EnableWarning
By default the generated classes include the #pragma warning disable directive to avoid generating warnings when compiling your project.
HidePrivateIntelliSense
This option adds on all private members the attribute EditorBrowsable(EditorBrowsableState.Never)] which avoids listing them in IntelliSense of the Visual Studio Code Editor.