浏览代码

Using some C# 6.0 features.

Bart De Smet 8 年之前
父节点
当前提交
09433d88b6

+ 3 - 10
Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs

@@ -15,7 +15,6 @@ namespace System.Reactive.Concurrency
         where TAbsolute : IComparable<TAbsolute>
     {
         private readonly SingleAssignmentDisposable _disposable = new SingleAssignmentDisposable();
-        private readonly TAbsolute _dueTime;
         private readonly IComparer<TAbsolute> _comparer;
 
         /// <summary>
@@ -29,17 +28,14 @@ namespace System.Reactive.Concurrency
             if (comparer == null)
                 throw new ArgumentNullException(nameof(comparer));
 
-            _dueTime = dueTime;
+            DueTime = dueTime;
             _comparer = comparer;
         }
 
         /// <summary>
         /// Gets the absolute time at which the item is due for invocation.
         /// </summary>
-        public TAbsolute DueTime
-        {
-            get { return _dueTime; }
-        }
+        public TAbsolute DueTime { get; }
 
         /// <summary>
         /// Invokes the work item.
@@ -181,10 +177,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// Gets whether the work item has received a cancellation request.
         /// </summary>
-        public bool IsCanceled
-        {
-            get { return _disposable.IsDisposed; }
-        }
+        public bool IsCanceled => _disposable.IsDisposed;
     }
 
     /// <summary>

+ 1 - 4
Rx.NET/Source/src/System.Reactive/Disposables/AnonymousDisposable.cs

@@ -27,10 +27,7 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _dispose == null; }
-        }
+        public bool IsDisposed => _dispose == null;
 
         /// <summary>
         /// Calls the disposal action if and only if the current instance hasn't been disposed yet.

+ 1 - 4
Rx.NET/Source/src/System.Reactive/Disposables/BooleanDisposable.cs

@@ -31,10 +31,7 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _isDisposed; }
-        }
+        public bool IsDisposed => _isDisposed;
 
         /// <summary>
         /// Sets the status to disposed, which can be observer through the <see cref="IsDisposed"/> property.

+ 4 - 10
Rx.NET/Source/src/System.Reactive/Disposables/CancellationDisposable.cs

@@ -17,7 +17,7 @@ namespace System.Reactive.Disposables
         /// Initializes a new instance of the <see cref="CancellationDisposable"/> class that uses an existing <seealso cref="CancellationTokenSource"/>.
         /// </summary>
         /// <param name="cts"><seealso cref="CancellationTokenSource"/> used for cancellation.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="cts"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="cts"/> is <c>null</c>.</exception>
         public CancellationDisposable(CancellationTokenSource cts)
         {
             if (cts == null)
@@ -35,12 +35,9 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Gets the <see cref="CancellationToken"/> used by this CancellationDisposable.
+        /// Gets the <see cref="CancellationToken"/> used by this <see cref="CancellationDisposable"/>.
         /// </summary>
-        public CancellationToken Token
-        {
-            get { return _cts.Token; }
-        }
+        public CancellationToken Token => _cts.Token;
 
         /// <summary>
         /// Cancels the underlying <seealso cref="CancellationTokenSource"/>.
@@ -53,9 +50,6 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _cts.IsCancellationRequested; }
-        }
+        public bool IsDisposed => _cts.IsCancellationRequested;
     }
 }

+ 12 - 27
Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs

@@ -75,18 +75,12 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Gets the number of disposables contained in the CompositeDisposable.
+        /// Gets the number of disposables contained in the <see cref="CompositeDisposable"/>.
         /// </summary>
-        public int Count
-        {
-            get
-            {
-                return _count;
-            }
-        }
+        public int Count => _count;
 
         /// <summary>
-        /// Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
+        /// Adds a disposable to the <see cref="CompositeDisposable"/> or disposes the disposable if the <see cref="CompositeDisposable"/> is disposed.
         /// </summary>
         /// <param name="item">Disposable to add.</param>
         /// <exception cref="ArgumentNullException"><paramref name="item"/> is null.</exception>
@@ -110,7 +104,7 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
+        /// Removes and disposes the first occurrence of a disposable from the <see cref="CompositeDisposable"/>.
         /// </summary>
         /// <param name="item">Disposable to remove.</param>
         /// <returns>true if found; false otherwise.</returns>
@@ -185,7 +179,7 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Removes and disposes all disposables from the CompositeDisposable, but does not dispose the CompositeDisposable.
+        /// Removes and disposes all disposables from the <see cref="CompositeDisposable"/>, but does not dispose the <see cref="CompositeDisposable"/>.
         /// </summary>
         public void Clear()
         {
@@ -203,7 +197,7 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Determines whether the CompositeDisposable contains a specific disposable.
+        /// Determines whether the <see cref="CompositeDisposable"/> contains a specific disposable.
         /// </summary>
         /// <param name="item">Disposable to search for.</param>
         /// <returns>true if the disposable was found; otherwise, false.</returns>
@@ -220,7 +214,7 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Copies the disposables contained in the CompositeDisposable to an array, starting at a particular array index.
+        /// Copies the disposables contained in the <see cref="CompositeDisposable"/> to an array, starting at a particular array index.
         /// </summary>
         /// <param name="array">Array to copy the contained disposables to.</param>
         /// <param name="arrayIndex">Target index at which to copy the first disposable of the group.</param>
@@ -242,13 +236,10 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Always returns false.
         /// </summary>
-        public bool IsReadOnly
-        {
-            get { return false; }
-        }
+        public bool IsReadOnly => false;
 
         /// <summary>
-        /// Returns an enumerator that iterates through the CompositeDisposable.
+        /// Returns an enumerator that iterates through the <see cref="CompositeDisposable"/>.
         /// </summary>
         /// <returns>An enumerator to iterate over the disposables.</returns>
         public IEnumerator<IDisposable> GetEnumerator()
@@ -264,20 +255,14 @@ namespace System.Reactive.Disposables
         }
 
         /// <summary>
-        /// Returns an enumerator that iterates through the CompositeDisposable.
+        /// Returns an enumerator that iterates through the <see cref="CompositeDisposable"/>.
         /// </summary>
         /// <returns>An enumerator to iterate over the disposables.</returns>
-        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
-        {
-            return GetEnumerator();
-        }
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
 
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _disposed; }
-        }
+        public bool IsDisposed => _disposed;
     }
 }

+ 4 - 11
Rx.NET/Source/src/System.Reactive/Disposables/ContextDisposable.cs

@@ -12,7 +12,6 @@ namespace System.Reactive.Disposables
     /// </summary>
     public sealed class ContextDisposable : ICancelable
     {
-        private readonly SynchronizationContext _context;
         private volatile IDisposable _disposable;
 
         /// <summary>
@@ -28,25 +27,19 @@ namespace System.Reactive.Disposables
             if (disposable == null)
                 throw new ArgumentNullException(nameof(disposable));
 
-            _context = context;
+            Context = context;
             _disposable = disposable;
         }
 
         /// <summary>
         /// Gets the provided <see cref="SynchronizationContext"/>.
         /// </summary>
-        public SynchronizationContext Context
-        {
-            get { return _context; }
-        }
+        public SynchronizationContext Context { get; }
 
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _disposable == BooleanDisposable.True; }
-        }
+        public bool IsDisposed => _disposable == BooleanDisposable.True;
 
         /// <summary>
         /// Disposes the underlying disposable on the provided <see cref="SynchronizationContext"/>.
@@ -57,7 +50,7 @@ namespace System.Reactive.Disposables
 
             if (disposable != BooleanDisposable.True)
             {
-                _context.PostWithStartComplete(d => d.Dispose(), disposable);
+                Context.PostWithStartComplete(d => d.Dispose(), disposable);
             }
         }
     }

+ 3 - 6
Rx.NET/Source/src/System.Reactive/Disposables/Disposable.cs

@@ -5,24 +5,21 @@
 namespace System.Reactive.Disposables
 {
     /// <summary>
-    /// Provides a set of static methods for creating Disposables.
+    /// Provides a set of static methods for creating <see cref="IDisposable"/> objects.
     /// </summary>
     public static class Disposable
     {
         /// <summary>
         /// Gets the disposable that does nothing when disposed.
         /// </summary>
-        public static IDisposable Empty
-        {
-            get { return DefaultDisposable.Instance; }
-        }
+        public static IDisposable Empty => DefaultDisposable.Instance;
 
         /// <summary>
         /// Creates a disposable object that invokes the specified action when disposed.
         /// </summary>
         /// <param name="dispose">Action to run during the first call to <see cref="IDisposable.Dispose"/>. The action is guaranteed to be run at most once.</param>
         /// <returns>The disposable object that runs the given action upon disposal.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="dispose"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="dispose"/> is <c>null</c>.</exception>
         public static IDisposable Create(Action dispose)
         {
             if (dispose == null)

+ 1 - 4
Rx.NET/Source/src/System.Reactive/Disposables/RefCountDisposable.cs

@@ -46,10 +46,7 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _disposable == null; }
-        }
+        public bool IsDisposed => _disposable == null;
 
         /// <summary>
         /// Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.

+ 3 - 10
Rx.NET/Source/src/System.Reactive/Disposables/ScheduledDisposable.cs

@@ -12,7 +12,6 @@ namespace System.Reactive.Disposables
     /// </summary>
     public sealed class ScheduledDisposable : ICancelable
     {
-        private readonly IScheduler _scheduler;
         private volatile IDisposable _disposable;
 
         /// <summary>
@@ -28,17 +27,14 @@ namespace System.Reactive.Disposables
             if (disposable == null)
                 throw new ArgumentNullException(nameof(disposable));
 
-            _scheduler = scheduler;
+            Scheduler = scheduler;
             _disposable = disposable;
         }
 
         /// <summary>
         /// Gets the scheduler where the disposable resource will be disposed on.
         /// </summary>
-        public IScheduler Scheduler
-        {
-            get { return _scheduler; }
-        }
+        public IScheduler Scheduler { get; }
 
         /// <summary>
         /// Gets the underlying disposable. After disposal, the result is undefined.
@@ -59,10 +55,7 @@ namespace System.Reactive.Disposables
         /// <summary>
         /// Gets a value that indicates whether the object is disposed.
         /// </summary>
-        public bool IsDisposed
-        {
-            get { return _disposable == BooleanDisposable.True; }
-        }
+        public bool IsDisposed => _disposable == BooleanDisposable.True;
 
         /// <summary>
         /// Disposes the wrapped disposable on the provided scheduler.

+ 2 - 14
Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs

@@ -78,13 +78,7 @@ namespace System.Reactive.Disposables
                 _disposable2 = disposable2;
             }
 
-            public override bool IsDisposed
-            {
-                get
-                {
-                    return _disposable1 == null;
-                }
-            }
+            public override bool IsDisposed => _disposable1 == null;
 
             public override void Dispose()
             {
@@ -122,13 +116,7 @@ namespace System.Reactive.Disposables
                     throw new ArgumentException(Strings_Core.DISPOSABLES_CANT_CONTAIN_NULL, nameof(disposables));
             }
 
-            public override bool IsDisposed
-            {
-                get
-                {
-                    return _disposables == null;
-                }
-            }
+            public override bool IsDisposed => _disposables == null;
 
             public override void Dispose()
             {

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

@@ -44,18 +44,18 @@ namespace System.Reactive
         /// <summary>
         /// Gets the sender object that raised the event.
         /// </summary>
-        public TSender Sender { get; private set; }
+        public TSender Sender { get; }
 
         /// <summary>
         /// Gets the event data that was generated by the event.
         /// </summary>
-        public TEventArgs EventArgs { get; private set; }
+        public TEventArgs EventArgs { get; }
 
         /// <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>
         /// <param name="other">An object to compare to the current <see cref="EventPattern{TSender, TEventArgs}"/> object.</param>
-        /// <returns>true if both <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event; otherwise, false.</returns>
+        /// <returns><c>true</c> if both <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event; otherwise, <c>false</c>.</returns>
         public bool Equals(EventPattern<TSender, TEventArgs> other)
         {
             if (object.ReferenceEquals(null, other))
@@ -70,7 +70,7 @@ namespace System.Reactive
         /// Determines whether the specified System.Object is equal to the current <see cref="EventPattern{TSender, TEventArgs}"/>.
         /// </summary>
         /// <param name="obj">The System.Object to compare with the current <see cref="EventPattern{TSender, TEventArgs}"/>.</param>
-        /// <returns>true if the specified System.Object is equal to the current <see cref="EventPattern{TSender, TEventArgs}"/>; otherwise, false.</returns>
+        /// <returns><c>true</c> if the specified System.Object is equal to the current <see cref="EventPattern{TSender, TEventArgs}"/>; otherwise, <c>false</c>.</returns>
         public override bool Equals(object obj)
         {
             return Equals(obj as EventPattern<TSender, TEventArgs>);
@@ -90,9 +90,9 @@ namespace System.Reactive
         /// <summary>
         /// Determines whether two specified <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event.
         /// </summary>
-        /// <param name="first">The first <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or null.</param>
-        /// <param name="second">The second <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or null.</param>
-        /// <returns>true if both <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event; otherwise, false.</returns>
+        /// <param name="first">The first <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or <c>null</c>.</param>
+        /// <param name="second">The second <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or <c>null</c>.</param>
+        /// <returns><c>true</c> if both <see cref="EventPattern{TSender, TEventArgs}"/> objects represent the same event; otherwise, <c>false</c>.</returns>
         public static bool operator ==(EventPattern<TSender, TEventArgs> first, EventPattern<TSender, TEventArgs> second)
         {
             return object.Equals(first, second);
@@ -101,9 +101,9 @@ namespace System.Reactive
         /// <summary>
         /// Determines whether two specified <see cref="EventPattern{TSender, TEventArgs}"/> objects represent a different event.
         /// </summary>
-        /// <param name="first">The first <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or null.</param>
-        /// <param name="second">The second <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or null.</param>
-        /// <returns>true if both <see cref="EventPattern{TSender, TEventArgs}"/> objects don't represent the same event; otherwise, false.</returns>
+        /// <param name="first">The first <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or <c>null</c>.</param>
+        /// <param name="second">The second <see cref="EventPattern{TSender, TEventArgs}"/> to compare, or <c>null</c>.</param>
+        /// <returns><c>true</c> if both <see cref="EventPattern{TSender, TEventArgs}"/> objects don't represent the same event; otherwise, <c>false</c>.</returns>
         public static bool operator !=(EventPattern<TSender, TEventArgs> first, EventPattern<TSender, TEventArgs> second)
         {
             return !object.Equals(first, second);

+ 38 - 81
Rx.NET/Source/src/System.Reactive/Notification.cs

@@ -30,7 +30,7 @@ namespace System.Reactive
         /// <summary>
         /// Represents an OnCompleted notification.
         /// </summary>
-        OnCompleted
+        OnCompleted,
     }
 
     /// <summary>
@@ -53,34 +53,22 @@ namespace System.Reactive
         /// <summary>
         /// Returns the value of an OnNext notification or throws an exception.
         /// </summary>
-        public abstract T Value
-        {
-            get;
-        }
+        public abstract T Value { get; }
 
         /// <summary>
         /// Returns a value that indicates whether the notification has a value.
         /// </summary>
-        public abstract bool HasValue
-        {
-            get;
-        }
+        public abstract bool HasValue { get; }
 
         /// <summary>
-        /// Returns the exception of an OnError notification or returns null.
+        /// Returns the exception of an OnError notification or returns <c>null</c>.
         /// </summary>
-        public abstract Exception Exception
-        {
-            get;
-        }
+        public abstract Exception Exception { get; }
 
         /// <summary>
         /// Gets the kind of notification that is represented.
         /// </summary>
-        public abstract NotificationKind Kind
-        {
-            get;
-        }
+        public abstract NotificationKind Kind { get; }
 
         /// <summary>
         /// Represents an OnNext notification to an observer.
@@ -93,43 +81,38 @@ namespace System.Reactive
 #endif
         internal sealed class OnNextNotification : Notification<T>
         {
-            T value;
-
             /// <summary>
             /// Constructs a notification of a new value.
             /// </summary>
             public OnNextNotification(T value)
             {
-                this.value = value;
+                Value = value;
             }
 
             /// <summary>
             /// Returns the value of an OnNext notification.
             /// </summary>
-            public override T Value { get { return value; } }
+            public override T Value { get; }
 
             /// <summary>
-            /// Returns null.
+            /// Returns <c>null</c>.
             /// </summary>
-            public override Exception Exception { get { return null; } }
+            public override Exception Exception => null;
 
             /// <summary>
-            /// Returns true.
+            /// Returns <c>true</c>.
             /// </summary>
-            public override bool HasValue { get { return true; } }
+            public override bool HasValue => true;
 
             /// <summary>
-            /// Returns NotificationKind.OnNext.
+            /// Returns <see cref="NotificationKind.OnNext"/>.
             /// </summary>
-            public override NotificationKind Kind { get { return NotificationKind.OnNext; } }
+            public override NotificationKind Kind => NotificationKind.OnNext;
 
             /// <summary>
             /// Returns the hash code for this instance.
             /// </summary>
-            public override int GetHashCode()
-            {
-                return EqualityComparer<T>.Default.GetHashCode(Value);
-            }
+            public override int GetHashCode() => EqualityComparer<T>.Default.GetHashCode(Value);
 
             /// <summary>
             /// Indicates whether this instance and a specified object are equal.
@@ -148,10 +131,7 @@ namespace System.Reactive
             /// <summary>
             /// Returns a string representation of this instance.
             /// </summary>
-            public override string ToString()
-            {
-                return String.Format(CultureInfo.CurrentCulture, "OnNext({0})", Value);
-            }
+            public override string ToString() => String.Format(CultureInfo.CurrentCulture, "OnNext({0})", Value);
 
             /// <summary>
             /// Invokes the observer's method corresponding to the notification.
@@ -227,43 +207,38 @@ namespace System.Reactive
 #endif
         internal sealed class OnErrorNotification : Notification<T>
         {
-            Exception exception;
-
             /// <summary>
             /// Constructs a notification of an exception.
             /// </summary>
             public OnErrorNotification(Exception exception)
             {
-                this.exception = exception;
+                Exception = exception;
             }
 
             /// <summary>
             /// Throws the exception.
             /// </summary>
-            public override T Value { get { exception.Throw(); return default(T); } }
+            public override T Value { get { Exception.Throw(); return default(T); } }
 
             /// <summary>
             /// Returns the exception.
             /// </summary>
-            public override Exception Exception { get { return exception; } }
+            public override Exception Exception { get; }
 
             /// <summary>
-            /// Returns false.
+            /// Returns <c>false</c>.
             /// </summary>
-            public override bool HasValue { get { return false; } }
+            public override bool HasValue => false;
 
             /// <summary>
-            /// Returns NotificationKind.OnError.
+            /// Returns <see cref="NotificationKind.OnError"/>.
             /// </summary>
-            public override NotificationKind Kind { get { return NotificationKind.OnError; } }
+            public override NotificationKind Kind => NotificationKind.OnError;
 
             /// <summary>
             /// Returns the hash code for this instance.
             /// </summary>
-            public override int GetHashCode()
-            {
-                return Exception.GetHashCode();
-            }
+            public override int GetHashCode() => Exception.GetHashCode();
 
             /// <summary>
             /// Indicates whether this instance and other are equal.
@@ -282,10 +257,7 @@ namespace System.Reactive
             /// <summary>
             /// Returns a string representation of this instance.
             /// </summary>
-            public override string ToString()
-            {
-                return String.Format(CultureInfo.CurrentCulture, "OnError({0})", Exception.GetType().FullName);
-            }
+            public override string ToString() => String.Format(CultureInfo.CurrentCulture, "OnError({0})", Exception.GetType().FullName);
 
             /// <summary>
             /// Invokes the observer's method corresponding to the notification.
@@ -369,32 +341,29 @@ namespace System.Reactive
             }
 
             /// <summary>
-            /// Throws an InvalidOperationException.
+            /// Throws an <see cref="InvalidOperationException"/>.
             /// </summary>
             public override T Value { get { throw new InvalidOperationException(Strings_Core.COMPLETED_NO_VALUE); } }
 
             /// <summary>
-            /// Returns null.
+            /// Returns <c>null</c>.
             /// </summary>
-            public override Exception Exception { get { return null; } }
+            public override Exception Exception => null;
 
             /// <summary>
-            /// Returns false.
+            /// Returns <c>false</c>.
             /// </summary>
-            public override bool HasValue { get { return false; } }
+            public override bool HasValue => false;
 
             /// <summary>
-            /// Returns NotificationKind.OnCompleted.
+            /// Returns <see cref="NotificationKind.OnCompleted"/>.
             /// </summary>
-            public override NotificationKind Kind { get { return NotificationKind.OnCompleted; } }
+            public override NotificationKind Kind => NotificationKind.OnCompleted;
 
             /// <summary>
             /// Returns the hash code for this instance.
             /// </summary>
-            public override int GetHashCode()
-            {
-                return typeof(T).GetHashCode() ^ 8510;
-            }
+            public override int GetHashCode() => typeof(T).GetHashCode() ^ 8510;
 
             /// <summary>
             /// Indicates whether this instance and other are equal.
@@ -411,10 +380,7 @@ namespace System.Reactive
             /// <summary>
             /// Returns a string representation of this instance.
             /// </summary>
-            public override string ToString()
-            {
-                return "OnCompleted()";
-            }
+            public override string ToString() => "OnCompleted()";
 
             /// <summary>
             /// Invokes the observer's method corresponding to the notification.
@@ -524,10 +490,7 @@ namespace System.Reactive
         /// This means two <see cref="Notification{T}"/> objects can be equal even though they don't represent the same observer method call, but have the same Kind and have equal parameters passed to the observer method.
         /// In case one wants to determine whether two <see cref="Notification{T}"/> objects represent a different observer method call, use Object.ReferenceEquals identity equality instead.
         /// </remarks>
-        public static bool operator !=(Notification<T> left, Notification<T> right)
-        {
-            return !(left == right);
-        }
+        public static bool operator !=(Notification<T> left, Notification<T> right) => !(left == right);
 
         /// <summary>
         /// Determines whether the specified System.Object is equal to the current <see cref="Notification{T}"/>.
@@ -539,10 +502,7 @@ namespace System.Reactive
         /// This means two <see cref="Notification{T}"/> objects can be equal even though they don't represent the same observer method call, but have the same Kind and have equal parameters passed to the observer method.
         /// In case one wants to determine whether two <see cref="Notification{T}"/> objects represent the same observer method call, use Object.ReferenceEquals identity equality instead.
         /// </remarks>
-        public override bool Equals(object obj)
-        {
-            return Equals(obj as Notification<T>);
-        }
+        public override bool Equals(object obj) => Equals(obj as Notification<T>);
 
         /// <summary>
         /// Invokes the observer's method corresponding to the notification.
@@ -580,10 +540,7 @@ namespace System.Reactive
         /// Returns an observable sequence with a single notification, using the immediate scheduler.
         /// </summary>
         /// <returns>The observable sequence that surfaces the behavior of the notification upon subscription.</returns>
-        public IObservable<T> ToObservable()
-        {
-            return this.ToObservable(ImmediateScheduler.Instance);
-        }
+        public IObservable<T> ToObservable() => ToObservable(ImmediateScheduler.Instance);
 
         /// <summary>
         /// Returns an observable sequence with a single notification.
@@ -648,4 +605,4 @@ namespace System.Reactive
 }
 
 #pragma warning restore 0659
-#pragma warning restore 0661
+#pragma warning restore 0661

+ 2 - 8
Rx.NET/Source/src/System.Reactive/ObservableQuery.cs

@@ -121,15 +121,9 @@ namespace System.Reactive
             _expression = expression;
         }
 
-        public Type ElementType
-        {
-            get { return typeof(TSource); }
-        }
+        public Type ElementType => typeof(TSource);
 
-        public IQbservableProvider Provider
-        {
-            get { return Qbservable.Provider; }
-        }
+        public IQbservableProvider Provider => Qbservable.Provider;
 
         public IDisposable Subscribe(IObserver<TSource> observer)
         {

+ 2 - 11
Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs

@@ -270,10 +270,7 @@ namespace System.Reactive.Subjects
         /// Gets an awaitable object for the current AsyncSubject.
         /// </summary>
         /// <returns>Object that can be awaited.</returns>
-        public AsyncSubject<T> GetAwaiter()
-        {
-            return this;
-        }
+        public AsyncSubject<T> GetAwaiter() => this;
 
         /// <summary>
         /// Specifies a callback action that will be invoked when the subject completes.
@@ -346,13 +343,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// Gets whether the AsyncSubject has completed.
         /// </summary>
-        public bool IsCompleted
-        {
-            get
-            {
-                return _isStopped;
-            }
-        }
+        public bool IsCompleted => _isStopped;
 
         /// <summary>
         /// Gets the last element of the subject, potentially blocking until the subject completes successfully or exceptionally.

+ 1 - 7
Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs

@@ -49,13 +49,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// Indicates whether the subject has been disposed.
         /// </summary>
-        public override bool IsDisposed
-        {
-            get
-            {
-                return _observer is DisposedObserver<T>;
-            }
-        }
+        public override bool IsDisposed => _observer is DisposedObserver<T>;
 
         #endregion
 

+ 5 - 16
Rx.NET/Source/src/System.Reactive/TimeInterval.cs

@@ -17,9 +17,6 @@ namespace System.Reactive
 #endif
     public struct TimeInterval<T> : IEquatable<TimeInterval<T>>
     {
-        private readonly TimeSpan _interval;
-        private readonly T _value;
-
         /// <summary>
         /// Constructs a time interval value.
         /// </summary>
@@ -27,25 +24,19 @@ namespace System.Reactive
         /// <param name="interval">Time interval associated with the value.</param>
         public TimeInterval(T value, TimeSpan interval)
         {
-            _interval = interval;
-            _value = value;
+            Interval = interval;
+            Value = value;
         }
 
         /// <summary>
         /// Gets the value.
         /// </summary>
-        public T Value
-        {
-            get { return _value; }
-        }
+        public T Value { get; }
 
         /// <summary>
         /// Gets the interval.
         /// </summary>
-        public TimeSpan Interval
-        {
-            get { return _interval; }
-        }
+        public TimeSpan Interval { get; }
 
         /// <summary>
         /// Determines whether the current <see cref="TimeInterval{T}"/> value has the same Value and Interval as a specified <see cref="TimeInterval{T}"/> value.
@@ -99,9 +90,7 @@ namespace System.Reactive
         /// <returns>A hash code for the current <see cref="TimeInterval{T}"/> value.</returns>
         public override int GetHashCode()
         {
-            var valueHashCode = Value == null ? 1963 : Value.GetHashCode();
-
-            return Interval.GetHashCode() ^ valueHashCode;
+            return Interval.GetHashCode() ^ (Value?.GetHashCode() ?? 1963);
         }
 
         /// <summary>

+ 5 - 16
Rx.NET/Source/src/System.Reactive/Timestamped.cs

@@ -18,9 +18,6 @@ namespace System.Reactive
     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Timestamped", Justification = "Reviewed and agreed upon.")]
     public struct Timestamped<T> : IEquatable<Timestamped<T>>
     {
-        private readonly DateTimeOffset _timestamp;
-        private readonly T _value;
-
         /// <summary>
         /// Constructs a timestamped value.
         /// </summary>
@@ -28,25 +25,19 @@ namespace System.Reactive
         /// <param name="timestamp">Timestamp associated with the value.</param>
         public Timestamped(T value, DateTimeOffset timestamp)
         {
-            _timestamp = timestamp;
-            _value = value;
+            Timestamp = timestamp;
+            Value = value;
         }
 
         /// <summary>
         /// Gets the value.
         /// </summary>
-        public T Value
-        {
-            get { return _value; }
-        }
+        public T Value { get; }
 
         /// <summary>
         /// Gets the timestamp.
         /// </summary>
-        public DateTimeOffset Timestamp
-        {
-            get { return _timestamp; }
-        }
+        public DateTimeOffset Timestamp { get; }
 
         /// <summary>
         /// Determines whether the current <see cref="Timestamped{T}" /> value has the same Value and Timestamp as a specified <see cref="Timestamped{T}" /> value.
@@ -100,9 +91,7 @@ namespace System.Reactive
         /// <returns>A hash code for the current <see cref="Timestamped{T}" /> value.</returns>
         public override int GetHashCode()
         {
-            var valueHashCode = Value == null ? 1979 : Value.GetHashCode();
-
-            return _timestamp.GetHashCode() ^ valueHashCode;
+            return Timestamp.GetHashCode() ^ (Value?.GetHashCode() ?? 1979);
         }
 
         /// <summary>

+ 26 - 46
Rx.NET/Source/src/System.Reactive/Unit.cs

@@ -13,72 +13,52 @@ namespace System.Reactive
     public struct Unit : IEquatable<Unit>
     {
         /// <summary>
-        /// Determines whether the specified Unit values is equal to the current Unit. Because Unit has a single value, this always returns true.
+        /// Determines whether the specified <see cref="Unit"/> value is equal to the current <see cref="Unit"/>. Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.
         /// </summary>
-        /// <param name="other">An object to compare to the current Unit value.</param>
-        /// <returns>Because Unit has a single value, this always returns true.</returns>
-        public bool Equals(Unit other)
-        {
-            return true;
-        }
+        /// <param name="other">An object to compare to the current <see cref="Unit"/> value.</param>
+        /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
+        public bool Equals(Unit other) => true;
 
         /// <summary>
-        /// Determines whether the specified System.Object is equal to the current Unit.
+        /// Determines whether the specified System.Object is equal to the current <see cref="Unit"/>.
         /// </summary>
-        /// <param name="obj">The System.Object to compare with the current Unit.</param>
-        /// <returns>true if the specified System.Object is a Unit value; otherwise, false.</returns>
-        public override bool Equals(object obj)
-        {
-            return obj is Unit;
-        }
+        /// <param name="obj">The System.Object to compare with the current <see cref="Unit"/>.</param>
+        /// <returns><c>true</c> if the specified System.Object is a <see cref="Unit"/> value; otherwise, <c>false</c>.</returns>
+        public override bool Equals(object obj) => obj is Unit;
 
         /// <summary>
-        /// Returns the hash code for the current Unit value.
+        /// Returns the hash code for the current <see cref="Unit"/> value.
         /// </summary>
-        /// <returns>A hash code for the current Unit value.</returns>
-        public override int GetHashCode()
-        {
-            return 0;
-        }
+        /// <returns>A hash code for the current <see cref="Unit"/> value.</returns>
+        public override int GetHashCode() => 0;
 
         /// <summary>
-        /// Returns a string representation of the current Unit value.
+        /// Returns a string representation of the current <see cref="Unit"/> value.
         /// </summary>
-        /// <returns>String representation of the current Unit value.</returns>
-        public override string ToString()
-        {
-            return "()";
-        }
+        /// <returns>String representation of the current <see cref="Unit"/> value.</returns>
+        public override string ToString() => "()";
 
         /// <summary>
-        /// Determines whether the two specified Unit values are equal. Because Unit has a single value, this always returns true.
+        /// Determines whether the two specified <see cref="Unit"/> values are equal. Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.
         /// </summary>
-        /// <param name="first">The first Unit value to compare.</param>
-        /// <param name="second">The second Unit value to compare.</param>
-        /// <returns>Because Unit has a single value, this always returns true.</returns>
+        /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
+        /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
+        /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>true</c>.</returns>
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
-        public static bool operator ==(Unit first, Unit second)
-        {
-            return true;
-        }
+        public static bool operator ==(Unit first, Unit second) => true;
 
         /// <summary>
-        /// Determines whether the two specified Unit values are not equal. Because Unit has a single value, this always returns false.
+        /// Determines whether the two specified <see cref="Unit"/> values are not equal. Because <see cref="Unit"/> has a single value, this always returns <c>false</c>.
         /// </summary>
-        /// <param name="first">The first Unit value to compare.</param>
-        /// <param name="second">The second Unit value to compare.</param>
-        /// <returns>Because Unit has a single value, this always returns false.</returns>
+        /// <param name="first">The first <see cref="Unit"/> value to compare.</param>
+        /// <param name="second">The second <see cref="Unit"/> value to compare.</param>
+        /// <returns>Because <see cref="Unit"/> has a single value, this always returns <c>false</c>.</returns>
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "first", Justification = "Parameter required for operator overloading."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "second", Justification = "Parameter required for operator overloading.")]
-        public static bool operator !=(Unit first, Unit second)
-        {
-            return false;
-        }
-
-        static readonly Unit _default = new Unit();
+        public static bool operator !=(Unit first, Unit second) => false;
 
         /// <summary>
-        /// Gets the single unit value.
+        /// Gets the single <see cref="Unit"/> value.
         /// </summary>
-        public static Unit Default { get { return _default; } }
+        public static Unit Default => default(Unit);
     }
 }