Răsfoiți Sursa

Merge pull request #1394 from dotnet/dev/bartde/deconstruct

Support deconstruction on some types.
Bart J.F. De Smet 5 ani în urmă
părinte
comite
24a9950553

+ 7 - 0
Rx.NET/Source/src/System.Reactive/EventPattern.cs

@@ -51,6 +51,13 @@ namespace System.Reactive
         /// </summary>
         public TEventArgs EventArgs { get; }
 
+        /// <summary>
+        /// Deconstructs the event pattern value into a sender and event data.
+        /// </summary>
+        /// <param name="sender">The sender object that raised the event.</param>
+        /// <param name="e">The event data that was generated by the event.</param>
+        public void Deconstruct(out TSender sender, out TEventArgs e) => (sender, e) = (Sender, EventArgs);
+
         /// <summary>
         /// Determines whether the current <see cref="EventPattern{TSender, TEventArgs}"/> object represents the same event as a specified <see cref="EventPattern{TSender, TEventArgs}"/> object.
         /// </summary>

+ 7 - 0
Rx.NET/Source/src/System.Reactive/TimeInterval.cs

@@ -38,6 +38,13 @@ namespace System.Reactive
         /// </summary>
         public TimeSpan Interval { get; }
 
+        /// <summary>
+        /// Deconstructs the time interval value into a value and a time interval.
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <param name="interval">Time interval associated with the value.</param>
+        public void Deconstruct(out T value, out TimeSpan interval) => (value, interval) = (Value, Interval);
+
         /// <summary>
         /// Determines whether the current <see cref="TimeInterval{T}"/> value has the same <see cref="Value"/> and <see cref="Interval"/> as a specified <see cref="TimeInterval{T}"/> value.
         /// </summary>

+ 7 - 0
Rx.NET/Source/src/System.Reactive/Timestamped.cs

@@ -39,6 +39,13 @@ namespace System.Reactive
         /// </summary>
         public DateTimeOffset Timestamp { get; }
 
+        /// <summary>
+        /// Deconstructs the timestamped value into a value and a timestamp.
+        /// </summary>
+        /// <param name="value">The value.</param>
+        /// <param name="timestamp">Timestamp associated with the value.</param>
+        public void Deconstruct(out T value, out DateTimeOffset timestamp) => (value, timestamp) = (Value, Timestamp);
+
         /// <summary>
         /// Determines whether the current <see cref="Timestamped{T}" /> value has the same <see cref="Value"/> and <see cref="Timestamp"/> as a specified <see cref="Timestamped{T}" /> value.
         /// </summary>

+ 3 - 0
Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.verified.cs

@@ -54,6 +54,7 @@ namespace System.Reactive
         public EventPattern(TSender? sender, TEventArgs e) { }
         public TEventArgs EventArgs { get; }
         public TSender Sender { get; }
+        public void Deconstruct(out TSender sender, out TEventArgs e) { }
         public bool Equals(System.Reactive.EventPattern<TSender, TEventArgs>? other) { }
         public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
@@ -189,6 +190,7 @@ namespace System.Reactive
         public TimeInterval(T value, System.TimeSpan interval) { }
         public System.TimeSpan Interval { get; }
         public T Value { get; }
+        public void Deconstruct(out T value, out System.TimeSpan interval) { }
         public bool Equals(System.Reactive.TimeInterval<T> other) { }
         public override bool Equals(object? obj) { }
         public override int GetHashCode() { }
@@ -206,6 +208,7 @@ namespace System.Reactive
         public Timestamped(T value, System.DateTimeOffset timestamp) { }
         public System.DateTimeOffset Timestamp { get; }
         public T Value { get; }
+        public void Deconstruct(out T value, out System.DateTimeOffset timestamp) { }
         public bool Equals(System.Reactive.Timestamped<T> other) { }
         public override bool Equals(object? obj) { }
         public override int GetHashCode() { }