Description

Provide the current object based on its type.

There is value in having a context that contains a current object. In the Unix shell, a current working directory helps one focus on the files of immediate interest. The [Current] attribute allows one to pull from some context based on the type of its argument.

An ICurrentProvider is implemented for the following types: InputField, Minibuffer, and Buffer. But one can add their own providers.

For instance, imagine a game with weapons that are degradable. A tester wishes to exercise that functionality. Suppose this command exists:

[Command]
public void DegradeWeapon(Weapon weapon) {
// Your degrade code here.
}

This command works but it will ask the user to select the weapon each time.

If operating on the player's equipped weapon makes sense and is convenient, one can add a class like CurrentWeaponProvider that implements ICurrentProvider. Plug that class into Minibuffer by doing the following:

Minibuffer.instance.currentProviders.Add(new CurrentWeaponProvider());

Then the command can be updated to this:

[Command]
public void DegradeWeapon([Current] Weapon weapon) {
// Your degrade code here.
}

Now the user will not be prompted for a weapon, but the method will be provided with the "current" weapon.

See also
Current

Public Member Functions

bool CanProvideType (Type t)
 Return true if it can provide the given type.
 
object CurrentObject ()
 Return the current object or null.
 

Properties

Type canonicalType [get]
 Return the principle type of this provider.