EDN Admin
Well-known member
Hello
We have a requirement to create C# class library from XSD. The properties of generated C# file should be decorated with custom attribute. Im exploring XSD.exe and other options to get this done. Please see by my input XSD file and expected output:
Input XSD File
<pre lang="x-xml <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema
<xs:element name="Customer" nillable="true" type="Customer" />
<xs:complexType name="Customer
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="LastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
[/code]
I want the output c# file to like this. See the custom attributes in bold/underlined. I want to know if the items in red can be generated using any techniques. Sincerely appreciate your feedback
Expected c# Output
<pre lang="x-c# using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using LTS.RuleEngine.Common;// This should be auto generated
namespace Customer
{
public class Customer:INotifyPropertyChanged
{
private string firstname;
private string lastname;
[TaxField("FirstName")]// This should be auto generated
public string FirstName
{
get { return this.firstname; }
set
{
this.firstname = value;
NotifyPropertyChanged("FirstName");
}
}
[TaxField("LastName")] // This should be auto generated
public string LastName
{
get { return this.lastname; }
set
{
this.lastname = value;
NotifyPropertyChanged("LastName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
[/code]
<div style="color:black; background-color:white Im able to generate the code to implement the INotifyPropertyChanged using XSD.exe switch, However, unable to add the custom attribute
<span style="text-decoration:underline [TaxField("propertyname")] .
Please let me know how this can be automated. Sincerely appreciate your help
View the full article
We have a requirement to create C# class library from XSD. The properties of generated C# file should be decorated with custom attribute. Im exploring XSD.exe and other options to get this done. Please see by my input XSD file and expected output:
Input XSD File
<pre lang="x-xml <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema
<xs:element name="Customer" nillable="true" type="Customer" />
<xs:complexType name="Customer
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="LastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
[/code]
I want the output c# file to like this. See the custom attributes in bold/underlined. I want to know if the items in red can be generated using any techniques. Sincerely appreciate your feedback
Expected c# Output
<pre lang="x-c# using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using LTS.RuleEngine.Common;// This should be auto generated
namespace Customer
{
public class Customer:INotifyPropertyChanged
{
private string firstname;
private string lastname;
[TaxField("FirstName")]// This should be auto generated
public string FirstName
{
get { return this.firstname; }
set
{
this.firstname = value;
NotifyPropertyChanged("FirstName");
}
}
[TaxField("LastName")] // This should be auto generated
public string LastName
{
get { return this.lastname; }
set
{
this.lastname = value;
NotifyPropertyChanged("LastName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
[/code]
<div style="color:black; background-color:white Im able to generate the code to implement the INotifyPropertyChanged using XSD.exe switch, However, unable to add the custom attribute
<span style="text-decoration:underline [TaxField("propertyname")] .
Please let me know how this can be automated. Sincerely appreciate your help
View the full article