generating C# classes from XSD with Custom Attributes..

P

parez

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
 
P

parez

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

Where are the C# Jedis?
 
J

Jon Skeet [C# MVP]

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.
 
P

parez

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

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
 
P

parez

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.


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

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
 
M

Marc Gravell

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
 
P

parez

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

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.
 
R

Rasheed Abdul

Hello:

Can you please share the final approach? I have a similar requirement and tired of googling:(

Thanks
Rasheed
<snip>


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

--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
On Wednesday, March 05, 2008 5:04 AM parez wrote:
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
On Wednesday, March 05, 2008 5:04 AM parez wrote:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top