You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Be allowed only on options and arguments, clarifying their use
Would require that the passed value match the generic of the option or argument, making using invalid default values, converters, validators, etc. not possible
And example is default values which are stored as object?
While it would be nice to store the specific value, rather than the general one, I do not see a way that is possible. However, I think the code below would solve the two problems above:
publicstruct ValueAnnotationAccessor<TValue>(CliSubsystem owner,AnnotationId<TValue> id){/// <summary>/// The ID of the annotation/// </summary>publicAnnotationId<TValue>Id{ get;}publicreadonlyvoidSet<TSymbolValue>(CliOption<TSymbolValue>symbol,TSymbolValuevalue)whereTSymbolValue:TValue=> owner.SetAnnotation(symbol, id, value);publicreadonlyvoidSet<TSymbolValue>(CliArgument<TSymbolValue>symbol,TSymbolValuevalue)whereTSymbolValue:TValue=> owner.SetAnnotation(symbol, id, value);publicreadonlyboolTryGet(CliSymbolsymbol,[NotNullWhen(true)]outTValue?value)=> owner.TryGetAnnotation(symbol, id,out value);}
If we wish this to be polymorphic with other AnnotationAccessors, it could derive from it, in which case it could also drop SetAnnotation
The text was updated successfully, but these errors were encountered:
[NotNullWhen(true)] out TValue? value seems strange. What if I have a nullable type (e.g. string?) as TValue and store null, and then query with TryGet; does that assign value = null and return true, thus claiming that value is not null after all? I imagine this should instead be [MaybeNullWhen(false)] out TValue value, like in Dictionary<TKey, TValue>.TryGetValue.
Value annotation accessors would do two things:
And example is default values which are stored as
object?
While it would be nice to store the specific value, rather than the general one, I do not see a way that is possible. However, I think the code below would solve the two problems above:
If we wish this to be polymorphic with other AnnotationAccessors, it could derive from it, in which case it could also drop
SetAnnotation
The text was updated successfully, but these errors were encountered: