Commit 7c80891a authored by Nick Craver's avatar Nick Craver

Cleanup: Condition

parent 9f326234
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
/// <summary> /// <summary>
/// Describes a pre-condition used in a redis transaction /// Describes a pre-condition used in a redis transaction
/// </summary> /// </summary>
...@@ -11,21 +10,26 @@ public abstract class Condition ...@@ -11,21 +10,26 @@ public abstract class Condition
{ {
internal abstract Condition MapKeys(Func<RedisKey,RedisKey> map); internal abstract Condition MapKeys(Func<RedisKey,RedisKey> map);
private Condition() { } private Condition() { }
/// <summary> /// <summary>
/// Enforces that the given hash-field must have the specified value /// Enforces that the given hash-field must have the specified value.
/// </summary> /// </summary>
/// <param name="key">The key of the hash to check.</param>
/// <param name="hashField">The field in the hash to check.</param>
/// <param name="value">The value that the hash field must match.</param>
public static Condition HashEqual(RedisKey key, RedisValue hashField, RedisValue value) public static Condition HashEqual(RedisKey key, RedisValue hashField, RedisValue value)
{ {
if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField)); if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField));
if (value.IsNull) return HashNotExists(key, hashField); if (value.IsNull) return HashNotExists(key, hashField);
return new EqualsCondition(key, hashField, true, value); return new EqualsCondition(key, hashField, true, value);
} }
/// <summary> /// <summary>
/// Enforces that the given hash-field must exist /// Enforces that the given hash-field must exist.
/// </summary> /// </summary>
/// <param name="key">The key of the hash to check.</param>
/// <param name="hashField">The field in the hash to check.</param>
public static Condition HashExists(RedisKey key, RedisValue hashField) public static Condition HashExists(RedisKey key, RedisValue hashField)
{ {
if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField)); if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField));
...@@ -33,8 +37,11 @@ public static Condition HashExists(RedisKey key, RedisValue hashField) ...@@ -33,8 +37,11 @@ public static Condition HashExists(RedisKey key, RedisValue hashField)
} }
/// <summary> /// <summary>
/// Enforces that the given hash-field must not have the specified value /// Enforces that the given hash-field must not have the specified value.
/// </summary> /// </summary>
/// <param name="key">The key of the hash to check.</param>
/// <param name="hashField">The field in the hash to check.</param>
/// <param name="value">The value that the hash field must not match.</param>
public static Condition HashNotEqual(RedisKey key, RedisValue hashField, RedisValue value) public static Condition HashNotEqual(RedisKey key, RedisValue hashField, RedisValue value)
{ {
if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField)); if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField));
...@@ -43,8 +50,10 @@ public static Condition HashNotEqual(RedisKey key, RedisValue hashField, RedisVa ...@@ -43,8 +50,10 @@ public static Condition HashNotEqual(RedisKey key, RedisValue hashField, RedisVa
} }
/// <summary> /// <summary>
/// Enforces that the given hash-field must not exist /// Enforces that the given hash-field must not exist.
/// </summary> /// </summary>
/// <param name="key">The key of the hash to check.</param>
/// <param name="hashField">The field in the hash that must not exist.</param>
public static Condition HashNotExists(RedisKey key, RedisValue hashField) public static Condition HashNotExists(RedisKey key, RedisValue hashField)
{ {
if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField)); if (hashField.IsNull) throw new ArgumentNullException(nameof(hashField));
...@@ -52,56 +61,52 @@ public static Condition HashNotExists(RedisKey key, RedisValue hashField) ...@@ -52,56 +61,52 @@ public static Condition HashNotExists(RedisKey key, RedisValue hashField)
} }
/// <summary> /// <summary>
/// Enforces that the given key must exist /// Enforces that the given key must exist.
/// </summary> /// </summary>
public static Condition KeyExists(RedisKey key) /// <param name="key">The key that must exist.</param>
{ public static Condition KeyExists(RedisKey key) => new ExistsCondition(key, RedisType.None, RedisValue.Null, true);
return new ExistsCondition(key, RedisType.None, RedisValue.Null, true);
}
/// <summary> /// <summary>
/// Enforces that the given key must not exist /// Enforces that the given key must not exist
/// </summary> /// </summary>
public static Condition KeyNotExists(RedisKey key) /// <param name="key">The key that must not exist.</param>
{ public static Condition KeyNotExists(RedisKey key) => new ExistsCondition(key, RedisType.None, RedisValue.Null, false);
return new ExistsCondition(key, RedisType.None, RedisValue.Null, false);
}
/// <summary> /// <summary>
/// Enforces that the given list index must have the specified value /// Enforces that the given list index must have the specified value
/// </summary> /// </summary>
public static Condition ListIndexEqual(RedisKey key, long index, RedisValue value) /// <param name="key">The key of the list to check.</param>
{ /// <param name="index">The position in the list to check.</param>
return new ListCondition(key, index, true, value); /// <param name="value">The value of the list position that must match.</param>
} public static Condition ListIndexEqual(RedisKey key, long index, RedisValue value) => new ListCondition(key, index, true, value);
/// <summary> /// <summary>
/// Enforces that the given list index must exist /// Enforces that the given list index must exist
/// </summary> /// </summary>
public static Condition ListIndexExists(RedisKey key, long index) /// <param name="key">The key of the list to check.</param>
{ /// <param name="index">The position in the list that must exist.</param>
return new ListCondition(key, index, true, null); public static Condition ListIndexExists(RedisKey key, long index) => new ListCondition(key, index, true, null);
}
/// <summary> /// <summary>
/// Enforces that the given list index must not have the specified value /// Enforces that the given list index must not have the specified value
/// </summary> /// </summary>
public static Condition ListIndexNotEqual(RedisKey key, long index, RedisValue value) /// <param name="key">The key of the list to check.</param>
{ /// <param name="index">The position in the list to check.</param>
return new ListCondition(key, index, false, value); /// <param name="value">The value of the list position must not match.</param>
} public static Condition ListIndexNotEqual(RedisKey key, long index, RedisValue value) => new ListCondition(key, index, false, value);
/// <summary> /// <summary>
/// Enforces that the given list index must not exist /// Enforces that the given list index must not exist
/// </summary> /// </summary>
public static Condition ListIndexNotExists(RedisKey key, long index) /// <param name="key">The key of the list to check.</param>
{ /// <param name="index">The position in the list that must not exist.</param>
return new ListCondition(key, index, false, null); public static Condition ListIndexNotExists(RedisKey key, long index) => new ListCondition(key, index, false, null);
}
/// <summary> /// <summary>
/// Enforces that the given key must have the specified value /// Enforces that the given key must have the specified value
/// </summary> /// </summary>
/// <param name="key">The key to check.</param>
/// <param name="value">The value that must match.</param>
public static Condition StringEqual(RedisKey key, RedisValue value) public static Condition StringEqual(RedisKey key, RedisValue value)
{ {
if (value.IsNull) return KeyNotExists(key); if (value.IsNull) return KeyNotExists(key);
...@@ -110,7 +115,9 @@ public static Condition StringEqual(RedisKey key, RedisValue value) ...@@ -110,7 +115,9 @@ public static Condition StringEqual(RedisKey key, RedisValue value)
/// <summary> /// <summary>
/// Enforces that the given key must not have the specified value /// Enforces that the given key must not have the specified value
/// </summary> /// </summary>
/// <param name="key">The key to check.</param>
/// <param name="value">The value that must not match.</param>
public static Condition StringNotEqual(RedisKey key, RedisValue value) public static Condition StringNotEqual(RedisKey key, RedisValue value)
{ {
if (value.IsNull) return KeyExists(key); if (value.IsNull) return KeyExists(key);
...@@ -119,156 +126,137 @@ public static Condition StringNotEqual(RedisKey key, RedisValue value) ...@@ -119,156 +126,137 @@ public static Condition StringNotEqual(RedisKey key, RedisValue value)
/// <summary> /// <summary>
/// Enforces that the given hash length is a certain value /// Enforces that the given hash length is a certain value
/// </summary> /// </summary>
public static Condition HashLengthEqual(RedisKey key, long length) /// <param name="key">The key of the hash to check.</param>
{ /// <param name="length">The length the hash must have.</param>
return new LengthCondition(key, RedisType.Hash, 0, length); public static Condition HashLengthEqual(RedisKey key, long length) => new LengthCondition(key, RedisType.Hash, 0, length);
}
/// <summary> /// <summary>
/// Enforces that the given hash length is less than a certain value /// Enforces that the given hash length is less than a certain value
/// </summary> /// </summary>
public static Condition HashLengthLessThan(RedisKey key, long length) /// <param name="key">The key of the hash to check.</param>
{ /// <param name="length">The length the hash must be less than.</param>
return new LengthCondition(key, RedisType.Hash, 1, length); public static Condition HashLengthLessThan(RedisKey key, long length) => new LengthCondition(key, RedisType.Hash, 1, length);
}
/// <summary> /// <summary>
/// Enforces that the given hash length is greater than a certain value /// Enforces that the given hash length is greater than a certain value
/// </summary> /// </summary>
public static Condition HashLengthGreaterThan(RedisKey key, long length) /// <param name="key">The key of the hash to check.</param>
{ /// <param name="length">The length the hash must be greater than.</param>
return new LengthCondition(key, RedisType.Hash, -1, length); public static Condition HashLengthGreaterThan(RedisKey key, long length) => new LengthCondition(key, RedisType.Hash, -1, length);
}
/// <summary> /// <summary>
/// Enforces that the given string length is a certain value /// Enforces that the given string length is a certain value
/// </summary> /// </summary>
public static Condition StringLengthEqual(RedisKey key, long length) /// <param name="key">The key of the string to check.</param>
{ /// <param name="length">The length the string must be equal to.</param>
return new LengthCondition(key, RedisType.String, 0, length); public static Condition StringLengthEqual(RedisKey key, long length) => new LengthCondition(key, RedisType.String, 0, length);
}
/// <summary> /// <summary>
/// Enforces that the given string length is less than a certain value /// Enforces that the given string length is less than a certain value
/// </summary> /// </summary>
public static Condition StringLengthLessThan(RedisKey key, long length) /// <param name="key">The key of the string to check.</param>
{ /// <param name="length">The length the string must be less than.</param>
return new LengthCondition(key, RedisType.String, 1, length); public static Condition StringLengthLessThan(RedisKey key, long length) => new LengthCondition(key, RedisType.String, 1, length);
}
/// <summary> /// <summary>
/// Enforces that the given string length is greater than a certain value /// Enforces that the given string length is greater than a certain value
/// </summary> /// </summary>
public static Condition StringLengthGreaterThan(RedisKey key, long length) /// <param name="key">The key of the string to check.</param>
{ /// <param name="length">The length the string must be greater than.</param>
return new LengthCondition(key, RedisType.String, -1, length); public static Condition StringLengthGreaterThan(RedisKey key, long length) => new LengthCondition(key, RedisType.String, -1, length);
}
/// <summary> /// <summary>
/// Enforces that the given list length is a certain value /// Enforces that the given list length is a certain value
/// </summary> /// </summary>
public static Condition ListLengthEqual(RedisKey key, long length) /// <param name="key">The key of the list to check.</param>
{ /// <param name="length">The length the list must be equal to.</param>
return new LengthCondition(key, RedisType.List, 0, length); public static Condition ListLengthEqual(RedisKey key, long length) => new LengthCondition(key, RedisType.List, 0, length);
}
/// <summary> /// <summary>
/// Enforces that the given list length is less than a certain value /// Enforces that the given list length is less than a certain value
/// </summary> /// </summary>
public static Condition ListLengthLessThan(RedisKey key, long length) /// <param name="key">The key of the list to check.</param>
{ /// <param name="length">The length the list must be less than.</param>
return new LengthCondition(key, RedisType.List, 1, length); public static Condition ListLengthLessThan(RedisKey key, long length) => new LengthCondition(key, RedisType.List, 1, length);
}
/// <summary> /// <summary>
/// Enforces that the given list length is greater than a certain value /// Enforces that the given list length is greater than a certain value
/// </summary> /// </summary>
public static Condition ListLengthGreaterThan(RedisKey key, long length) /// <param name="key">The key of the list to check.</param>
{ /// <param name="length">The length the list must be greater than.</param>
return new LengthCondition(key, RedisType.List, -1, length); public static Condition ListLengthGreaterThan(RedisKey key, long length) => new LengthCondition(key, RedisType.List, -1, length);
}
/// <summary> /// <summary>
/// Enforces that the given set cardinality is a certain value /// Enforces that the given set cardinality is a certain value
/// </summary> /// </summary>
public static Condition SetLengthEqual(RedisKey key, long length) /// <param name="key">The key of the set to check.</param>
{ /// <param name="length">The length the set must be equal to.</param>
return new LengthCondition(key, RedisType.Set, 0, length); public static Condition SetLengthEqual(RedisKey key, long length) => new LengthCondition(key, RedisType.Set, 0, length);
}
/// <summary> /// <summary>
/// Enforces that the given set cardinality is less than a certain value /// Enforces that the given set cardinality is less than a certain value
/// </summary> /// </summary>
public static Condition SetLengthLessThan(RedisKey key, long length) /// <param name="key">The key of the set to check.</param>
{ /// <param name="length">The length the set must be less than.</param>
return new LengthCondition(key, RedisType.Set, 1, length); public static Condition SetLengthLessThan(RedisKey key, long length) => new LengthCondition(key, RedisType.Set, 1, length);
}
/// <summary> /// <summary>
/// Enforces that the given set cardinality is greater than a certain value /// Enforces that the given set cardinality is greater than a certain value
/// </summary> /// </summary>
public static Condition SetLengthGreaterThan(RedisKey key, long length) /// <param name="key">The key of the set to check.</param>
{ /// <param name="length">The length the set must be greater than.</param>
return new LengthCondition(key, RedisType.Set, -1, length); public static Condition SetLengthGreaterThan(RedisKey key, long length) => new LengthCondition(key, RedisType.Set, -1, length);
}
/// <summary> /// <summary>
/// Enforces that the given set contains a certain member /// Enforces that the given set contains a certain member
/// </summary> /// </summary>
public static Condition SetContains(RedisKey key, RedisValue member) /// <param name="key">The key of the set to check.</param>
{ /// <param name="member">The member the set must contain.</param>
return new ExistsCondition(key, RedisType.Set, member, true); public static Condition SetContains(RedisKey key, RedisValue member) => new ExistsCondition(key, RedisType.Set, member, true);
}
/// <summary> /// <summary>
/// Enforces that the given set does not contain a certain member /// Enforces that the given set does not contain a certain member
/// </summary> /// </summary>
public static Condition SetNotContains(RedisKey key, RedisValue member) /// <param name="key">The key of the set to check.</param>
{ /// <param name="member">The member the set must not contain.</param>
return new ExistsCondition(key, RedisType.Set, member, false); public static Condition SetNotContains(RedisKey key, RedisValue member) => new ExistsCondition(key, RedisType.Set, member, false);
}
/// <summary> /// <summary>
/// Enforces that the given sorted set cardinality is a certain value /// Enforces that the given sorted set cardinality is a certain value
/// </summary> /// </summary>
public static Condition SortedSetLengthEqual(RedisKey key, long length) /// <param name="key">The key of the sorted set to check.</param>
{ /// <param name="length">The length the sorted set must be equal to.</param>
return new LengthCondition(key, RedisType.SortedSet, 0, length); public static Condition SortedSetLengthEqual(RedisKey key, long length) => new LengthCondition(key, RedisType.SortedSet, 0, length);
}
/// <summary> /// <summary>
/// Enforces that the given sorted set cardinality is less than a certain value /// Enforces that the given sorted set cardinality is less than a certain value
/// </summary> /// </summary>
public static Condition SortedSetLengthLessThan(RedisKey key, long length) /// <param name="key">The key of the sorted set to check.</param>
{ /// <param name="length">The length the sorted set must be less than.</param>
return new LengthCondition(key, RedisType.SortedSet, 1, length); public static Condition SortedSetLengthLessThan(RedisKey key, long length) => new LengthCondition(key, RedisType.SortedSet, 1, length);
}
/// <summary> /// <summary>
/// Enforces that the given sorted set cardinality is greater than a certain value /// Enforces that the given sorted set cardinality is greater than a certain value
/// </summary> /// </summary>
public static Condition SortedSetLengthGreaterThan(RedisKey key, long length) /// <param name="key">The key of the sorted set to check.</param>
{ /// <param name="length">The length the sorted set must be greater than.</param>
return new LengthCondition(key, RedisType.SortedSet, -1, length); public static Condition SortedSetLengthGreaterThan(RedisKey key, long length) => new LengthCondition(key, RedisType.SortedSet, -1, length);
}
/// <summary> /// <summary>
/// Enforces that the given sorted set contains a certain member /// Enforces that the given sorted set contains a certain member
/// </summary> /// </summary>
public static Condition SortedSetContains(RedisKey key, RedisValue member) /// <param name="key">The key of the sorted set to check.</param>
{ /// <param name="member">The member the sorted set must contain.</param>
return new ExistsCondition(key, RedisType.SortedSet, member, true); public static Condition SortedSetContains(RedisKey key, RedisValue member) => new ExistsCondition(key, RedisType.SortedSet, member, true);
}
/// <summary> /// <summary>
/// Enforces that the given sorted set does not contain a certain member /// Enforces that the given sorted set does not contain a certain member
/// </summary> /// </summary>
public static Condition SortedSetNotContains(RedisKey key, RedisValue member) /// <param name="key">The key of the sorted set to check.</param>
{ /// <param name="member">The member the sorted set must not contain.</param>
return new ExistsCondition(key, RedisType.SortedSet, member, false); public static Condition SortedSetNotContains(RedisKey key, RedisValue member) => new ExistsCondition(key, RedisType.SortedSet, member, false);
}
internal abstract void CheckCommands(CommandMap commandMap); internal abstract void CheckCommands(CommandMap commandMap);
internal abstract IEnumerable<Message> CreateMessages(int db, ResultBox resultBox); internal abstract IEnumerable<Message> CreateMessages(int db, ResultBox resultBox);
...@@ -289,8 +277,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes ...@@ -289,8 +277,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
{ {
var msg = message as ConditionMessage; var msg = message as ConditionMessage;
var condition = msg?.Condition; var condition = msg?.Condition;
bool final; if (condition != null && condition.TryValidate(result, out bool final))
if (condition != null && condition.TryValidate(result, out final))
{ {
SetResult(message, final); SetResult(message, final);
return true; return true;
...@@ -339,6 +326,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map) ...@@ -339,6 +326,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map)
{ {
return new ExistsCondition(map(key), type, expectedValue, expectedResult); return new ExistsCondition(map(key), type, expectedValue, expectedResult);
} }
public ExistsCondition(RedisKey key, RedisType type, RedisValue expectedValue, bool expectedResult) public ExistsCondition(RedisKey key, RedisType type, RedisValue expectedValue, bool expectedResult)
{ {
if (key.IsNull) throw new ArgumentException("key"); if (key.IsNull) throw new ArgumentException("key");
...@@ -376,10 +364,7 @@ public override string ToString() ...@@ -376,10 +364,7 @@ public override string ToString()
+ (expectedResult ? " exists" : " does not exists"); + (expectedResult ? " exists" : " does not exists");
} }
internal override void CheckCommands(CommandMap commandMap) internal override void CheckCommands(CommandMap commandMap) => commandMap.AssertAvailable(cmd);
{
commandMap.AssertAvailable(cmd);
}
internal override IEnumerable<Message> CreateMessages(int db, ResultBox resultBox) internal override IEnumerable<Message> CreateMessages(int db, ResultBox resultBox)
{ {
...@@ -390,13 +375,12 @@ internal override IEnumerable<Message> CreateMessages(int db, ResultBox resultBo ...@@ -390,13 +375,12 @@ internal override IEnumerable<Message> CreateMessages(int db, ResultBox resultBo
yield return message; yield return message;
} }
internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) => serverSelectionStrategy.HashSlot(key);
{
return serverSelectionStrategy.HashSlot(key);
}
internal override bool TryValidate(RawResult result, out bool value) internal override bool TryValidate(RawResult result, out bool value)
{ {
switch (type) { switch (type)
{
case RedisType.SortedSet: case RedisType.SortedSet:
var parsedValue = result.AsRedisValue(); var parsedValue = result.AsRedisValue();
value = (parsedValue.IsNull != expectedResult); value = (parsedValue.IsNull != expectedResult);
...@@ -419,11 +403,11 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -419,11 +403,11 @@ internal override bool TryValidate(RawResult result, out bool value)
internal class EqualsCondition : Condition internal class EqualsCondition : Condition
{ {
internal override Condition MapKeys(Func<RedisKey,RedisKey> map) internal override Condition MapKeys(Func<RedisKey,RedisKey> map)
{ {
return new EqualsCondition(map(key), hashField, expectedEqual, expectedValue); return new EqualsCondition(map(key), hashField, expectedEqual, expectedValue);
} }
private readonly bool expectedEqual; private readonly bool expectedEqual;
private readonly RedisValue hashField, expectedValue; private readonly RedisValue hashField, expectedValue;
private readonly RedisKey key; private readonly RedisKey key;
...@@ -462,6 +446,7 @@ internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrateg ...@@ -462,6 +446,7 @@ internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrateg
{ {
return serverSelectionStrategy.HashSlot(key); return serverSelectionStrategy.HashSlot(key);
} }
internal override bool TryValidate(RawResult result, out bool value) internal override bool TryValidate(RawResult result, out bool value)
{ {
switch (result.Type) switch (result.Type)
...@@ -486,6 +471,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map) ...@@ -486,6 +471,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map)
{ {
return new ListCondition(map(key), index, expectedResult, expectedValue); return new ListCondition(map(key), index, expectedResult, expectedValue);
} }
private readonly bool expectedResult; private readonly bool expectedResult;
private readonly long index; private readonly long index;
private readonly RedisValue? expectedValue; private readonly RedisValue? expectedValue;
...@@ -519,10 +505,8 @@ internal sealed override IEnumerable<Message> CreateMessages(int db, ResultBox r ...@@ -519,10 +505,8 @@ internal sealed override IEnumerable<Message> CreateMessages(int db, ResultBox r
yield return message; yield return message;
} }
internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) => serverSelectionStrategy.HashSlot(key);
{
return serverSelectionStrategy.HashSlot(key);
}
internal override bool TryValidate(RawResult result, out bool value) internal override bool TryValidate(RawResult result, out bool value)
{ {
switch (result.Type) switch (result.Type)
...@@ -555,6 +539,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map) ...@@ -555,6 +539,7 @@ internal override Condition MapKeys(Func<RedisKey,RedisKey> map)
{ {
return new LengthCondition(map(key), type, compareToResult, expectedLength); return new LengthCondition(map(key), type, compareToResult, expectedLength);
} }
private readonly int compareToResult; private readonly int compareToResult;
private readonly long expectedLength; private readonly long expectedLength;
private readonly RedisKey key; private readonly RedisKey key;
...@@ -622,6 +607,7 @@ internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrateg ...@@ -622,6 +607,7 @@ internal override int GetHashSlot(ServerSelectionStrategy serverSelectionStrateg
{ {
return serverSelectionStrategy.HashSlot(key); return serverSelectionStrategy.HashSlot(key);
} }
internal override bool TryValidate(RawResult result, out bool value) internal override bool TryValidate(RawResult result, out bool value)
{ {
switch (result.Type) switch (result.Type)
...@@ -639,7 +625,6 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -639,7 +625,6 @@ internal override bool TryValidate(RawResult result, out bool value)
return false; return false;
} }
} }
} }
/// <summary> /// <summary>
...@@ -664,19 +649,14 @@ internal ConditionResult(Condition condition) ...@@ -664,19 +649,14 @@ internal ConditionResult(Condition condition)
/// </summary> /// </summary>
public bool WasSatisfied => wasSatisfied; public bool WasSatisfied => wasSatisfied;
internal IEnumerable<Message> CreateMessages(int db) internal IEnumerable<Message> CreateMessages(int db) => Condition.CreateMessages(db, resultBox);
{
return Condition.CreateMessages(db, resultBox);
}
internal ResultBox<bool> GetBox() { return resultBox; } internal ResultBox<bool> GetBox() { return resultBox; }
internal bool UnwrapBox() internal bool UnwrapBox()
{ {
if (resultBox != null) if (resultBox != null)
{ {
Exception ex; ResultBox<bool>.UnwrapAndRecycle(resultBox, false, out bool val, out Exception ex);
bool val;
ResultBox<bool>.UnwrapAndRecycle(resultBox, false, out val, out ex);
resultBox = null; resultBox = null;
wasSatisfied = ex == null && val; wasSatisfied = ex == null && val;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment