tags:

views:

267

answers:

2

I'm using xsd.exe to make the C# classes for our settings. I have a setting that is per-server and per-database, so I want the class to behave like Dictionary<string, string[][]>. So I want to be able to say

string serverName = "myServer";
int databaseId = 1;
FieldSettings fieldSettings = getFieldSettings();

string[] fields = fieldSettings[serverName][databaseId];

how do I represent that in XSD?

+1  A: 

This not what xsd is used for. You can always just add your own indexer to a partial class, and mark it with [XmlIgnore]

leppie
+2  A: 

xsd defines the data structure, not really the access approach. I don't think you can express "this is a lookup" in xsd : everything is either values or set of values/entities.

If you want specific handling, you might consider custom serialization - or alternatively consider your DTOs and your working classes as separate things, and simply translate between the two.

[edit] As leppie notes - you can write your own indexer (typically in a partial class if generating cs from the xsd) that loops over the list to find the item: this will give you the caller usage, but not really the full dictionary experience (uniqueness, O(1) retrieval, etc)

Marc Gravell
+1 for not capitalizing my nick! :)
leppie
@leppie - I've found [Ctrl]+C, [Ctrl]+V saves a lot of offence. You'd be amazed how many people keep "correcting" me to Mark.
Marc Gravell