Custom C# code generation from XSD RRS feed

  • Question

  • Hello

    We have a requirement to create C# class library from XSD. The properties of generated C# file should be decorated with custom attribute. I'm exploring XSD.exe and other options to get this done. Please see by my input XSD file and expected output:

    Input XSD File

    <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:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
    <xs:element minOccurs="0" maxOccurs="1" name="LastName" type="xs:string" />

    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 

    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; }
    this.firstname = value;
    [TaxField("LastName")] // This should be auto generated
    public string LastName
    get { return this.lastname; }
    this.lastname = value;
    public event PropertyChangedEventHandler PropertyChanged;
    I'm able to generate the code to implement the INotifyPropertyChanged using XSD.exe switch, However, unable to add the custom attribute [TaxField("propertyname")] . Please let me know how this can be automated. Sincerely appreciate your help


    • Edited by arasheed Tuesday, December 14, 2010 6:55 PM Formated
    Tuesday, December 14, 2010 6:49 PM


All replies