Skip to content
Alexandru Maftei edited this page Jun 6, 2014 · 1 revision

vCommands provides a mechanism for easy configuration: Variables.

These variables can easily and efficiently be accessed through code and through commands in vCommands.

Base variable

Every variable implements the interface IVariable.

Every command has a name, and an abstract (short description). These are accessible through the properties Name and Abstract.
Any variable's underlying typed value can be retrieved through the T GetValue<T>() method, where T is the desired type. This is for extreme cases and should not be overused.
Its value as string can be manipulated through the StringValue property. As with the previously-mentioned method, this property's setter generally should not be overused. The getter should be safe.

Each variable has a Change event, which is raised before the value of a variable is about to be changed.
This event provides most information needed and the possibility to cancel the change with a custom message. (status code is implicitly -2)

Please note that only a change from within vCommands can be stopped. The properties (such as StringValue) are not controlled in any way.

Types of variables

So far, vCommands contains 3 types of variables, each for a different circumstance.

This is the simplest kind of variable. It simply wraps around a field whose type is provided through a generic argument.

So far, the following types are supported (due to conversion to and from string): string, bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double and decimal.

The underlying value can be accessed very efficiently through the Value property (which will get inlined by the JITter in most cases), making this type of variable ideal for intensive accessing (getting and setting).
Access from commands is also generally very quick.

This is exactly like Variable, except all access to the underlying value is under a lock, making it completely thread-safe.

I recommend using this only if truly necessary. The locking does add a performance penalty, which may affect the application in many cases.

This pseudo-variable uses a set of delegates for every function of it.

There is a delegate for each of the following: getting value, setting value, getting string, setting string.

Either of these may be present or absent, the properties will be adapted and exceptions will be thrown when appropriate, workarounds will be used when available and proper status code and outputs will be returned when evaluated.

This is ideal for many scenarios, such as for really overused fields, which could be set through delegates (moving some of the overhead from your code to vCommands).
Another problem that this aims to solve is complex pseudo-variables, that would be constructed on-demand or which need extra access rights/logic.

Clone this wiki locally