我可以从ResXResourceReader订购/排序数据吗?

本文关键字:数据 排序 ResXResourceReader 订购 我可以 | 更新日期: 2023-09-27 18:37:15

我需要在代码隐藏中读取整个 resx 文件。我是这样做的:

ResXResourceReader rsxrOrganizationSubtypes = new ResXResourceReader(@"D:'DNN_Cafaas'DesktopModules'OPEGIEKA.DNN.Modules.CreateInstitution'App_LocalResources'OrganizationSubtypes.resx");
rsxrOrganizationSubtypes.UseResXDataNodes = true;
IDictionaryEnumerator dict = rsxrOrganizationSubtypes.GetEnumerator();
while (dict.MoveNext())
{
    ResXDataNode node = (ResXDataNode)dict.Value;
}

是否有可能从resx文件对结果进行排序/排序?例如按名称?

已解决(按 resx 文件中的值排序)。也许有更好的方法可以做到这一点,但它有效:

ResXResourceReader rsxr = new ResXResourceReader(PathToResX);
rsxr.UseResXDataNodes = true;
IDictionaryEnumerator dictRSXR = rsxr.GetEnumerator();
SortedDictionary<string, string> sortedRSXR = new SortedDictionary<string, string>();
while (dictRSXR.MoveNext())
{
    ResXDataNode node = (ResXDataNode)dictRSXR.Value;
    sortedRSXR.Add(node.GetValue((ITypeResolutionService)null).ToString(), node.Name);
}
foreach (KeyValuePair<string, string> p in sortedRSXR)
{
    counterDDL++;
    dropDownList.Items.Insert(counterDDL, new ListItem(p.Key, p.Value));                                
}

我可以从ResXResourceReader订购/排序数据吗?

您可以在 while 循环中向SortedDictionary<string, ResXDataNode>添加键和值。这应该会自动对条目进行排序。