diff --git a/.editorconfig b/.editorconfig
index b79f2c4f21..5dbbb2dc68 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,99 +1,199 @@
-# editorconfig.org
+# EditorConfig is awesome:http://EditorConfig.org
+# From https://raw.githubusercontent.com/dotnet/roslyn/master/.editorconfig
# top-most EditorConfig file
root = true
-[project.json]
-indent_size = 2
-
-# C# files
-[*.cs]
-insert_final_newline = true
+# Don't use tabs for indentation.
+[*]
indent_style = space
+# (Please don't specify an indent_size here; that has too many unintended consequences.)
+
+# Code files
+[*.{cs,csx,vb,vbx}]
indent_size = 4
-# New line preferences
-csharp_new_line_before_open_brace = all
-csharp_new_line_before_else = true
-csharp_new_line_before_catch = true
-csharp_new_line_before_finally = true
-csharp_new_line_before_members_in_object_initializers = true
-csharp_new_line_before_members_in_anonymous_types = true
-csharp_new_line_between_query_expression_clauses = true
+insert_final_newline = true
+charset = utf-8-bom
-# Indentation preferences
-csharp_indent_block_contents = true
-csharp_indent_braces = false
-csharp_indent_case_contents = true
-csharp_indent_switch_labels = true
-csharp_indent_labels = one_less_than_current
+# Xml project files
+[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
+indent_size = 2
+
+# Xml config files
+[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
+indent_size = 2
+
+# Yml/Yaml files
+[*.{yaml,yml}]
+indent_size = 2
+
+# JSON files
+[*.json]
+indent_size = 2
+
+# Shell scripts
+[*.sh]
+end_of_line = lf
+
+[*.{cmd,bat}]
+end_of_line = crlf
+
+# Dotnet code style settings:
+[*.{cs,vb}]
+# Sort using and Import directives with System.* appearing first
+dotnet_sort_system_directives_first = true
+# Put a blank line between System.* and Microsoft.*
+dotnet_separate_import_directive_groups = true
-# avoid this. unless absolutely necessary
+# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
-# use var everywhere
-csharp_style_var_for_built_in_types = true:suggestion
-csharp_style_var_when_type_is_apparent = true:suggestion
-csharp_style_var_elsewhere = true:suggestion
-
-# use language keywords instead of BCL types
+# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
-# name all constant fields using PascalCase
-dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
-dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
-dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
+# Prefer read-only on fields
+dotnet_style_readonly_field = true:warning
+
+# Suggest more modern language features when available
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_conditional_expression_over_return = false
+dotnet_style_prefer_conditional_expression_over_assignment = false
+dotnet_style_prefer_auto_properties = true
+
+# Accessibility modifiers
+dotnet_style_require_accessibility_modifiers = always:suggestion
+
+
+# Naming Rules
+
+# Interfaces start with an I and are PascalCased
+dotnet_naming_rule.interfaces_must_be_pascal_cased_and_prefixed_with_I.symbols = interface_symbols
+dotnet_naming_rule.interfaces_must_be_pascal_cased_and_prefixed_with_I.style = pascal_case_and_prefix_with_I_style
+dotnet_naming_rule.interfaces_must_be_pascal_cased_and_prefixed_with_I.severity = warning
+
+# External members are PascalCased
+dotnet_naming_rule.externally_visible_members_must_be_pascal_cased.symbols = externally_visible_symbols
+dotnet_naming_rule.externally_visible_members_must_be_pascal_cased.style = pascal_case_style
+dotnet_naming_rule.externally_visible_members_must_be_pascal_cased.severity = warning
+
+# Parameters are camelCased
+dotnet_naming_rule.parameters_must_be_camel_cased.symbols = parameter_symbols
+dotnet_naming_rule.parameters_must_be_camel_cased.style = camel_case_style
+dotnet_naming_rule.parameters_must_be_camel_cased.severity = warning
+
+# Constants are PascalCased
+dotnet_naming_rule.constants_must_be_pascal_cased.symbols = constant_symbols
+dotnet_naming_rule.constants_must_be_pascal_cased.style = pascal_case_style
+dotnet_naming_rule.constants_must_be_pascal_cased.severity = warning
+
+# Uncomment this group and comment out the next group if you prefer s_ prefixes for static fields
+
+# Private static fields are prefixed with s_ and are camelCased like s_myStatic
+#dotnet_naming_rule.private_static_fields_must_be_camel_cased_and_prefixed_with_s_underscore.symbols = private_static_field_symbols
+#dotnet_naming_rule.private_static_fields_must_be_camel_cased_and_prefixed_with_s_underscore.style = camel_case_and_prefix_with_s_underscore_style
+#dotnet_naming_rule.private_static_fields_must_be_camel_cased_and_prefixed_with_s_underscore.severity = warning
+
+# Static readonly fields are PascalCased
+dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.symbols = private_static_readonly_field_symbols
+dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.style = pascal_case_style
+dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.severity = warning
+
+# Comment this group and uncomment out the next group if you don't want _ prefixed fields.
-dotnet_naming_symbols.constant_fields.applicable_kinds = field
-dotnet_naming_symbols.constant_fields.required_modifiers = const
+# Private instance fields are camelCased with an _ like _myField
+dotnet_naming_rule.private_instance_fields_must_be_camel_cased_and_prefixed_with_underscore.symbols = private_field_symbols
+dotnet_naming_rule.private_instance_fields_must_be_camel_cased_and_prefixed_with_underscore.style = camel_case_and_prefix_with_underscore_style
+dotnet_naming_rule.private_instance_fields_must_be_camel_cased_and_prefixed_with_underscore.severity = warning
-# name all static fields using PascalCase
-dotnet_naming_rule.static_fields_should_be_pascal_case.severity = suggestion
-dotnet_naming_rule.static_fields_should_be_pascal_case.symbols = static_fields
-dotnet_naming_rule.static_fields_should_be_pascal_case.style = pascal_case_style
+# Private instance fields are camelCased
+#dotnet_naming_rule.private_instance_fields_must_be_camel_cased.symbols = private_field_symbols
+#dotnet_naming_rule.private_instance_fields_must_be_camel_cased.style = camel_case_style
+#dotnet_naming_rule.private_instance_fields_must_be_camel_cased.severity = warning
-dotnet_naming_symbols.static_fields.applicable_kinds = field
-dotnet_naming_symbols.static_fields.required_modifiers = static
+# Symbols
+dotnet_naming_symbols.externally_visible_symbols.applicable_kinds = class,struct,interface,enum,property,method,field,event,delegate
+dotnet_naming_symbols.externally_visible_symbols.applicable_accessibilities = public,internal,friend,protected,protected_internal,protected_friend,private_protected
-dotnet_naming_style.pascal_case_style.capitalization = pascal_case
+dotnet_naming_symbols.interface_symbols.applicable_kinds = interface
+dotnet_naming_symbols.interface_symbols.applicable_accessibilities = *
-# internal and private fields should be _camelCase
-dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
-dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
-dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
+dotnet_naming_symbols.parameter_symbols.applicable_kinds = parameter
+dotnet_naming_symbols.parameter_symbols.applicable_accessibilities = *
-dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
-dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
+dotnet_naming_symbols.constant_symbols.applicable_kinds = field
+dotnet_naming_symbols.constant_symbols.required_modifiers = const
+dotnet_naming_symbols.constant_symbols.applicable_accessibilities = *
-dotnet_naming_style.camel_case_underscore_style.required_prefix = _
-dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
+dotnet_naming_symbols.private_static_field_symbols.applicable_kinds = field
+dotnet_naming_symbols.private_static_field_symbols.required_modifiers = static,shared
+dotnet_naming_symbols.private_static_field_symbols.applicable_accessibilities = private
+
+dotnet_naming_symbols.private_static_readonly_field_symbols.applicable_kinds = field
+dotnet_naming_symbols.private_static_readonly_field_symbols.required_modifiers = static,shared,readonly
+dotnet_naming_symbols.private_static_readonly_field_symbols.applicable_accessibilities = private
+
+dotnet_naming_symbols.private_field_symbols.applicable_kinds = field
+dotnet_naming_symbols.private_field_symbols.applicable_accessibilities = private
+
+# Styles
+dotnet_naming_style.camel_case_style.capitalization = camel_case
+
+dotnet_naming_style.pascal_case_style.capitalization = pascal_case
+
+dotnet_naming_style.camel_case_and_prefix_with_s_underscore_style.required_prefix = s_
+dotnet_naming_style.camel_case_and_prefix_with_s_underscore_style.capitalization = camel_case
+
+dotnet_naming_style.camel_case_and_prefix_with_underscore_style.required_prefix = _
+dotnet_naming_style.camel_case_and_prefix_with_underscore_style.capitalization = camel_case
+
+dotnet_naming_style.pascal_case_and_prefix_with_I_style.required_prefix = I
+dotnet_naming_style.pascal_case_and_prefix_with_I_style.capitalization = pascal_case
+
+
+# CSharp code style settings:
+[*.cs]
+# Indentation preferences
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_switch_labels = true
+csharp_indent_labels = flush_left
+
+# Prefer "var" everywhere
+csharp_style_var_for_built_in_types = true:suggestion
+csharp_style_var_when_type_is_apparent = true:suggestion
+csharp_style_var_elsewhere = true:suggestion
# Code style defaults
-dotnet_sort_system_directives_first = true
-dotnet_style_require_accessibility_modifiers = omit_if_default
csharp_preserve_single_line_blocks = true
-csharp_preserve_single_line_statements = false
+csharp_preserve_single_line_statements = true
-# Expression-level preferences
-dotnet_style_object_initializer = true:suggestion
-dotnet_style_collection_initializer = true:suggestion
-dotnet_style_explicit_tuple_names = true:suggestion
-dotnet_style_prefer_inferred_tuple_names = true:suggestion
-dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
-dotnet_style_coalesce_expression = true:suggestion
-dotnet_style_null_propagation = true:suggestion
-
-# Expression-bodied members
+# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
+
+# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
+# Expression
+csharp_prefer_simple_default_expression = true:suggestion
+csharp_style_deconstructed_variable_declaration = true:suggestion
+csharp_style_pattern_local_over_anonymous_function = true:suggestion
+
# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
@@ -103,6 +203,15 @@ csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
+# Newline settings
+csharp_new_line_before_open_brace = all
+csharp_new_line_before_else = true
+csharp_new_line_before_catch = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_between_query_expression_clauses = true
+
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
@@ -125,36 +234,4 @@ csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
-csharp_space_between_square_brackets = false
-
-# C++ Files
-[*.{cpp,h,in}]
-curly_bracket_next_line = true
-indent_brace_style = Allman
-
-# Xml project files
-[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
-indent_size = 2
-
-# Xml build files
-[*.builds]
-indent_size = 2
-
-# Yml/Yaml files
-[*.{yaml,yml}]
-indent_size = 2
-
-# Xml files
-[*.{xml,stylecop,resx,ruleset}]
-indent_size = 2
-
-# Xml config files
-[*.{props,targets,config,nuspec}]
-indent_size = 2
-
-# Shell scripts
-[*.sh]
-end_of_line = lf
-
-[*.{cmd, bat}]
-end_of_line = crlf
+csharp_space_between_square_brackets = false
\ No newline at end of file
diff --git a/Rx.NET/Source/Directory.build.props b/Rx.NET/Source/Directory.build.props
index 7c05ded82b..4584b4077b 100644
--- a/Rx.NET/Source/Directory.build.props
+++ b/Rx.NET/Source/Directory.build.props
@@ -21,6 +21,7 @@
$(MSBuildThisFileDirectory)artifacts
true
true
+ latest
diff --git a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/BufferCountBenchmark.cs b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/BufferCountBenchmark.cs
index 8e262d717a..fb714e5c89 100644
--- a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/BufferCountBenchmark.cs
+++ b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/BufferCountBenchmark.cs
@@ -13,7 +13,7 @@ namespace Benchmarks.System.Reactive
[MemoryDiagnoser]
public class BufferCountBenchmark
{
- IList _store;
+ private IList _store;
[Benchmark]
public void Exact()
diff --git a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/Program.cs b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/Program.cs
index 9b1d620f69..2e1c24ffab 100644
--- a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/Program.cs
+++ b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/Program.cs
@@ -7,9 +7,9 @@
namespace Benchmarks.System.Reactive
{
- class Program
+ internal class Program
{
- static void Main()
+ private static void Main()
{
var switcher = new BenchmarkSwitcher(new[] {
typeof(ZipBenchmark),
diff --git a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/RangeBenchmark.cs b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/RangeBenchmark.cs
index ab42b0fa35..3f3ef2f173 100644
--- a/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/RangeBenchmark.cs
+++ b/Rx.NET/Source/benchmarks/Benchmarks.System.Reactive/RangeBenchmark.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
@@ -14,8 +14,7 @@ public class RangeBenchmark
{
[Params(1, 10, 100, 1000, 10000, 100000, 1000000)]
public int N;
-
- int _store;
+ private int _store;
[Benchmark]
public void Range()
diff --git a/Rx.NET/Source/src/AssemblyInfo.cs b/Rx.NET/Source/src/AssemblyInfo.cs
index 598bc0228d..c58daae750 100644
--- a/Rx.NET/Source/src/AssemblyInfo.cs
+++ b/Rx.NET/Source/src/AssemblyInfo.cs
@@ -7,5 +7,4 @@
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
-[assembly: AllowPartiallyTrustedCallers]
-[assembly: NeutralResourcesLanguage("en-US")]
\ No newline at end of file
+[assembly: NeutralResourcesLanguage("en-US")]
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ColdObservable.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ColdObservable.cs
index 06402d31bc..fed6354587 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ColdObservable.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ColdObservable.cs
@@ -2,61 +2,58 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
+using System;
using System.Collections.Generic;
using System.Reactive;
-using System;
using System.Reactive.Disposables;
namespace Microsoft.Reactive.Testing
{
- class ColdObservable : ITestableObservable
+ internal class ColdObservable : ITestableObservable
{
- readonly TestScheduler scheduler;
- readonly Recorded>[] messages;
- readonly List subscriptions = new List();
+ private readonly TestScheduler _scheduler;
+ private readonly Recorded>[] _messages;
+ private readonly List _subscriptions = new List();
public ColdObservable(TestScheduler scheduler, params Recorded>[] messages)
{
- if (scheduler == null)
- throw new ArgumentNullException(nameof(scheduler));
- if (messages == null)
- throw new ArgumentNullException(nameof(messages));
-
- this.scheduler = scheduler;
- this.messages = messages;
+ _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
+ _messages = messages ?? throw new ArgumentNullException(nameof(messages));
}
public virtual IDisposable Subscribe(IObserver observer)
{
if (observer == null)
+ {
throw new ArgumentNullException(nameof(observer));
+ }
- subscriptions.Add(new Subscription(scheduler.Clock));
- var index = subscriptions.Count - 1;
+ _subscriptions.Add(new Subscription(_scheduler.Clock));
+ var index = _subscriptions.Count - 1;
var d = new CompositeDisposable();
- for (var i = 0; i < messages.Length; ++i)
+ for (var i = 0; i < _messages.Length; ++i)
{
- var notification = messages[i].Value;
- d.Add(scheduler.ScheduleRelative(default(object), messages[i].Time, (scheduler1, state1) => { notification.Accept(observer); return Disposable.Empty; }));
+ var notification = _messages[i].Value;
+ d.Add(_scheduler.ScheduleRelative(default(object), _messages[i].Time, (scheduler1, state1) => { notification.Accept(observer); return Disposable.Empty; }));
}
return Disposable.Create(() =>
{
- subscriptions[index] = new Subscription(subscriptions[index].Subscribe, scheduler.Clock);
+ _subscriptions[index] = new Subscription(_subscriptions[index].Subscribe, _scheduler.Clock);
d.Dispose();
});
}
public IList Subscriptions
{
- get { return subscriptions; }
+ get { return _subscriptions; }
}
public IList>> Messages
{
- get { return messages; }
+ get { return _messages; }
}
}
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/HotObservable.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/HotObservable.cs
index 80d36d8329..c43ce7cf8c 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/HotObservable.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/HotObservable.cs
@@ -2,36 +2,31 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
+using System;
using System.Collections.Generic;
using System.Reactive;
-using System;
using System.Reactive.Disposables;
namespace Microsoft.Reactive.Testing
{
- class HotObservable : ITestableObservable
+ internal class HotObservable : ITestableObservable
{
- readonly TestScheduler scheduler;
- readonly List> observers = new List>();
- readonly List subscriptions = new List();
- readonly Recorded>[] messages;
+ private readonly TestScheduler _scheduler;
+ private readonly List> _observers = new List>();
+ private readonly List _subscriptions = new List();
+ private readonly Recorded>[] _messages;
public HotObservable(TestScheduler scheduler, params Recorded>[] messages)
{
- if (scheduler == null)
- throw new ArgumentNullException(nameof(scheduler));
- if (messages == null)
- throw new ArgumentNullException(nameof(messages));
-
- this.scheduler = scheduler;
- this.messages = messages;
+ _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
+ _messages = messages ?? throw new ArgumentNullException(nameof(messages));
for (var i = 0; i < messages.Length; ++i)
{
var notification = messages[i].Value;
scheduler.ScheduleAbsolute(default(object), messages[i].Time, (scheduler1, state1) =>
{
- var _observers = observers.ToArray();
+ var _observers = this._observers.ToArray();
for (var j = 0; j < _observers.Length; ++j)
{
notification.Accept(_observers[j]);
@@ -44,27 +39,29 @@ public HotObservable(TestScheduler scheduler, params Recorded>[]
public virtual IDisposable Subscribe(IObserver observer)
{
if (observer == null)
+ {
throw new ArgumentNullException(nameof(observer));
+ }
- observers.Add(observer);
- subscriptions.Add(new Subscription(scheduler.Clock));
- var index = subscriptions.Count - 1;
+ _observers.Add(observer);
+ _subscriptions.Add(new Subscription(_scheduler.Clock));
+ var index = _subscriptions.Count - 1;
return Disposable.Create(() =>
{
- observers.Remove(observer);
- subscriptions[index] = new Subscription(subscriptions[index].Subscribe, scheduler.Clock);
+ _observers.Remove(observer);
+ _subscriptions[index] = new Subscription(_subscriptions[index].Subscribe, _scheduler.Clock);
});
}
public IList Subscriptions
{
- get { return subscriptions; }
+ get { return _subscriptions; }
}
public IList>> Messages
{
- get { return messages; }
+ get { return _messages; }
}
}
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/MockObserver.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/MockObserver.cs
index fd1154739c..59028f9460 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/MockObserver.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/MockObserver.cs
@@ -2,23 +2,20 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
+using System;
using System.Collections.Generic;
using System.Reactive;
-using System;
namespace Microsoft.Reactive.Testing
{
- class MockObserver : ITestableObserver
+ internal class MockObserver : ITestableObserver
{
- TestScheduler scheduler;
- List>> messages;
+ private TestScheduler scheduler;
+ private List>> messages;
public MockObserver(TestScheduler scheduler)
{
- if (scheduler == null)
- throw new ArgumentNullException(nameof(scheduler));
-
- this.scheduler = scheduler;
+ this.scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
messages = new List>>();
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/NamespaceDoc.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/NamespaceDoc.cs
index 463d55d081..40b5167e40 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/NamespaceDoc.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/NamespaceDoc.cs
@@ -8,7 +8,7 @@ namespace Microsoft.Reactive.Testing
/// The Microsoft.Reactive.Testing namespace contains interfaces and classes providing functionality to test applications and libraries built using Reactive Extensions.
///
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
- class NamespaceDoc
+ internal class NamespaceDoc
{
}
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Properties/AssemblyInfo.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Properties/AssemblyInfo.cs
index bff391c5ac..317c6542fb 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Properties/AssemblyInfo.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Properties/AssemblyInfo.cs
@@ -1,9 +1,7 @@
using System;
using System.Runtime.InteropServices;
-using System.Security;
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
-//[assembly: AllowPartiallyTrustedCallers]
\ No newline at end of file
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs
index a752c2a8ca..250e1c34cb 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveAssert.cs
@@ -6,9 +6,8 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-using System.Text;
-using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Text;
using Xunit;
namespace Microsoft.Reactive.Testing
@@ -18,7 +17,7 @@ namespace Microsoft.Reactive.Testing
///
public static class ReactiveAssert
{
- static string Message(IEnumerable actual, IEnumerable expected)
+ private static string Message(IEnumerable actual, IEnumerable expected)
{
var sb = new StringBuilder();
sb.AppendLine();
@@ -43,12 +42,19 @@ static string Message(IEnumerable actual, IEnumerable expected)
public static void AreElementsEqual(IEnumerable expected, IEnumerable actual)
{
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
+
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
if (!expected.SequenceEqual(actual))
+ {
Assert.True(false, Message(actual, expected));
+ }
}
///
@@ -62,12 +68,19 @@ public static void AreElementsEqual(IEnumerable expected, IEnumerable a
public static void AreElementsEqual(IEnumerable expected, IEnumerable actual, string message)
{
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
+
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
if (!expected.SequenceEqual(actual))
+ {
Assert.True(false, message);
+ }
}
///
@@ -80,9 +93,14 @@ public static void AreElementsEqual(IEnumerable expected, IEnumerable a
public static void AreElementsEqual(IObservable expected, IObservable actual)
{
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
+
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
AreElementsEqual(expected.Materialize().ToEnumerable(), actual.Materialize().ToEnumerable());
}
@@ -98,9 +116,14 @@ public static void AreElementsEqual(IObservable expected, IObservable a
public static void AreElementsEqual(IObservable expected, IObservable actual, string message)
{
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
+
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
AreElementsEqual(expected.Materialize().ToEnumerable(), actual.Materialize().ToEnumerable(), message);
}
@@ -114,7 +137,9 @@ public static void AreElementsEqual(IObservable expected, IObservable a
public static void Throws(Action action) where TException : Exception
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var failed = false;
try
@@ -131,7 +156,9 @@ public static void Throws(Action action) where TException : Exceptio
}
if (failed)
+ {
Assert.True(false, string.Format(CultureInfo.CurrentCulture, "Expected {0}.", typeof(TException).Name));
+ }
}
///
@@ -144,7 +171,9 @@ public static void Throws(Action action) where TException : Exceptio
public static void Throws(Action action, string message) where TException : Exception
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var failed = false;
try
@@ -161,7 +190,9 @@ public static void Throws(Action action, string message) where TExce
}
if (failed)
+ {
Assert.True(false, message);
+ }
}
///
@@ -174,7 +205,9 @@ public static void Throws(Action action, string message) where TExce
public static void Throws(TException exception, Action action) where TException : Exception
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var failed = false;
try
@@ -192,7 +225,9 @@ public static void Throws(TException exception, Action action) where
}
if (failed)
+ {
Assert.True(false, string.Format(CultureInfo.CurrentCulture, "Expected {0}.", typeof(TException).Name));
+ }
}
///
@@ -206,7 +241,9 @@ public static void Throws(TException exception, Action action) where
public static void Throws(TException exception, Action action, string message) where TException : Exception
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var failed = false;
try
@@ -224,7 +261,9 @@ public static void Throws(TException exception, Action action, strin
}
if (failed)
+ {
Assert.True(false, message);
+ }
}
///
@@ -237,9 +276,14 @@ public static void Throws(TException exception, Action action, strin
public static void AssertEqual(this IEnumerable actual, IEnumerable expected)
{
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
+
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
ReactiveAssert.AreElementsEqual(expected, actual);
}
@@ -254,9 +298,14 @@ public static void AssertEqual(this IEnumerable actual, IEnumerable exp
public static void AssertEqual(this IEnumerable actual, params T[] expected)
{
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
+
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
ReactiveAssert.AreElementsEqual(expected, actual);
}
@@ -271,9 +320,14 @@ public static void AssertEqual(this IEnumerable actual, params T[] expecte
public static void AssertEqual(this IObservable actual, IObservable expected)
{
if (actual == null)
+ {
throw new ArgumentNullException(nameof(actual));
+ }
+
if (expected == null)
+ {
throw new ArgumentNullException(nameof(expected));
+ }
ReactiveAssert.AreElementsEqual(expected, actual);
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveTest.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveTest.cs
index ca34268e48..e90a5fa7c6 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveTest.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/ReactiveTest.cs
@@ -16,7 +16,7 @@ public class ReactiveTest
/// Default virtual time used for creation of observable sequences in -based unit tests.
///
public const long Created = 100;
-
+
///
/// Default virtual time used to subscribe to observable sequences in -based unit tests.
///
@@ -50,7 +50,9 @@ public static Recorded> OnNext(long ticks, T value)
public static Recorded> OnNext(long ticks, Func predicate)
{
if (predicate == null)
+ {
throw new ArgumentNullException(nameof(predicate));
+ }
return new Recorded>(ticks, new OnNextPredicate(predicate));
}
@@ -89,7 +91,9 @@ public static Recorded> OnCompleted(long ticks, T witness)
public static Recorded> OnError(long ticks, Exception exception)
{
if (exception == null)
+ {
throw new ArgumentNullException(nameof(exception));
+ }
return new Recorded>(ticks, Notification.CreateOnError(exception));
}
@@ -105,11 +109,13 @@ public static Recorded> OnError(long ticks, Exception excepti
public static Recorded> OnError(long ticks, Func predicate)
{
if (predicate == null)
+ {
throw new ArgumentNullException(nameof(predicate));
+ }
return new Recorded>(ticks, new OnErrorPredicate(predicate));
}
-
+
///
/// Factory method for an OnError notification record at a given time with a given error, using inference to determine the type of .
///
@@ -122,7 +128,9 @@ public static Recorded> OnError(long ticks, Func> OnError(long ticks, Exception exception, T witness)
{
if (exception == null)
+ {
throw new ArgumentNullException(nameof(exception));
+ }
return new Recorded>(ticks, Notification.CreateOnError(exception));
}
@@ -139,7 +147,9 @@ public static Recorded> OnError(long ticks, Exception excepti
public static Recorded> OnError(long ticks, Func predicate, T witness)
{
if (predicate == null)
+ {
throw new ArgumentNullException(nameof(predicate));
+ }
return new Recorded>(ticks, new OnErrorPredicate(predicate));
}
@@ -167,7 +177,7 @@ public static Subscription Subscribe(long start)
#region Predicate-based notification assert helper classes
- class OnNextPredicate : PredicateNotification
+ private class OnNextPredicate : PredicateNotification
{
private readonly Func _predicate;
@@ -179,17 +189,25 @@ public OnNextPredicate(Func predicate)
public override bool Equals(Notification other)
{
if (Object.ReferenceEquals(this, other))
+ {
return true;
- if (Object.ReferenceEquals(other, null))
+ }
+
+ if (other is null)
+ {
return false;
+ }
+
if (other.Kind != NotificationKind.OnNext)
+ {
return false;
+ }
return _predicate(other.Value);
}
}
- class OnErrorPredicate : PredicateNotification
+ private class OnErrorPredicate : PredicateNotification
{
private readonly Func _predicate;
@@ -201,17 +219,25 @@ public OnErrorPredicate(Func predicate)
public override bool Equals(Notification other)
{
if (Object.ReferenceEquals(this, other))
+ {
return true;
- if (Object.ReferenceEquals(other, null))
+ }
+
+ if (other is null)
+ {
return false;
+ }
+
if (other.Kind != NotificationKind.OnError)
+ {
return false;
+ }
return _predicate(other.Exception);
}
}
- abstract class PredicateNotification : Notification
+ private abstract class PredicateNotification : Notification
{
#region Non-implemented members (by design)
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Recorded.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Recorded.cs
index 85d9d0410d..fc54a15fbc 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Recorded.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Recorded.cs
@@ -83,7 +83,10 @@ public bool Equals(Recorded other)
public override bool Equals(object obj)
{
if (obj is Recorded)
+ {
return Equals((Recorded)obj);
+ }
+
return false;
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Subscription.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Subscription.cs
index cbf71d4b55..a4bfe0a2ad 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Subscription.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Subscription.cs
@@ -22,8 +22,8 @@ public struct Subscription : IEquatable
///
public const long Infinite = long.MaxValue;
- private long _subscribe;
- private long _unsubscribe;
+ private readonly long _subscribe;
+ private readonly long _unsubscribe;
///
/// Gets the subscription virtual time.
@@ -72,7 +72,7 @@ public bool Equals(Subscription other)
/// The first Subscription value to compare.
/// The second Subscription value to compare.
/// true if the first Subscription value has the same Subscribe and Unsubscribe as the second Subscription value; otherwise, false.
- public static bool operator==(Subscription left, Subscription right)
+ public static bool operator ==(Subscription left, Subscription right)
{
return left.Equals(right);
}
@@ -96,7 +96,10 @@ public bool Equals(Subscription other)
public override bool Equals(object obj)
{
if (obj is Subscription)
+ {
return Equals((Subscription)obj);
+ }
+
return false;
}
@@ -116,9 +119,13 @@ public override int GetHashCode()
public override string ToString()
{
if (Unsubscribe == Infinite)
+ {
return string.Format(CultureInfo.CurrentCulture, "({0}, Infinite)", Subscribe);
+ }
else
+ {
return string.Format(CultureInfo.CurrentCulture, "({0}, {1})", Subscribe, Unsubscribe);
+ }
}
}
}
diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs b/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs
index dfae974d07..f004458766 100644
--- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs
+++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs
@@ -26,7 +26,9 @@ public class TestScheduler : VirtualTimeScheduler
public override IDisposable ScheduleAbsolute(TState state, long dueTime, Func action)
{
if (dueTime <= Clock)
+ {
dueTime = Clock + 1;
+ }
return base.ScheduleAbsolute(state, dueTime, action);
}
@@ -75,7 +77,9 @@ protected override long ToRelative(TimeSpan timeSpan)
public ITestableObserver Start(Func> create, long created, long subscribed, long disposed)
{
if (create == null)
+ {
throw new ArgumentNullException(nameof(create));
+ }
var source = default(IObservable);
var subscription = default(IDisposable);
@@ -102,7 +106,9 @@ public ITestableObserver Start(Func> create, long created,
public ITestableObserver Start(Func> create, long disposed)
{
if (create == null)
+ {
throw new ArgumentNullException(nameof(create));
+ }
return Start(create, ReactiveTest.Created, ReactiveTest.Subscribed, disposed);
}
@@ -117,7 +123,9 @@ public ITestableObserver Start(Func> create, long disposed)
public ITestableObserver Start(Func> create)
{
if (create == null)
+ {
throw new ArgumentNullException(nameof(create));
+ }
return Start(create, ReactiveTest.Created, ReactiveTest.Subscribed, ReactiveTest.Disposed);
}
@@ -132,7 +140,9 @@ public ITestableObserver Start(Func> create)
public ITestableObservable CreateHotObservable(params Recorded>[] messages)
{
if (messages == null)
+ {
throw new ArgumentNullException(nameof(messages));
+ }
return new HotObservable(this, messages);
}
@@ -147,7 +157,9 @@ public ITestableObservable CreateHotObservable(params Recorded CreateColdObservable(params Recorded>[] messages)
{
if (messages == null)
+ {
throw new ArgumentNullException(nameof(messages));
+ }
return new ColdObservable(this, messages);
}
diff --git a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Observable.Aliases.cs b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Observable.Aliases.cs
index 5d15a300e6..5ce3d94a94 100644
--- a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Observable.Aliases.cs
+++ b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Observable.Aliases.cs
@@ -5,9 +5,7 @@
#pragma warning disable 1591
using System.Collections.Generic;
-using System.Reactive.Concurrency;
using System.Reactive.Linq;
-using System.Reactive;
using System.Reactive.Threading.Tasks; // needed for doc comments
using System.Threading;
using System.Threading.Tasks;
diff --git a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Qbservable.Aliases.Generated.cs b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Qbservable.Aliases.Generated.cs
index 08e32c4e73..5e9bf5d29b 100644
--- a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Qbservable.Aliases.Generated.cs
+++ b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/Qbservable.Aliases.Generated.cs
@@ -5,18 +5,11 @@
#pragma warning disable 1591
-using System;
-using System.Reactive.Concurrency;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
-using System.Reactive.Joins;
-using System.Linq;
using System.Linq.Expressions;
-using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
-using System.Reactive;
-using System.Reactive.Subjects;
namespace System.Reactive.Linq
{
diff --git a/Rx.NET/Source/src/System.Reactive/AnonymousObservable.cs b/Rx.NET/Source/src/System.Reactive/AnonymousObservable.cs
index 93ed5e6c6a..c4a5a93815 100644
--- a/Rx.NET/Source/src/System.Reactive/AnonymousObservable.cs
+++ b/Rx.NET/Source/src/System.Reactive/AnonymousObservable.cs
@@ -21,10 +21,7 @@ public sealed class AnonymousObservable : ObservableBase
/// is null.
public AnonymousObservable(Func, IDisposable> subscribe)
{
- if (subscribe == null)
- throw new ArgumentNullException(nameof(subscribe));
-
- _subscribe = subscribe;
+ _subscribe = subscribe ?? throw new ArgumentNullException(nameof(subscribe));
}
///
diff --git a/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs b/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs
index 9e947738d0..7588639e9b 100644
--- a/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs
+++ b/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs
@@ -23,16 +23,9 @@ public sealed class AnonymousObserver : ObserverBase
/// or or is null.
public AnonymousObserver(Action onNext, Action onError, Action onCompleted)
{
- if (onNext == null)
- throw new ArgumentNullException(nameof(onNext));
- if (onError == null)
- throw new ArgumentNullException(nameof(onError));
- if (onCompleted == null)
- throw new ArgumentNullException(nameof(onCompleted));
-
- _onNext = onNext;
- _onError = onError;
- _onCompleted = onCompleted;
+ _onNext = onNext ?? throw new ArgumentNullException(nameof(onNext));
+ _onError = onError ?? throw new ArgumentNullException(nameof(onError));
+ _onCompleted = onCompleted ?? throw new ArgumentNullException(nameof(onCompleted));
}
///
diff --git a/Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs b/Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs
index 8ddd722b18..10abcc0e5a 100644
--- a/Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs
+++ b/Rx.NET/Source/src/System.Reactive/AnonymousSafeObserver.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
-using System.Reactive.Disposables;
using System.Threading;
namespace System.Reactive
@@ -47,7 +46,9 @@ public override void OnNext(T value)
finally
{
if (!__noError)
+ {
Dispose();
+ }
}
}
}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/AsyncLock.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/AsyncLock.cs
index 55f4f09b0b..c0866bfd64 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/AsyncLock.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/AsyncLock.cs
@@ -13,7 +13,7 @@ public sealed class AsyncLock : IDisposable
{
private bool isAcquired = false;
private bool hasFaulted = false;
- private object guard = new object();
+ private readonly object guard = new object();
private Queue<(Action action, Delegate @delegate, object state)> queue;
///
@@ -26,7 +26,9 @@ public sealed class AsyncLock : IDisposable
public void Wait(Action action)
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
Wait(action, closureAction => closureAction());
}
@@ -44,13 +46,15 @@ public void Wait(Action action)
internal void Wait(TState state, Action action)
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
Wait(state, action, (actionObject, stateObject) => ((Action)actionObject)((TState)stateObject));
}
private void Wait(object state, Delegate @delegate, Action action)
- {
+ {
// allow one thread to update the state
lock (guard)
{
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/CatchScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/CatchScheduler.cs
index 1f0315067e..cc77789c05 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/CatchScheduler.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/CatchScheduler.cs
@@ -77,7 +77,7 @@ public CatchSchedulerLongRunning(ISchedulerLongRunning scheduler, Func(TState state, Action action)
{
return _scheduler.ScheduleLongRunning(
- (scheduler: this, action, state),
+ (scheduler: this, action, state),
(tuple, cancel) =>
{
try
@@ -124,7 +124,9 @@ public void Dispose()
// take effect.
//
if (_failed)
+ {
return default;
+ }
try
{
@@ -135,7 +137,9 @@ public void Dispose()
_failed = true;
if (!_catchScheduler._handler(exception))
+ {
throw;
+ }
Disposable.TryDispose(ref _cancel);
return default;
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs
index c1054756cd..af37d2b79e 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs
@@ -33,7 +33,9 @@ public WorkItem(Action
public sealed class NewThreadScheduler : LocalScheduler, ISchedulerLongRunning, ISchedulerPeriodic
{
- internal static readonly Lazy s_instance = new Lazy(() => new NewThreadScheduler());
+ internal static readonly Lazy Instance = new Lazy(() => new NewThreadScheduler());
private readonly Func _threadFactory;
@@ -27,7 +27,7 @@ public NewThreadScheduler()
///
/// Gets an instance of this scheduler that uses the default Thread constructor.
///
- public static NewThreadScheduler Default => s_instance.Value;
+ public static NewThreadScheduler Default => Instance.Value;
#if !NO_THREAD
///
@@ -37,13 +37,11 @@ public NewThreadScheduler()
/// is null.
public NewThreadScheduler(Func threadFactory)
{
- if (threadFactory == null)
- throw new ArgumentNullException(nameof(threadFactory));
#else
private NewThreadScheduler(Func threadFactory)
{
#endif
- _threadFactory = threadFactory;
+ _threadFactory = threadFactory ?? throw new ArgumentNullException(nameof(threadFactory));
}
///
@@ -58,10 +56,14 @@ private NewThreadScheduler(Func threadFactory)
public override IDisposable Schedule(TState state, TimeSpan dueTime, Func action)
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
- var scheduler = new EventLoopScheduler(_threadFactory);
- scheduler.ExitIfEmpty = true;
+ var scheduler = new EventLoopScheduler(_threadFactory)
+ {
+ ExitIfEmpty = true
+ };
return scheduler.Schedule(state, dueTime, action);
}
@@ -76,7 +78,9 @@ public override IDisposable Schedule(TState state, TimeSpan dueTime, Fun
public IDisposable ScheduleLongRunning(TState state, Action action)
{
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var d = new BooleanDisposable();
@@ -108,9 +112,14 @@ public IDisposable ScheduleLongRunning(TState state, Action(TState state, TimeSpan period, Func action)
{
if (period < TimeSpan.Zero)
+ {
throw new ArgumentOutOfRangeException(nameof(period));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
var periodic = new Periodic(state, period, action);
@@ -152,7 +161,9 @@ public void Run()
lock (_cancel)
{
if (Monitor.Wait(_cancel, timeout))
+ {
return;
+ }
}
_state = _action(_state);
@@ -185,4 +196,4 @@ public override IStopwatch StartStopwatch()
return new StopwatchImpl();
}
}
-}
\ No newline at end of file
+}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs
index d1764c342e..0c5b730574 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs
@@ -25,11 +25,8 @@ public abstract class ScheduledItem : IScheduledItem, ICom
/// is null.
protected ScheduledItem(TAbsolute dueTime, IComparer comparer)
{
- if (comparer == null)
- throw new ArgumentNullException(nameof(comparer));
-
DueTime = dueTime;
- _comparer = comparer;
+ _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
}
///
@@ -65,7 +62,7 @@ public void Invoke()
public int CompareTo(ScheduledItem other)
{
// MSDN: By definition, any object compares greater than null, and two null references compare equal to each other.
- if (ReferenceEquals(other, null))
+ if (other is null)
{
return 1;
}
@@ -186,14 +183,9 @@ public sealed class ScheduledItem : ScheduledItem
public ScheduledItem(IScheduler scheduler, TValue state, Func action, TAbsolute dueTime, IComparer comparer)
: base(dueTime, comparer)
{
- if (scheduler == null)
- throw new ArgumentNullException(nameof(scheduler));
- if (action == null)
- throw new ArgumentNullException(nameof(action));
-
- _scheduler = scheduler;
+ _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
_state = state;
- _action = action;
+ _action = action ?? throw new ArgumentNullException(nameof(action));
}
///
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs
index 475ef2af26..3a6fa7ea70 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs
@@ -20,7 +20,9 @@ public static partial class Scheduler
public static SchedulerOperation Yield(this IScheduler scheduler)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(a), scheduler.GetCancellationToken());
}
@@ -36,7 +38,9 @@ public static SchedulerOperation Yield(this IScheduler scheduler)
public static SchedulerOperation Yield(this IScheduler scheduler, CancellationToken cancellationToken)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(a), cancellationToken);
}
@@ -52,7 +56,9 @@ public static SchedulerOperation Yield(this IScheduler scheduler, CancellationTo
public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
}
@@ -69,7 +75,9 @@ public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTi
public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime, CancellationToken cancellationToken)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
}
@@ -85,7 +93,9 @@ public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTi
public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
}
@@ -102,7 +112,9 @@ public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset
public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime, CancellationToken cancellationToken)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
}
@@ -119,9 +131,14 @@ public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset
public static IDisposable ScheduleAsync(this IScheduler scheduler, TState state, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, action);
}
@@ -138,9 +155,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, TState state, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, action);
}
@@ -155,9 +177,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -172,9 +199,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -192,9 +224,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, Func(this IScheduler scheduler, TState state, TimeSpan dueTime, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, dueTime, action);
}
@@ -212,9 +249,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, TState state, TimeSpan dueTime, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, dueTime, action);
}
@@ -230,9 +272,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -248,9 +295,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueT
public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -268,9 +320,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueT
public static IDisposable ScheduleAsync(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, dueTime, action);
}
@@ -288,9 +345,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, state, dueTime, action);
}
@@ -306,9 +368,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, TStat
public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -324,9 +391,14 @@ public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffse
public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
}
@@ -369,7 +441,9 @@ private static IDisposable InvokeAsync(IScheduler self, TState s, Func
{
if (t.IsCanceled)
+ {
return;
+ }
if (t.Exception != null)
{
@@ -389,8 +463,7 @@ private static IDisposable InvokeAsync(IScheduler self, TState s, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule(action, (_action, self) => _action(() => self(_action)));
}
@@ -38,9 +42,14 @@ public static IDisposable Schedule(this IScheduler scheduler, Action act
public static IDisposable Schedule(this IScheduler scheduler, TState state, Action> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule((state, action), (s, p) => InvokeRec1(s, p));
}
@@ -63,9 +72,14 @@ private static IDisposable InvokeRec1(IScheduler scheduler, (TState stat
public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule(action, dueTime, (_action, self) => _action(dt => self(_action, dt)));
}
@@ -83,9 +97,14 @@ public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime,
public static IDisposable Schedule(this IScheduler scheduler, TState state, TimeSpan dueTime, Action> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule((state, action), dueTime, (s, p) => InvokeRec2(s, p));
}
@@ -108,9 +127,14 @@ private static IDisposable InvokeRec2(IScheduler scheduler, (TState stat
public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule(action, dueTime, (_action, self) => _action(dt => self(_action, dt)));
}
@@ -128,9 +152,14 @@ public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset due
public static IDisposable Schedule(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Action> action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule((state, action), dueTime, (s, p) => InvokeRec3(s, p));
}
@@ -142,7 +171,7 @@ private static IDisposable InvokeRec3(IScheduler scheduler, (TState stat
return recursiveInvoker;
}
- abstract class InvokeRecBaseState : IDisposable
+ private abstract class InvokeRecBaseState : IDisposable
{
protected readonly IScheduler scheduler;
@@ -161,11 +190,10 @@ public void Dispose()
}
- sealed class InvokeRec1State : InvokeRecBaseState
+ private sealed class InvokeRec1State : InvokeRecBaseState
{
- readonly Action> action;
-
- readonly Action recurseCallback;
+ private readonly Action> action;
+ private readonly Action recurseCallback;
public InvokeRec1State(IScheduler scheduler, Action> action) : base(scheduler)
{
@@ -177,7 +205,8 @@ internal void InvokeNext(TState state)
{
var sad = new SingleAssignmentDisposable();
group.Add(sad);
- sad.Disposable = scheduler.Schedule((state, sad, @this: this), (_, nextState) => {
+ sad.Disposable = scheduler.Schedule((state, sad, @this: this), (_, nextState) =>
+ {
nextState.@this.group.Remove(nextState.sad);
nextState.@this.InvokeFirst(nextState.state);
return Disposable.Empty;
@@ -190,11 +219,10 @@ internal void InvokeFirst(TState state)
}
}
- sealed class InvokeRec2State : InvokeRecBaseState
+ private sealed class InvokeRec2State : InvokeRecBaseState
{
- readonly Action> action;
-
- readonly Action recurseCallback;
+ private readonly Action> action;
+ private readonly Action recurseCallback;
public InvokeRec2State(IScheduler scheduler, Action> action) : base(scheduler)
{
@@ -206,7 +234,8 @@ internal void InvokeNext(TState state, TimeSpan time)
{
var sad = new SingleAssignmentDisposable();
group.Add(sad);
- sad.Disposable = scheduler.Schedule((state, sad, @this: this), time, (_, nextState) => {
+ sad.Disposable = scheduler.Schedule((state, sad, @this: this), time, (_, nextState) =>
+ {
nextState.@this.group.Remove(nextState.sad);
nextState.@this.InvokeFirst(nextState.state);
return Disposable.Empty;
@@ -219,11 +248,10 @@ internal void InvokeFirst(TState state)
}
}
- sealed class InvokeRec3State : InvokeRecBaseState
+ private sealed class InvokeRec3State : InvokeRecBaseState
{
- readonly Action> action;
-
- readonly Action recurseCallback;
+ private readonly Action> action;
+ private readonly Action recurseCallback;
public InvokeRec3State(IScheduler scheduler, Action> action) : base(scheduler)
{
@@ -235,7 +263,8 @@ internal void InvokeNext(TState state, DateTimeOffset dtOffset)
{
var sad = new SingleAssignmentDisposable();
group.Add(sad);
- sad.Disposable = scheduler.Schedule((state, sad, @this: this), dtOffset, (_, nextState) => {
+ sad.Disposable = scheduler.Schedule((state, sad, @this: this), dtOffset, (_, nextState) =>
+ {
nextState.@this.group.Remove(nextState.sad);
nextState.@this.InvokeFirst(nextState.state);
return Disposable.Empty;
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs
index e4d98ee047..012dfbcd32 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs
@@ -28,11 +28,19 @@ public static partial class Scheduler
public static IDisposable SchedulePeriodic(this IScheduler scheduler, TState state, TimeSpan period, Func action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (period < TimeSpan.Zero)
+ {
throw new ArgumentOutOfRangeException(nameof(period));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return SchedulePeriodic_(scheduler, state, period, action);
}
@@ -54,11 +62,19 @@ public static IDisposable SchedulePeriodic(this IScheduler scheduler, TS
public static IDisposable SchedulePeriodic(this IScheduler scheduler, TState state, TimeSpan period, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (period < TimeSpan.Zero)
+ {
throw new ArgumentOutOfRangeException(nameof(period));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return SchedulePeriodic_(scheduler, (state, action), period, t => { t.action(t.state); return t; });
}
@@ -78,11 +94,19 @@ public static IDisposable SchedulePeriodic(this IScheduler scheduler, TS
public static IDisposable SchedulePeriodic(this IScheduler scheduler, TimeSpan period, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (period < TimeSpan.Zero)
+ {
throw new ArgumentOutOfRangeException(nameof(period));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return SchedulePeriodic_(scheduler, action, period, a => { a(); return a; });
}
@@ -99,7 +123,9 @@ public static IDisposable SchedulePeriodic(this IScheduler scheduler, TimeSpan p
public static IStopwatch StartStopwatch(this IScheduler scheduler)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
//
// All schedulers deriving from LocalScheduler will automatically pick up this
@@ -576,7 +602,9 @@ private void Tick(int command, Action recurse)
// safely bail out, delegating work to the catch-up tail calls.
//
if (Interlocked.Increment(ref _pendingTickCount) == 1)
+ {
goto case DISPATCH_START;
+ }
break;
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
index bf6d5788eb..de0246628c 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
@@ -18,9 +18,14 @@ public static partial class Scheduler
public static IDisposable Schedule(this IScheduler scheduler, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
// Surprisingly, passing the method group of Invoke will create a fresh
// delegate each time although it's static, while an anonymous
@@ -44,12 +49,17 @@ public static IDisposable Schedule(this IScheduler scheduler, Action action)
internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.Schedule(
- (action, state),
+ (action, state),
(_, tuple) =>
{
tuple.action(tuple.state);
@@ -68,9 +78,14 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS
public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
// See note above.
return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
@@ -88,9 +103,14 @@ public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime,
internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, TimeSpan dueTime, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
// See note above.
return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
@@ -107,9 +127,14 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS
public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
// See note above.
return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
@@ -127,9 +152,14 @@ public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset due
internal static IDisposable ScheduleAction(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
// See note above.
return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
@@ -145,9 +175,14 @@ internal static IDisposable ScheduleAction(this IScheduler scheduler, TS
public static IDisposable ScheduleLongRunning(this ISchedulerLongRunning scheduler, Action action)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (action == null)
+ {
throw new ArgumentNullException(nameof(action));
+ }
return scheduler.ScheduleLongRunning(action, (a, c) => a(c));
}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs
index 86e08eb5b0..a692d9fcea 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs
@@ -15,7 +15,9 @@ public static partial class Scheduler
public static IScheduler DisableOptimizations(this IScheduler scheduler)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
return new DisableOptimizationsScheduler(scheduler);
}
@@ -30,9 +32,14 @@ public static IScheduler DisableOptimizations(this IScheduler scheduler)
public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
{
if (scheduler == null)
+ {
throw new ArgumentNullException(nameof(scheduler));
+ }
+
if (optimizationInterfaces == null)
+ {
throw new ArgumentNullException(nameof(optimizationInterfaces));
+ }
return new DisableOptimizationsScheduler(scheduler, optimizationInterfaces);
}
@@ -49,9 +56,14 @@ public static IScheduler Catch(this IScheduler scheduler, Func(scheduler, handler);
}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
index fd590c208d..4077118f9b 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
@@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
-using System.Reactive.PlatformServices;
using System.Globalization;
+using System.Reactive.PlatformServices;
namespace System.Reactive.Concurrency
{
@@ -90,7 +90,10 @@ private static IScheduler Initialize(string name)
var res = PlatformEnlightenmentProvider.Current.GetService(name);
#pragma warning restore CS0618 // Type or member is obsolete
if (res == null)
+ {
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings_Core.CANT_OBTAIN_SCHEDULER, name));
+ }
+
return res;
}
}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs
index e7462b4186..0c812717ce 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs
@@ -89,10 +89,14 @@ internal SchedulerOperationAwaiter(Func schedule, Cancellat
public void OnCompleted(Action continuation)
{
if (continuation == null)
+ {
throw new ArgumentNullException(nameof(continuation));
+ }
if (_continuation != null)
+ {
throw new InvalidOperationException(Strings_Core.SCHEDULER_OPERATION_ALREADY_AWAITED);
+ }
if (_postBackToOriginalContext)
{
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs
index 57a7f04b2d..bdad239415 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs
@@ -31,7 +31,9 @@ public SchedulerQueue()
public SchedulerQueue(int capacity)
{
if (capacity < 0)
+ {
throw new ArgumentOutOfRangeException(nameof(capacity));
+ }
_queue = new PriorityQueue>(capacity);
}
diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs
index ad1e8043e3..4aac7c60bd 100644
--- a/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs
+++ b/Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs
@@ -28,7 +28,9 @@ public SchedulerWrapper(IScheduler scheduler, ConditionalWeakTable