public bool TryGetValue(FunctionAttributeIndex key, out ICollection <AttributeValue> value) { value = default; if (ContainsKey(key)) { return(false); } value = new ValueAttributeCollection(Container, key); return(true); }
#pragma warning disable CS8767 // IReadOnlyDictionary<TKey,TValue> interface does not have nullability attributes in netstandard2.1, this suppression could be removed after move to .NET 5 public bool TryGetValue(FunctionAttributeIndex key, [MaybeNullWhen(false)] out ICollection <AttributeValue> value) #pragma warning restore CS8767 { value = default; if (this.ContainsKey(key)) { return(false); } value = new ValueAttributeCollection(this.container, key); return(true); }
public bool TryGetValue(FunctionAttributeIndex key, /*[MaybeNullWhen( false )]*/ out ICollection <AttributeValue> value) { // sadly the runtime provided interface doesn't correctly apply the MaybeNullWhen attribute, // and the compiler generates warning: // CS8767: Nullability of reference types in type of parameter 'value' of 'bool ValueAttributeDictionary.TryGetValue(FunctionAttributeIndex key, out ICollection<AttributeValue> value)' doesn't match implicitly implemented member 'bool IReadOnlyDictionary<FunctionAttributeIndex, ICollection<AttributeValue>>.TryGetValue(FunctionAttributeIndex key, out ICollection<AttributeValue> value)' because of nullability attributes. // Yeah, clear as mud, right? // So, use the ! to silence the compiler and don't use the attribute, sigh... what a mess... value = null !; if (ContainsKey(key)) { return(false); } value = new ValueAttributeCollection(Container, key); return(true); }