Use null-coalescing compound assignment for caches. (#295)

I didn't know this was possible before. It's neater so let's use it consistenly.
This commit is contained in:
Simeon 2020-06-16 21:41:25 -07:00 коммит произвёл GitHub
Родитель d8e194d278
Коммит d21f426974
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 6 добавлений и 7 удалений

Просмотреть файл

@ -30,7 +30,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.GenericData
: result;
}
public static GenericDataList Empty => s_empty ?? (s_empty = new GenericDataList(Array.Empty<GenericDataObject>()));
public static GenericDataList Empty => s_empty ??= new GenericDataList(Array.Empty<GenericDataObject>());
public GenericDataObject this[int index] => _items[index];

Просмотреть файл

@ -26,7 +26,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.GenericData
? Empty
: new GenericDataMap(items);
public static GenericDataMap Empty => s_empty ?? (s_empty = new GenericDataMap(new Dictionary<string, GenericDataObject>(0)));
public static GenericDataMap Empty => s_empty ??= new GenericDataMap(new Dictionary<string, GenericDataObject>(0));
public GenericDataObject this[string key] => _items[key];

Просмотреть файл

@ -4579,7 +4579,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
void EnsureColorThemePropertyExists(TranslationContext context, string bindingName, Color defaultValue)
{
// Create a theme property set if one hasn't been created yet.
var themeProperties = _themePropertySet ?? (_themePropertySet = _c.CreatePropertySet());
var themeProperties = _themePropertySet ??= _c.CreatePropertySet();
var defaultValueAsWinUIColor = Color(defaultValue);
var defaultValueAsVector4 = Vector4(defaultValueAsWinUIColor);
@ -4618,7 +4618,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
void EnsureScalarThemePropertyExists(string bindingName, double defaultValue)
{
// Create a theme property set if one hasn't been created yet.
var themeProperties = _themePropertySet ?? (_themePropertySet = _c.CreatePropertySet());
var themeProperties = _themePropertySet ??= _c.CreatePropertySet();
var defaultValueAsFloat = Float(defaultValue);

Просмотреть файл

@ -23,13 +23,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Expressions
/// Gets a simplified form of the expression. May be the same as this.
/// </summary>
// Expressions are immutable, so it's always safe to return a cached version.
public T Simplified => _simplifiedExpressionCache ?? (_simplifiedExpressionCache = Simplify());
public T Simplified => _simplifiedExpressionCache ??= Simplify();
/// <inheritdoc/>
// Expressions are immutable, so it's always safe to return a cached version.
// Always return the simplified version.
public override string ToText()
=> _expressionTextCache ?? (_expressionTextCache = Simplified.CreateExpressionText());
public override string ToText() => _expressionTextCache ??= Simplified.CreateExpressionText();
protected virtual T Simplify() => (T)this;