Difference between revisions of "Dice/RollerConfig"
Line 60: | Line 60: | ||
== Thread Safety == | == Thread Safety == | ||
− | Reading values from RollerConfig is thread safe. Writing values or manipulating the FunctionRegistry or MacroRegistry is not thread-safe. Internal functions do not write to RollerConfig. | + | Reading values from RollerConfig is thread safe. Writing values or manipulating the FunctionRegistry or MacroRegistry is not thread-safe. Internal functions do not write to RollerConfig. The default implementation of GetRandomBytes is thread-safe; passing your own version here may or may not be thread-safe. |
+ | |||
+ | If full thread-safety is desired for RollerConfig, please open an issue on GitHub explaining your use-case. | ||
== Examples == | == Examples == |
Revision as of 21:49, 14 August 2017
Stores various configuration related to the dice roller.
- Namespace: Dice
- Assembly: DiceRoller (in DiceRoller.dll)
Inheritance Hierarchy
System.Object
- Dice.RollerConfig
Syntax
public class RollerConfig
Constructors
Name | Description | |
---|---|---|
RollerConfig() | Constructs a new RollerConfig instance with default values. |
Properties
Name | Description | |
---|---|---|
ExecuteMacro | Gets or sets the function used to execute macros. | |
FunctionRegistry | Gets or sets the registry of all valid function names and their callbacks. | |
MacroRegistry | Gets or sets the registry of all valid macro names and their callbacks. | |
GetRandomBytes | Gets or sets the function used to generate random numbers. | |
MaxDice | Gets or sets the maximum number of dice that may be rolled. | |
MaxRecursionDepth | Gets or sets how deeply nested a dice expression can get. | |
MaxRerolls | Gets or sets the maximum number of times a single die may be rerolled. | |
MaxSides | Gets or sets the maximum number of sides a single die may have. | |
NormalSidesOnly | Gets or sets whether dice expressions are limited to rolling dice with a "normal" number of sides, or if they can roll dice of any number of sides. |
Remarks
The default values for RollerConfig are as follows. These values are set upon constructing the object, however they can be overridden by passing in different values when creating the object (see Examples below for details).
FunctionRegistry = new FunctionRegistry();
FunctionRegistry.RegisterType(typeof(BuiltinFunctions));
MacroRegistry = new MacroRegistry();
GetRandomBytes = null; // null makes use of System.Cryptography.RNGCryptoServiceProvider to generate random numbers
MaxDice = 1000;
MaxRecursionDepth = 20;
MaxRerolls = 100;
MaxSides = 10000;
NormalSidesOnly = false;
Thread Safety
Reading values from RollerConfig is thread safe. Writing values or manipulating the FunctionRegistry or MacroRegistry is not thread-safe. Internal functions do not write to RollerConfig. The default implementation of GetRandomBytes is thread-safe; passing your own version here may or may not be thread-safe.
If full thread-safety is desired for RollerConfig, please open an issue on GitHub explaining your use-case.
Examples
The following is an example of creating a custom RollerConfig which leaves most values at their default but customizes some others.
using Dice;
class Sample
{
public static void Main()
{
var config = new RollerConfig()
{
MaxDice = 200
};
}
}