Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

generating C# classes from XSD with Custom Attributes..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parez - 03 Mar 2008 16:53 GMT
Hi All

I am trying to generate classes from XSD which looks like this

namespace WindowsFormsApplication1.Something.Some
{
   public class Address
   {

       public Address()
       {
       }

       [FormMapper("TextBox2")]

       public string StreetAddress { get; set; }
       [FormMapper("TextBox3")]
       public string UnitNumber { get; set; }
       [FormMapper("TextBox4")]
       public string City { get; set; }
       [FormMapper("TextBox5")]
       public string State { get; set; }
       [FormMapper("TextBox6")]
       public string zip { get; set; }

   }
}

How do i represent the FormMapper Attribute in the xsd.

Please Help and thanks
parez - 03 Mar 2008 19:29 GMT
> Hi All
>
[quoted text clipped - 28 lines]
>
> Please Help and thanks

Where are the C# Jedis?
Jon Skeet [C# MVP] - 03 Mar 2008 19:36 GMT
<snip>

> Where are the C# Jedis?

Perhaps if you gave more information in your question - like how your
code currently works - you'd be more likely to get an answer.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

parez - 03 Mar 2008 20:03 GMT
> <snip>
>
[quoted text clipped - 6 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

I dont have  currently working code. I have been recommended to  use
XSD.exe to generate the code instead of typing it in.

The auto generated code should have custom attributes (in my example
it its FormMapper)

public class Address
   {

       public Address()
       {
       }

       [FormMapper("TextBox2")]

       public string StreetAddress { get; set; }
       [FormMapper("TextBox3")]
       public string UnitNumber { get; set; }
       [FormMapper("TextBox4")]
       public string City { get; set; }
       [FormMapper("TextBox5")]
       public string State { get; set; }
       [FormMapper("TextBox6")]
       public string zip { get; set; }

   }

What I am trying to do is.
I have to send XML requests to the server based on the events on my
winform applications. They could add/update/get requests. I will have
70-80 different requests types and hence 70-80 XSDs  (or Classes) to
maintain.
I am planning to use reflection to populate fields on the winforms
using the FormMapper attribute.But that may not be the only reason why
i need custom attributes. I mite also need to get someinfo about the
fields(like readonly, enabled ) etc from the server.

TIA
Marc Gravell - 04 Mar 2008 08:04 GMT
The problem is that xsd (either the format or the exe) isn't going to be in
the least bit interested in your attribute. Of couse, having your object
model dictate the UI also might not be the best idea... personally I'd
separate the two concepts completely, perhaps using xml generation if (and
only if) it made sense.

Marc
parez - 04 Mar 2008 20:52 GMT
> The problem is that xsd (either the format or the exe) isn't going to be in
> the least bit interested in your attribute. Of couse, having your object
[quoted text clipped - 3 lines]
>
> Marc

Hi Marc,

I finally have a custom code generator which geneerates the
Attributes...
I am using the XSD to create classes because the server is going to
use the same XSD to process my request.
My classes are not part of the business tier. They are a part of the
presentation layer(well.. its sits between the winforms and Server).
I am planning to use reflection to populate the form fields.Thats why
I am using the FormMapper Attribute.
sloan - 03 Mar 2008 20:24 GMT
Maybe this can help:

http://www.jondavis.net/blog/post/2007/05/XML-to-C-Code-Generation.aspx

I'm not sure..but check it out.

> Hi All
>
[quoted text clipped - 27 lines]
>
> Please Help and thanks
parez - 03 Mar 2008 21:20 GMT
> Maybe this can help:
>
[quoted text clipped - 33 lines]
>
> > Please Help and thanks

Thanks..That is the direction I mite have to go in..

I found more info here

http://msdn2.microsoft.com/en-us/library/aa302301.aspx

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.