Aliasing

Scott Waldron Updated by Scott Waldron

All Dino imports can be aliased. Sometimes this is helpful to save a few keystrokes later, and other times it is downright essential – some types must be aliased on import. Sometimes, as when importing scripts, the alias radically changes how the imported object is subsequently accessed.

// aliased script import
import script 'Other.dino' as Other;

// aliased native type imports
from System import 'Func`2' as F2; // generic delegate type
from System.Collections.Generic import List as GList;
from System import Convert as C;

Importing Generic Types with Aliases

When importing generic types (for example, SomeType<T>, OtherType<K, V>), you must use a special import mechanism if the generic type name conflicts with a non-generic type name in the same namespace. Dino will be smart about generic types that do not have a name clash. For example, System.Collections.Generic contains the List<T> class. However, there is no such thing as a List class (non-generic version). So, this import statement:

from System.Collections.Generic import List;

will import the List<T> class (since it can infer what you meant), which you would use as follows:

var glist = List[string]();
glist.Add('test');

However, consider the case of a fictitious namespace called Foo that contains the non-generic Bar class, and the generic Bar<T> class. To import the generic Bar<T> class, you would need to use this syntax:

from Foo import 'Bar`1' as Bar1;

This odd syntax is based on the way that names are maintained internally in the .NET framework: generic classes are named with their class name, a backtick, and then the number of generic arguments. For example, the Func<Tin, Tout> delegate would have the name Func`2.

Since the backtick is not an allowable character in a Dino identifier or type name, these types of imports must be aliased.

How did we do?

Native Types

Other Dino Scripts

Contact