By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,698 Members | 1,535 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,698 IT Pros & Developers. It's quick & easy.

Long Generic Instantiations

P: n/a
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,InnerDic tionary>;

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.
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jasper Kent" <ja*********@hotmail.com> wrote in message
news:91******************@newsfe3-gui.ntli.net...
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,InnerDic tionary>;

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.

Nov 17 '05 #2

P: n/a
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,InnerDic tionary>
{ }

Hope this helps
Jay
"Jasper Kent" <ja*********@hotmail.com> wrote in message
news:91******************@newsfe3-gui.ntli.net...
| 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,InnerDic tionary>;
|
| 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.
|
|
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.