質問

I have a custom class named CatalogItem which I receive in a method, as an arrayed parameter.

Based upon one of the properties of these elements must assemble a matrix that the method returns.

public CatalogItem[][] ReorderCatalogItems(CatalogItem[] items)

The properties

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

But Visual Studio 2003 is not 2005, 2008 or 2010. It's been some time since I coded in this framework (1.1) for the last time.

I have this, since List and generics do not exist

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++;
    }
}

@Edit: oh for further understanding, this is my real and last objective: create an xml with this format. I've developed an XMLDoc Method todo so, but I need to create a control break iteration

<?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>
役に立ちましたか?

解決

In .NET 1.1 you'd basically have to use ArrayList where each element is an ArrayList if you want "fully" dynamic sizes. It's a pain, and involves casting all over the place, but such is life.

In this case I'm not sure you actually need that though - it's not entirely clear what you're trying to do, but if you actually know the size of the "outer" array you could just build up an ArrayList for each item, then use:

CatalogItem[] subArray = (CatalogItem) list.ToArray(typeof(CatalogItem));
orderedItems[index] = subArray;

to convert that list to an array, and store it in the "outer" array.

Hope that helps - sorry not to be able to give more complete code, but as I say it's not clear to me what exactly you're trying to achieve.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top