Enum Type Import Definitions
To use enum types as the core types for type shortcuts, the designer has to know where to load the enum types from. It uses type imports files which define which assemblies contain enum types. After type import files are loaded, the enums are available in the Type Shortcuts of the project and you can define new type shortcuts based on them.
As all target frameworks support enum types directly, you don't need type converters to work with enum types: it's enough to import the enum types in the designer using type import files.
Location and file format
TypeImport files, with the extension .typeimports
are small XML files
which are stored in TypeConverter folders (either the default type
converter folder of the designer or the additional type converter folder
specified in the Project Settings) or in the
folder from which the project was loaded.
For example, if your project is called MyCRMProject.llblgenproj
, the type imports file could be called MyCRMProject.llblgenproj.typeimports
. This isn't required
however. If you have specific type imports for a particular project, use the projectfilename.llblgenproj.typeimports format. If you have type imports for all
your projects, use any filename with the .typeimports
file extension, as long as the filename doesn't contain .llblgenproj
.
The format is as follows:
<typeImports>
<typeImport typeName="" assemblyFile=""/>
</typeImports>
The XML is stored in .typeimports
files which are all read at project
load (at the same time when Type Converters are read from the same
folder(s)). typeName is the name to use to obtain a Type instance
using the System.Type
.NET class. assemblyFile is the filename + full path,
which points to an assembly to load which contains the type specified.
If the type isn't an enum type, the type is ignored. If assemblyFile is omitted, the system will try to instantiate the type without the filename, e.g. through a type-lookup in the current appDomain.
Wildcards in enum type names
If you have a lot of enum types to import, it can become tedious to specify them all explicitly in a .typeimports file. To import a range of enums matching
a name with wildcards, you can specify the *
wildcard character (one or more times) in the enum type name, as long as you also specify the assembly filename.
The assembly filename can't contain wildcards. An example of a wildcard using typeimports file is given below.
All public (and nested public) enum types which match the enum typename (with wildcard) will be imported.
Nested enum types and wildcards
Nested types are accepted too, using +
characters. A valid wildcard using name could be: "MyNamespace.My*+*"
, meaning all nested enums in all classes starting with My
in the namespace MyNamespace
.
Examples
Enum type is part of a globally available assembly
The most basic typeimports file is the one which references a type that's in an assembly that's in the GAC or otherwise in an assembly that's directly discoverable by the designer:
<typeImports>
<typeImport typeName="System.ConsoleColor"/>
</typeImports>
Enum type is part of a non-globally available assembly
More advanced are types which are present in an assembly that's local to the project and thus not available from the GAC: the designer can only load the assembly if its path is fully specified, or relative to the TypeImport file.
<typeImports>
<typeImport typeName="EnumTypes.CategoryType" assemblyFile="\Myprojects\MyEnumDlls\EnumTypes.dll"/>
</typeImports>
Enum type is nested inside a type that's part of a non-globally available assembly
Enum types nested inside a class type need a different specification: using a +
delimiter. Below is an example of an enum type InnerEnum
that's nested
inside the class ClassWithInner
that's present an assembly that's local to the project and thus not available from the GAC: the designer can only load the
assembly if its path is fully specified.
<typeImports>
<typeImport typeName="EnumTypes.ClassWithInner+InnerEnum" assemblyFile="\Myprojects\MyEnumDlls\EnumTypes.dll"/>
</typeImports>
Enum type from an assembly relatively located from the typeimports file
Here a .typeimports file is shown which contains an assembly specification which is relative to the location of the .typeimports file itself
<typeImports>
<typeImport typeName="EnumTypes.MyEnumType" assemblyFile="..\..\MyEnumDlls\EnumTypes.dll"/>
</typeImports>
Enum types specified using a wildcard
To import all enum types in a given namespace for instance, you can specify a wildcard:
<typeImports>
<typeImport typeName="EnumTypes.*" assemblyFile="\Myprojects\MyEnumDlls\EnumTypes.dll"/>
</typeImports>
This will import all public (and nested public) enum types matching the string EnumTypes.*
, so EnumTypes.MyEnumType
and also EnumTypes.MyClass+MyNestedEnumType
.
But not MyClass+MyNestedEnumType
as it doesn't match EnumTypes
for the namespace.
You can specify more than one wildcard in the enum typename, like in the example below:
<typeImports>
<typeImport typeName="EnumTypes.MyClass*+MyNested*" assemblyFile="\Myprojects\MyEnumDlls\EnumTypes.dll"/>
</typeImports>
Re-loading .typeimports files
If you have created a .typeimports
file and you want to import its
contents, you don't need to restart the designer. You can re-load the
.typeimports
files by right-clicking the project node in the Project Explorer, and select Re-scan for TypeConverters and .typeimports files from the context menu.
Check which types are loaded
To see which types are loaded, use from the main menu: Tools -> View Loaded External Types... This will show all loaded external types, including enum types. If your enum type isn't present, please check the Application Output Pane in the designer (docked at the bottom) to see whether an error occurred during type load.