FieldSpecified with nullable and PascalCase changes

May 18, 2011 at 2:49 PM

I implemented a few changes to the branched version (3.5) of Xsd2Code to address a few issues for us:

1. I hate the FieldNameSpecified thing in the classes. For nullable types it really shouldn't be necessary. So, I generate this for nullables:

public bool FieldNameSpecified {
     get {
           return FieldName.HasValue;

Now, you can set your field to null and not worry about setting the "specified" boolean.

2. Some value types were generating code in the setter checking for nulls (e.g. decimal type). It compiles but FX cop gets upset.

3. Our xsds get generated by a java server and everything in the xsd is lowercase. I have modified xsd2code to generate code that conforms to c# code conventions (i.e. upper case property & class names).

If anyone is interested, these are the changes.

May 20, 2011 at 1:23 AM

Sounds interesting! Though the link provided is broken?

May 20, 2011 at 7:10 AM

Good work !

I can move your code into the next release (3.6). Your link is broken. you can send me your zip file at

Thank you.

May 20, 2011 at 8:25 AM

Apologies, I will put it back up later today (I can't access the server from work and I can't seem to be able to attach anything on this forum...).

pcabanel - I doubt you'll want to put it into your release, the code needs a bit of refactoring.

e.g. I just addressed an issue where xs:integer types are converted to strings in the .NET code ( because there was no such thing as a BigInteger in .NET.  "The xs:integer type is specified as a number with no upper or lower bound on its size. For this reason, neither XML serialization nor validation map it to the System.Int32 type". I addressed this problem directly in CodeExtension.cs, but my guess is that you would want to refactor this out into a Net40Extension.cs (as the BigInteger is in System.Numerics in .NET 4).

My plan is to fix these kind of refactoring issues but I have a project to press on with and so far I have just got it going good enough for me.

Either way, I'll post the code later and you can run a diff on it to see what i've been hacking about with.