mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 14:28:47 +00:00
docs: explain use of ref return
This commit is contained in:
parent
4a0e3c10d7
commit
8e6796607c
@ -54,6 +54,8 @@ public static class DictionaryExtensions
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
ref var value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
|
||||
// DO NOT CHANGE. reassigning value is necessary to mutate the dictionary, due to ref return above.
|
||||
// mutation of the dictionary is INTENDED BEHAVIOUR. this is not a mistake.
|
||||
return value = exists ? updateValueFactory(key, value!) : addValue;
|
||||
#else
|
||||
if (dictionary.TryGetValue(key, out TValue? old))
|
||||
@ -173,6 +175,8 @@ public static class DictionaryExtensions
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
|
||||
// DO NOT CHANGE. reassigning value is necessary to mutate the dictionary, due to ref return above.
|
||||
// mutation of the dictionary is INTENDED BEHAVIOUR. this is not a mistake.
|
||||
return value = exists ? updateValueFactory(key, value!) : addValueFactory(key);
|
||||
#else
|
||||
if (dictionary.TryGetValue(key, out TValue? old))
|
||||
@ -310,6 +314,8 @@ public static class DictionaryExtensions
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
ref TValue? value = ref CollectionsMarshal.GetValueRefOrAddDefault(dictionary, key, out bool exists);
|
||||
// DO NOT CHANGE. reassigning value is necessary to mutate the dictionary, due to ref return above.
|
||||
// mutation of the dictionary is INTENDED BEHAVIOUR. this is not a mistake.
|
||||
return value = exists ? updateValueFactory(key, value!, factoryArgument) : addValueFactory(key, factoryArgument);
|
||||
#else
|
||||
if (dictionary.TryGetValue(key, out TValue? old))
|
||||
|
Loading…
Reference in New Issue
Block a user