Click or drag to resize

Understanding Type Name Resolution in Nimbus

Whenever you enter the name of a type into the Nimbus driver designer or any of its associated item editors, Nimbus needs to locate the assembly in which the type you're referring to is defined. To do this, Nimbus uses the same mechanism as Visual Studio itself. Specifically, it resolves type names based upon the driver project's set of assembly refererences, project references, and NuGet package references.

If the type name resolution operation fails, Nimbus will display an error message indicating the type you've entered is unknown. The most common reasons for this error message are:

  • The type name is misspelled (i.e., there is a typo in the name you entered).

  • The namespace has not been included in the type name. For most types used by an IVI.NET driver, the type can be specified without including the parent namespace. The namespace need not be specfied in the following cases:

    1. The type is in the main driver assembly.

    2. The type is defined in an IVI assembly. For example, IWaveform<double> can be specified instead of Ivi.Driver.IWaveform<double>.

    3. The type is in mscorlib. For example, IList can be specified instead of System.Collections.IList.

  • The type is defined in an assembly that the driver project is not currently referencing. Nimbus cannot infer which assembly that might be, so you'll need to add a reference to the assembly that contains the type you're trying to use.

If Nimbus determines that the type you entered exists in more than one assembly referenced by the driver project, then Nimbus will display a dialog box asking you to clarify which type you intended to use.

Nimbus type name resolution is characterized in more detail below.

Type Parameters

In addition to recognizing standard type names, Nimbus also recognizes generic type parameter names, so long as the type parameter you're referring to is in scope relative to the item you're editing.

In order to further explain, consider the following simple generic type definition:

C#
// A generic type.
public class Acme4321DataSet<T> : DriverNode
{
    private T[] DataSet { get; set; }

  [DriverMethod]
  public void Transform<U>(U[] data)
    {
      // Transformation each element of "DataSet" according to the values passed in
        // via the "data" parameter.
    }
}

In the above code, the Acme4321DataSet class has been defined as a generic type, and includes a single type parameter (T). This type parameter is used to define a private property within the Acme4321DataSet class that will hold a reference to an "array of T" (DataSet).

This class also defines a generic method named Transform. The Transform method defines a different type parameter (U), and accepts an "array of U" as a parameter (data).

In this example, T and U are different type names, and may be used when entering type names in the driver designer's tree view or item editors. Exactly when type parameters such as T and U used above may be entered depends on exactly what you are trying to add or modify using the designer.

For example, if you are adding a new property to the Acme4321DataSet class, or using an item editor to change the type of a property already defined on that class, you may enter T as the type of that property. Likewise, you may enter T as the return type for a method defined on that class.

Similarly, if you are adding or changing a parameter of the Transform method, then the set of type names you may use to indicate the type of that parameter includes both T and U. The type parameter T is available because it is defined on the class that contains the Transform method. The type parameter U is also available to be used as a parameter type because U is defined on the method that contains the parameter you're adding or updating.

For a more in-depth explanation of generic types, generic methods and working with type parameters, refer to the C# Programming Guide in MSDN.

See Also

Download a complete CHM version of this documentation here.