Skip to main content
A newer version of this page is available. .

Declare Menu

  • 4 minutes to read

The Declare menu is a quick and easy way to add the required code to your types.

Declare_Main

Usage

  1. Place the caret into a type definition and hit Alt+Insert.
  2. Select the required action and hit Enter.
  3. Select the members involved in the declaration using the mouse or Space key.

    Declare_2

  4. Optionally, open the Options menu using the Ctrl key.

    • To change options, use the mouse or corresponding letter keys displayed in the menu.
    • To close the menu, hit Enter.
  5. Hit Enter to confirm the members' selection and perform the declaration.

Declare Items

The Declare menu supports the following actions:

  • Constructor

    Generates the constructor for a class.

    Selectable items: Members to initialize in the constructor using its parameters.

    Options:

    • Constructor Accessibility

      Possible values:

      • public (selected by default);
      • internal;
      • protected internal;
      • protected;
      • private.
    • Generate properties

      Possible values:

      • yes;
      • no (selected by default).
  • IDisposable Implementation

    Makes any class disposable. Adds the IDisposable implementation along with all required methods (Dispose and other optional methods) to the class. This feature is identical to the Implement IDisposable Code Provider.

    Selectable items: Members to be included in the dispose pattern. The default interface implementation is added if no disposable members are found.

    Options:

    • Fields can be null — check this option if the fields or properties for which you are going to define the dispose pattern can potentially have a null value. If this option is selected, the members are checked for null before being disposed of.
    • Type can be inheritable — check this option to create another protected virtual Dispose method accepting a boolean parameter, which allows you to disable the actual disposing.
    • Type contains unmanned resources — check this option to create the ReleaseUnmanagedResources method and the destructor that calls ReleaseUnmanagedResources and optionally calls Dispose.
  • Delegate Members

    Creates members that wrap around the contained field's or property's members. This feature is useful when you need to surface a field's or property's members to this parent type.

    Selectable items: Members to delegate.

  • Override Members

    Overrides some members from the inherited classes.

    Selectable items: Members to override.

    Options:

    • Property Style

      Possible values:

      • Default — generated properties return the value of corresponding properties from the base class or throw a NotImplementedException;
      • Auto-implemented (selected by default);
      • Property with Backing Field.
  • Missing Members

    Implements any interface members missing from the class.

    Selectable items: Members to delegate.

    Options:

    • Property Style

      Possible values:

      • Default — generated properties return the value of corresponding properties from the base class or throw a NotImplementedException;
      • Auto-implemented (selected by default);
      • Property with Backing Field.
  • Partial Members

    Implements any partial members missing from the class.

    Selectable items: Members to delegate.

    Options:

    • Property Style

      Possible values:

      • Default — generated properties return the value of corresponding properties from the base class or throw a NotImplementedException;
      • Auto-implemented (selected by default);
      • Property with Backing Field.
  • Equality members

    Generates two Equals methods and a GetHashCode override.

    Selectable items: Members to be compared in the equality check.

    Options:

    • Implement IEquatable<T> interface — adds the interface implementation to the target type.
    • Overload equality members — implements the overloads of the "==" and "!=" operators, so that they call custom Equals method.
  • Comparison members

    Generates the CompareTo implementation and optionally implements the IComparable<T> and IComparable interfaces.

    Selectable items: Members to be compared on objects' comparison.

    Options:

    • Implement IComparable<T> and IComparable interfaces — adds interfaces implementation to the target type.
    • Overload relational members — implements the overloads of the ">", "<", ">=" and "<=" operators, so that they call custom CompareTo method.
  • ToString Override

    Generates the code of ToString() method override.

    Selectable items: Members whose values form the returned string.

  • Properties and Read-only properties

    Generates properties for the selected fields.

    Selectable items: Fields for which to generate properties.

    Options:

    • Accessibility

      Possible values:

      • public (selected by default);
      • internal;
      • protected internal;
      • protected;
      • private.
    • Virtual

      Possible values:

      • yes;
      • no (selected by default).