David C# is probably the quick solution. These classes, generated by XSD or XDS2Code (much nicer, as an add-in with lots of control), will be hand-tuned and then can be compiled to a DLL - so the VB people can use that. The application it will be used in was originally (2004 to 2007) written in VB.NET with framework 2.0 - I had forgotten the rehashed version of the application will be written in C# anyway. The XSD schemas are set in stone (and include many includes) - ISO FGDC ANZLIC etc - so we leave the xml alone. Generated classes for the UI / data maintenance have more flexibility.
Thanks - you got me over that mental block. (and it would be clumsy to code that in VB) ________________________________ Ian Thomas Victoria Park, Western Australia -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of David Richards Sent: Monday, August 06, 2012 6:51 AM To: ozDotNet Subject: Re: Enum problem - case-sensitivity Ian, I just got into the office and confirmed the enumeration would work in c#. eg: enum blah {y, Y, n, N} is fine. I just realised the reference to a default enumeration value was a separate question, sorry. I'm not aware of this option being available in xml but the first value in an enumeration is, unless specified otherwise, set to 0. So you could possibly include "Unknown" or "NotSet" as your first value. The result would be: enum blah { Unknown, y, Y, n, N } I'm assuming I understood your question correctly :) David "If we can hit that bullseye, the rest of the dominoes will fall like a house of cards... checkmate!" -Zapp Brannigan, Futurama On 6 August 2012 07:13, David Richards <[email protected]> wrote: > Ian, use c#. At least for the classes being generated from the schema. I'm > not in a position to confirm this but I would think the enum is fine in c# > since its case sensitive. > > I'm not sure how the default value reference is relevant to this issue. > > On Aug 6, 2012 3:58 AM, "Ian Thomas" <[email protected]> wrote: >> >> I have a problem that arose when generating code from xml schema (XSD >> files) using a tool XSD2Code (Codeplex - like xsd.exe), where the xml >> fragment is - >> >> >> >> <xs:element name="casesens"> >> >> <xs:simpleType> >> >> <xs:restriction base="xs:string"> >> >> <xs:enumeration value="y"/> >> >> <xs:enumeration value="Y"/> >> >> <xs:enumeration value="n"/> >> >> <xs:enumeration value="N"/> >> >> </xs:restriction> >> >> </xs:simpleType> >> >> </xs:element> >> >> >> >> The code that is generated (ignore its ugliness and verbosity) is - >> >> Public Enum metadataDistinfoStdorderDigformDigtinfoAsciistrCasesens >> >> >> >> '''<remarks/> >> >> y >> >> >> >> '''<remarks/> >> >> Y >> >> >> >> '''<remarks/> >> >> n >> >> >> >> '''<remarks/> >> >> N >> >> End Enum >> >> >> >> which causes errors in VS2010 because N and Y are generated twice in this >> enum. >> >> Of course, the code generator inter-relates partial class, field, >> property, and this enum - and the element casesens is an essential part of >> the schema. >> >> The Microsoft tool XSD.EXE generates much the same code - >> >> '''<remarks/> >> >> <System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1"), _ >> >> System.SerializableAttribute(), _ >> >> System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true, >> [Namespace]:="http://pc158.nc.fs.fed.us/nbii_std")> _ >> >> Public Enum metadataDistinfoStdorderDigformDigtinfoAsciistrCasesens >> >> '''<remarks/> >> >> y >> >> '''<remarks/> >> >> Y >> >> '''<remarks/> >> >> n >> >> '''<remarks/> >> >> N >> >> End Enum >> >> >> >> - and of course causes the same error. Any suggestions how I can get >> around this? >> >> MSDN suggests as a part of enumeration best practices: >> >> If there is an obvious default case that your application has to >> represent, consider using an enumerated constant whose value is zero to >> represent it. If there is no default case, consider using an enumerated >> constant whose value is zero to specify the case that is not represented by >> any of the other enumerated constants. >> >> How would I implement that suggestion? >> >> ________________________________ >> >> Ian Thomas >> Victoria Park, Western Australia
