I'm using CodeDom to build smart classes from an XSD file. To do that I create I do the following
XmlSchemaImporter schemaImporter = new XmlSchemaImporter(xsds);
CodeNamespace codeNamespace = new CodeNamespace(settings.Nmspace);
// export the code inside the namespace
XmlCodeExporter codeExporter = new XmlCodeExporter(codeNamespace, null, CodeGenerationOptions.GenerateProperties);
// load objects fromm the XSD
var maps = new List<XmlTypeMapping>();
foreach (XmlSchema schema in xsds)
{
if (settings.UseTypes)
{
foreach (XmlSchemaType schemaT in schema.SchemaTypes.Values)
maps.Add(schemaImporter.ImportSchemaType(schemaT.QualifiedName));
}
if (settings.UseElements)
{
foreach (XmlSchemaElement schemaT in schema.Elements.Values)
maps.Add(schemaImporter.ImportTypeMapping(schemaT.QualifiedName));
}
//if (settings.UseNotations)
// {
// foreach (XmlSchemaNotation schemaT in schema.Notations.Values)
// maps.Add(schemaImporter.ImportTypeMapping(schemaT.QualifiedName));
// }
}
// export all selected objects to the namespace code
foreach (var map in maps)
codeExporter.ExportTypeMapping(map);
// process the files to update classes and other objects
CodeNamespace newCodeNamespace = PostProcess(settings, codeNamespace);
Inside the XSD are some multidimensions arrays (giving something like "byte[][] myarray;" inside the produced code).
When I parse all members found inside the XSD and the parser reaches one of these multidimensions arrays the CodeMemberField or CodeMemberProperty contains a Type property which contains an ArrayRank property supposed to indicate the number of dimensions of the array (https://learn.microsoft.com/en-us/dotnet/api/system.codedom.codetypereference.arrayrank?view=dotnet-plat-ext-5.0)
However property.Type.ArrayRank is ALWAYS set to 1, whatever the number of dimensions. When I debug the app I can see another property inside the Type one (which is a CodeTypeReference) called NestedArrayDepth which indicates 2 (the right number of dimensions) while ArrayRank remains set to 1, as you can see here
I don't know whether this is a bug in the framework or intentional.
My question would then be: how do I get the real number of dimensions using CodeDom ? Is there a trick I don't know or do not suspect somewhere ?
I finally couldn't find a way to that. It was in fact a jagged array and despite the fact CodeDom seems to identify it I don't know how to get the information.
I solved my issue by replacing the byte[][] types bu objects[] types and will take care of what I'm doing when accessing these data until I find another way to do.
So sad...