【发布时间】:2012-04-01 19:33:48
【问题描述】:
我有一个名为 CatalogItem 的自定义类,我在方法中接收它作为数组参数。
必须根据这些元素的属性之一组装该方法返回的矩阵。
public CatalogItem[][] ReorderCatalogItems(CatalogItem[] items)
属性
public string Id
public string Version
public bool HasVersion
public bool HasDependencies
public string Name
public string DisplayName
public bool IsExportable
public string CatalogName
public string ZipName
但 Visual Studio 2003 不是 2005、2008 或 2010。我上次在这个框架 (1.1) 中编码已经有一段时间了。
我有这个,因为 List 和泛型不存在
StringBuilder zipNames = new StringBuilder();
foreach(CatalogItem item in items)
{
if(item.ZipName != string.Empty && zipNames.ToString().IndexOf(item.ZipName) == -1)
{
zipNames.Append(item.ZipName);
zipNames.Append("\r\n");
//StringBuilder.AppendLine(string) is unexistent in fwk 1.1
}
}
//SplitString is a custom method that does a string.Split with a string parser (unexistent out-of-the-box feat. in 2003)
string[] sZipNames = SplitString(zipNames.ToString(),"\r\n");
CatalogItem[][] orderedItems = new CatalogItem[sZipNames.Length+1][];
///+1 since string.Empty is one of the valid elements
/// even when not listed on zZipNames (name default)
foreach(CatalogItem item in items)
{
int i = 0;
bool Next = true;
while(Next)
{
if(item.ZipName == string.Empty)
{
//I'm out of ideas now
}
if(sZipNames[i].IndexOf(item.ZipName) == -1)
{
//I'm out of ideas now
}
i++;
}
}
@编辑: 哦,为了进一步理解,这是我真正的最后一个目标:创建一个具有这种格式的 xml。我为此开发了一个 XMLDoc 方法,但我需要创建一个控制中断迭代
<?xml version="1.0" encoding="utf-8"?>
<export>
<items outputfile="c:\data\erase\exportbatch.zip">
<item>
<catalog>operations</catalog>
<id>Od4f0f211-4673-49cd-a197-567768b9c00a</id>
<name>NewOp</name>
<dependencies>false</dependencies>
</item>
<item>
<catalog>operations</catalog>
<id>Oc19efe25-33ec-45b7-9cc1-a813ffbecc61</id>
<name>TestAttributes</name>
</item>
</items>
<items outputfile="c:\data\erase\exportbatch2.zip">
<item>
<catalog>transactions</catalog>
<id>T15454fe0-7afb-4146-9ec3-83547f96b25a</id>
<name>GetAllEmployee</name>
<dependencies>true</dependencies>
</item>
<item>
<catalog>transactions</catalog>
<id>Tc37afa55-39e4-416d-9088-011a117cff72</id>
<name>CustOrderHist_Test123</name>
<dependencies>false</dependencies>
</item>
</items>
</export>
【问题讨论】:
标签: c# .net-1.1 visual-studio-2003