MockExtensions
public static class MockExtensionsConvenience helpers that let generated values become null/default with a tunable
probability, plus small IList/IReadOnlyList helpers (PickRandom, Shuffle).
Methods
Section titled “Methods”
OrNull(T, float)
Section titled “OrNull(T, float)”public static T OrNull<T>(this T value, float nullProbability = 0.3) where T : classReturn value or null with nullProbability.
Parameters
| Name | Type |
|---|---|
value |
{T} |
nullProbability |
System.Single |
Returns
{T}
OrNullable(T, float)
Section titled “OrNullable(T, float)”public static T? OrNullable<T>(this T value, float nullProbability = 0.3) where T : structReturn value wrapped as a Nullable<T>, possibly as null.
Use this for value types since OrNull is restricted to reference types — C# does not
allow overload resolution based on class/struct constraints alone.
Parameters
| Name | Type |
|---|---|
value |
{T} |
nullProbability |
System.Single |
Returns
System.Nullable{{T}}
OrDefault(T, float)
Section titled “OrDefault(T, float)”public static T OrDefault<T>(this T value, float defaultProbability = 0.3)Return value or default(T) with defaultProbability.
Works for both reference and value types.
Parameters
| Name | Type |
|---|---|
value |
{T} |
defaultProbability |
System.Single |
Returns
{T}
PickRandom(IReadOnlyList)
Section titled “PickRandom(IReadOnlyList)”public static T PickRandom<T>(this IReadOnlyList<T> items)Pick a random element from items using MockMagic’s seeded RNG.
Parameters
| Name | Type |
|---|---|
items |
System.Collections.Generic.IReadOnlyList{{T}} |
Returns
{T}
Shuffle(IList)
Section titled “Shuffle(IList)”public static void Shuffle<T>(this IList<T> items)Shuffle items in place using MockMagic’s seeded RNG.
Parameters
| Name | Type |
|---|---|
items |
System.Collections.Generic.IList{{T}} |