Clarify usage of IUnionMembers interface - #55183
Conversation
clarify Union member providers
BillWagner
left a comment
There was a problem hiding this comment.
Hi @BarionLP
This is a good start. I'd like to see the example updated to include the additional members. So, instead of:
[System.Runtime.CompilerServices.Union]
public record class Outcome<T> : Outcome<T>.IUnionMembers
{
private readonly object? _value;
private Outcome(object? value) => _value = value;
public interface IUnionMembers
{
static Outcome<T> Create(T? value) => new(value);
static Outcome<T> Create(Exception? value) => new(value);
object? Value { get; }
}
object? IUnionMembers.Value => _value;
}The sample should include:
[System.Runtime.CompilerServices.Union]
public record class Outcome<T> : Outcome<T>.IUnionMembers
{
private readonly object? _value;
private Outcome(object? value) => _value = value;
public interface IUnionMembers
{
static Outcome<T> Create(T? value) => new(value);
static Outcome<T> Create(Exception? value) => new(value);
object? Value { get; }
bool TryGetValue(out T value);
bool TryGetValue(out Exception value);
}
object? IUnionMembers.Value => _value;
}Can you add that as well?
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
|
@BillWagner while changing this i noticed the current example has a bug. |
@BarionLP This is interesting. I want to loop in @333fred and @AlekseyTs on this part. I had thought making the record type Everything looks good, but I'd like to get their thoughts before we finalize and merge this. |
|
I suggest including explicit cast to And the type should implement |
will do |
|
Perhaps the example shouldn't use |
i turned it into a struct (which is what i would do in this case and most union use cases i think) |
Thanks @BarionLP |
BillWagner
left a comment
There was a problem hiding this comment.
Thanks for working through this with all of us @BarionLP
I'll
now. You should see the changes on the live site in the next day or so, on our regular publishing cycle.
Summary
clarify that all union members must be part of the interface
so far the paragraph mostly talks about factory methods.
Internal previews