Long Generic Instantiations

  • Thread starter Thread starter Jasper Kent
  • Start date Start date
J

Jasper Kent

I'm trying to do the equivalent of using typedefs with templates in C++ to
avoid long instantiation names.

I can do this okay:

using BigDictionary = System.Collections.Generic.Dictionary<int,
System.Collections.Generic.Dictionary<int, string>>;

class MyClass
{
private BigDictionary myDictionary;
}

But I think it would be tidier to break it down, something like:

using InnerDictionary = System.Collections.Generic.Dictionary<int, string>;
using BigDictionary =
System.Collections.Generic.Dictionary<int,InnerDictionary>;

class MyClass
{
private BigDictionary myDictionary;
}

However, InnerDictionary is not recognised in the declaration of
BigDictionary. Is there any way I can do this?

In practice, the types I am using are fully scoped, rather than being
fundamental types, so the whole thing is even more verbose.

Thank is advance.
 
Jasper,

Unfortunately, there is no way to do this. The using statement doesn't
allow references to other using statements, so you will have to create
separate aliases for each.

Hope this helps.
 
Jasper,
Have you considered inheritance?

As the import alias is nothing more then an alias that is local to that
source file.

Something like (not tested):

class InnerDictionary : System.Collections.Generic.Dictionary<int,
string>
{ }

class BigDictionary :
System.Collections.Generic.Dictionary<int,InnerDictionary>
{ }

Hope this helps
Jay


| I'm trying to do the equivalent of using typedefs with templates in C++ to
| avoid long instantiation names.
|
| I can do this okay:
|
| using BigDictionary = System.Collections.Generic.Dictionary<int,
| System.Collections.Generic.Dictionary<int, string>>;
|
| class MyClass
| {
| private BigDictionary myDictionary;
| }
|
| But I think it would be tidier to break it down, something like:
|
| using InnerDictionary = System.Collections.Generic.Dictionary<int,
string>;
| using BigDictionary =
| System.Collections.Generic.Dictionary<int,InnerDictionary>;
|
| class MyClass
| {
| private BigDictionary myDictionary;
| }
|
| However, InnerDictionary is not recognised in the declaration of
| BigDictionary. Is there any way I can do this?
|
| In practice, the types I am using are fully scoped, rather than being
| fundamental types, so the whole thing is even more verbose.
|
| Thank is advance.
|
|
 

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

Back
Top