Collection Types

C

Chris Marsh

All

I have a small project that I'm working on - more for my own edification
than the resultant product. The purpose of the project is to display the
different versions of assemblies that are referenced by other assemblies (in
a given folder), and which the referencing assemblies are. Therefore, if the
folder foo is being inspected, the following may be a typical result:

foo [folder]
|
---- assembly1 [assembly being referenced by at least one assembly in folder
foo]
|
---- 1.2.3.4 [version]
|
---- assembly2.dll [references assembly 1, version 1.2.3.4]
|
---- assembly3.dll
|
---- 1.2.3.5
|
---- assembly6.dll
|
---- assembly7
|
---- 1.2.3.8
|
---- assembly1.dll
|
---- 1.2.3.9
|
---- assembly2.dll

To achieve this, I'm iterating through each file in the folder, and if it's
an assembly I'm then getting its collection of references; from each of
which I can build my "map" of all assembly references as shown above.

Where I'm getting stuck (and the real point of the exercise from a personal
development perspective) is how to store this data. Is there an existing
collection type that lends itself to this hierarchical structure, or need I
roll my own? If so, what would be suitable underlying collection types, and
how would they interact? How would I handle sorting?

Any comments or advice would be very much appreciated, as I would like to
understand the optimal manner in whcih to approach this sort of problem.

Many thanks in advance!
 
C

Chris Marsh

All

Sorry, I forgot to mention that I'm targetting the .NET framework version
2.0, although comments regarding 3.5 would also be most welcome.

Cheers!
 
A

Adam Benson

Is there an existing collection type that lends itself to this
Not really.
Something like this ?

/*
* A1 -> A1.child1

* -> A1.child2 -> grandchild1

* grandchild2

*/

private static void TestAssemblyMap()

{

AssemblyMap am = new AssemblyMap();

am.Add("A1");

AssemblyMap a1 = am["A1"];

a1.Add("A1.child1");

a1.Add("A1.child2");

AssemblyMap child2 = a1["A1.child2"];

child2.Add("grandchild1");

child2.Add("grandchild2");

}

}

public class AssemblyMap : Dictionary<string, AssemblyMap>

{

public AssemblyMap Add(string n)

{

AssemblyMap am = new AssemblyMap();

this.Add(n, am);

return am;

}

}
That's a bit too long for my tea break :)

Besides, it depends on how you want to sort - what's the ordering?

BTW - you would need to watch out for circular dependencies - which the
above code does not do.

Anyway, hope it gives you a start.

Cheers,

Adam.
=========
 
C

Chris Marsh

Mike/Adam

Thanks very much for your input. I've been thinking more about this problem,
and although your[Adam] solution does pretty much what I was asking for, I'm
wondering if I'm approaching this from the wrong perspective.

In essence, my data can be represented by the tuple [string
referencedAssemblyName, string referencedAssemblyVersion, string
referencingAssemblyFileName]. I could introduce a class
AssemblyReferenceInfo to hold this data, and implement the IComparable
interface. I can then store these objects in an
ArrayList<AssemblyReferenceInfo>, which would be sortable. Each object in
the ArrayList would be unique, as I would never have an assembly that holds
more than one reference to the same version of the same assembly.

Does this sound like a more effective means to process this type of data? I
can immediately see how to display this in a console - I just need to
investigate more sophisticated display options.

Thanks again for your time - let me know if you see any issue with the
above.

Cheers!

--
Regards

Chris Marsh

Adam Benson said:
Not really.
Something like this ?

/*
* A1 -> A1.child1

* -> A1.child2 -> grandchild1

* grandchild2

*/

private static void TestAssemblyMap()

{

AssemblyMap am = new AssemblyMap();

am.Add("A1");

AssemblyMap a1 = am["A1"];

a1.Add("A1.child1");

a1.Add("A1.child2");

AssemblyMap child2 = a1["A1.child2"];

child2.Add("grandchild1");

child2.Add("grandchild2");

}

}

public class AssemblyMap : Dictionary<string, AssemblyMap>

{

public AssemblyMap Add(string n)

{

AssemblyMap am = new AssemblyMap();

this.Add(n, am);

return am;

}

}
That's a bit too long for my tea break :)

Besides, it depends on how you want to sort - what's the ordering?

BTW - you would need to watch out for circular dependencies - which the
above code does not do.

Anyway, hope it gives you a start.

Cheers,

Adam.
=========
 
A

Adam Benson

Does this sound like a more effective means to process this type of data?
It does.

You'd presumably get a list like this for assemblies referencing a.dll :

[a.dll, 1.0.0.0, b.dll]
[a.dll, 1.0.0.0, c.dll]
[a.dll, 1.0.0.0, d.dll]
[a.dll, 1.0.0.0, e.dll]

Looks like a nice solution.

Regards,

Adam.
========
 
C

Chris Marsh

Adam

Adam Benson said:
Does this sound like a more effective means to process this type of data?
It does.

You'd presumably get a list like this for assemblies referencing a.dll :

[a.dll, 1.0.0.0, b.dll]
[a.dll, 1.0.0.0, c.dll]
[a.dll, 1.0.0.0, d.dll]
[a.dll, 1.0.0.0, e.dll]
Exactly!

Looks like a nice solution.

Cheers :) Thanks again for your input - much appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top