[英]CodeTypeReference.ArrayRank alternative
我正在使用 CodeDom 從 XSD 文件構建智能類。 為此,我創建了以下操作
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);
XSD 內部是一些多維 arrays(在生成的代碼中給出類似“byte[][] myarray;”的內容)。
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://docs.microsoft. com/en-us/dotnet/api/system.codedom.codetypereference.arrayrank?view=dotnet-plat-ext-5.0 )
然而,property.Type.ArrayRank 總是設置為 1,無論維數是多少。 當我調試應用程序時,我可以在 Type one(它是 CodeTypeReference)中看到另一個名為 NestedArrayDepth 的屬性,它表示 2(正確的維數),而 ArrayRank 仍然設置為 1,如您在此處看到的
我不知道這是框架中的錯誤還是故意的。
那么我的問題是:如何使用 CodeDom 獲得實際的維數? 有什么我不知道或不懷疑的技巧嗎?
我終於找不到辦法了。 它實際上是一個鋸齒狀數組,盡管 CodeDom 似乎可以識別它,但我不知道如何獲取信息。
我通過替換 byte[][] 類型 bu objects[] 類型解決了我的問題,並且會在訪問這些數據時處理我正在做的事情,直到我找到另一種方法。
好難過...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.