I'm thinking about using the new type MaybeValue<T> - introduced for the new failSafeDefaultValue in the GetOrSet method - also as the return value of the TryGetResult<T> method.
The basic rationale behind this is unification of the "maybe a value, maybe not" concept.
The main difference from now would be that TryGetResult<T> implicitly converts to a bool (the idea was to use that in an if statement) whereas MaybeValue<T> implicitly converts to/from a T value, much like a Nullable<T>. But, just like a Nullable<T>, it does have an HasValue property for easy checks, so it should not be that problematic.
In practice, before we should have done one of these:
// ASSIGNMENT + IMPLICIT CONVERSION TO bool, KINDA WEIRD
TryGetResult<int> foo;
if (foo = cache.TryGet<int>("foo"))
{
var value = foo.Value;
}
// ASSIGNMENT DONE BEFORE
var foo = cache.TryGet<int>("foo");
if (foo)
{
var value = foo.Value;
}
whereas now we can do one of these:
var foo = cache.TryGet<int>("foo");
if (foo.HasValue) // EXPLICIT .HasValue CHECK
{
// EXPLICIT .Value USAGE
var value = foo.Value;
// OR IMPLICIT CONVERSION, LIKE WITH A Nullable<T>
var value = foo;
}
// OR .GetValueOrDefault(123) USAGE, LIKE A Nullable<T>
var foo = cache.TryGet<int>("foo");
var value = foo.GetValueOrDefault(123);
Even though FusionCache is still in the 0.X version phase (so can have breaking changes), just in case of existing usage of the TryGet[Async] method in someone else's code I can easily add the old Success prop marked as Obsolete with an explanation on how to use the new thing. Maybe some pieces of code with a direct check in an if statement would stop compiling, but that would be resolved by simply adding .HasValue.
I'm thinking about using the new type
MaybeValue<T>
- introduced for the newfailSafeDefaultValue
in theGetOrSet
method - also as the return value of theTryGetResult<T>
method.The basic rationale behind this is unification of the "maybe a value, maybe not" concept.
The main difference from now would be that
TryGetResult<T>
implicitly converts to abool
(the idea was to use that in anif
statement) whereasMaybeValue<T>
implicitly converts to/from aT
value, much like aNullable<T>
. But, just like aNullable<T>
, it does have anHasValue
property for easy checks, so it should not be that problematic.In practice, before we should have done one of these:
whereas now we can do one of these:
Even though FusionCache is still in the
0.X
version phase (so can have breaking changes), just in case of existing usage of theTryGet[Async]
method in someone else's code I can easily add the oldSuccess
prop marked asObsolete
with an explanation on how to use the new thing. Maybe some pieces of code with a direct check in anif
statement would stop compiling, but that would be resolved by simply adding.HasValue
.Opinions?