Making Functions working with Lazy<T>
trimmer friendly
#69486
-
I'm trying to make these two functions trimmer friendly: public static class Lazy
{
public static Lazy<TItem> Return<TItem>(TItem value) => new(value);
public static Lazy<TResult> Select<T, TResult>(this Lazy<T> lazy, Func<T, TResult> selector)
=> new(() => selector(lazy.Value));
}
Is it OK to use I think it should be OK because:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think in this case it's probably safe, but I would still suggest considering annotating the generic arguments of your methods to avoid the suppression. Suppressions are very tricky to get right and even if they are right at the time you add them, they may not be forever. If somebody changes the code to actually do call the public parameterless .ctor there will still be no warning (because of the suppression) and suddenly things will break. I vaguely remember us discussing that some .ctors of |
Beta Was this translation helpful? Give feedback.
I think in this case it's probably safe, but I would still suggest considering annotating the generic arguments of your methods to avoid the suppression. Suppressions are very tricky to get right and even if they are right at the time you add them, they may not be forever. If somebody changes the code to actually do call the public parameterless .ctor there will still be no warning (because of the suppression) and suddenly things will break.
I vaguely remember us discussing that some .ctors of
Lazy
don't need the annotation (as you mention), but currently there's no good way to express this fact in the language/attributes.