Browse Source

Use C# 7 language features

Oren Novotny 8 years ago
parent
commit
41064bf39d
29 changed files with 126 additions and 130 deletions
  1. 79 0
      .editorconfig
  2. 0 21
      Ix.NET/Source/Ix.NET.sln.DotSettings
  3. 0 6
      Ix.NET/Source/Ix.NET.v3.ncrunchsolution
  4. 2 4
      Ix.NET/Source/System.Interactive.Async.Providers/AsyncQueryable.cs
  5. 0 5
      Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.v3.ncrunchproject
  6. 6 12
      Ix.NET/Source/System.Interactive.Async/AppendPrepend.cs
  7. 1 2
      Ix.NET/Source/System.Interactive.Async/AsyncEnumerableHelpers.cs
  8. 1 2
      Ix.NET/Source/System.Interactive.Async/Cast.cs
  9. 1 2
      Ix.NET/Source/System.Interactive.Async/Concatenate.cs
  10. 2 4
      Ix.NET/Source/System.Interactive.Async/Count.cs
  11. 1 2
      Ix.NET/Source/System.Interactive.Async/ElementAt.cs
  12. 2 4
      Ix.NET/Source/System.Interactive.Async/Last.cs
  13. 7 5
      Ix.NET/Source/System.Interactive.Async/Lookup.cs
  14. 1 2
      Ix.NET/Source/System.Interactive.Async/Reverse.cs
  15. 3 5
      Ix.NET/Source/System.Interactive.Async/Select.cs
  16. 2 4
      Ix.NET/Source/System.Interactive.Async/SequenceEqual.cs
  17. 2 4
      Ix.NET/Source/System.Interactive.Async/Single.cs
  18. 0 5
      Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.v3.ncrunchproject
  19. 2 4
      Ix.NET/Source/System.Interactive.Async/ToAsyncEnumerable.cs
  20. 2 4
      Ix.NET/Source/System.Interactive.Async/ToCollection.cs
  21. 1 2
      Ix.NET/Source/System.Interactive.Async/Where.cs
  22. 3 6
      Ix.NET/Source/System.Interactive.Providers/QueryableEx.cs
  23. 0 5
      Ix.NET/Source/System.Interactive.Tests.Uwp.DeviceRunner/System.Interactive.Tests.Uwp.DeviceRunner.v3.ncrunchproject
  24. 1 2
      Ix.NET/Source/System.Interactive/Case.cs
  25. 1 2
      Ix.NET/Source/System.Interactive/Memoize.cs
  26. 0 5
      Ix.NET/Source/System.Interactive/System.Interactive.v3.ncrunchproject
  27. 5 5
      Ix.NET/Source/Tests/AsyncTests.Single.cs
  28. 1 1
      Ix.NET/Source/Tests/Tests.csproj
  29. 0 5
      Ix.NET/Source/Tests/Tests.v3.ncrunchproject

+ 79 - 0
.editorconfig

@@ -0,0 +1,79 @@
+# EditorConfig is awesome:http://EditorConfig.org
+# From https://raw.githubusercontent.com/dotnet/roslyn/master/.editorconfig
+
+# top-most EditorConfig file
+root = 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
+
+# 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
+
+# JSON files
+[*.json]
+indent_size = 2
+
+# Dotnet code style settings:
+[*.{cs,vb}]
+# Sort using and Import directives with System.* appearing first
+dotnet_sort_system_directives_first = true
+# 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 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
+
+# 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
+
+# CSharp code style settings:
+[*.cs]
+# 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
+
+# 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
+
+# Suggest more modern language features when available
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+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

File diff suppressed because it is too large
+ 0 - 21
Ix.NET/Source/Ix.NET.sln.DotSettings


+ 0 - 6
Ix.NET/Source/Ix.NET.v3.ncrunchsolution

@@ -1,6 +0,0 @@
-<SolutionConfiguration>
-  <Settings>
-    <AllowParallelTestExecution>True</AllowParallelTestExecution>
-    <SolutionConfigured>True</SolutionConfigured>
-  </Settings>
-</SolutionConfiguration>

+ 2 - 4
Ix.NET/Source/System.Interactive.Async.Providers/AsyncQueryable.cs

@@ -23,8 +23,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var queryable = source as IAsyncQueryable<TElement>;
-            if (queryable != null)
+            if (source is IAsyncQueryable<TElement> queryable)
             {
                 return queryable;
             }
@@ -34,8 +33,7 @@ namespace System.Linq
 
         private static Expression GetSourceExpression<TSource>(IAsyncEnumerable<TSource> source)
         {
-            var queryable = source as IAsyncQueryable<TSource>;
-            if (queryable != null)
+            if (source is IAsyncQueryable<TSource> queryable)
             {
                 return queryable.Expression;
             }

+ 0 - 5
Ix.NET/Source/System.Interactive.Async.Providers/System.Interactive.Async.Providers.v3.ncrunchproject

@@ -1,5 +0,0 @@
-<ProjectConfiguration>
-  <Settings>
-    <PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
-  </Settings>
-</ProjectConfiguration>

+ 6 - 12
Ix.NET/Source/System.Interactive.Async/AppendPrepend.cs

@@ -18,8 +18,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var appendable = source as AppendPrepentAsyncIterator<TSource>;
-            if (appendable != null)
+            if (source is AppendPrepentAsyncIterator<TSource> appendable)
             {
                 return appendable.Append(element);
             }
@@ -32,8 +31,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var appendable = source as AppendPrepentAsyncIterator<TSource>;
-            if (appendable != null)
+            if (source is AppendPrepentAsyncIterator<TSource> appendable)
             {
                 return appendable.Prepend(element);
             }
@@ -197,8 +195,7 @@ namespace System.Linq
                     index = 1;
                 }
 
-                var sourceCollection = source as ICollection<TSource>;
-                if (sourceCollection != null)
+                if (source is ICollection<TSource> sourceCollection)
                 {
                     sourceCollection.CopyTo(array, index);
                 }
@@ -253,8 +250,7 @@ namespace System.Linq
 
             public override async Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken)
             {
-                var listProv = source as IIListProvider<TSource>;
-                if (listProv != null)
+                if (source is IIListProvider<TSource> listProv)
                 {
                     var count = await listProv.GetCountAsync(onlyIfCheap, cancellationToken).ConfigureAwait(false);
                     return count == -1 ? -1 : count + 1;
@@ -433,8 +429,7 @@ namespace System.Linq
                     ++index;
                 }
 
-                var sourceCollection = source as ICollection<TSource>;
-                if (sourceCollection != null)
+                if (source is ICollection<TSource> sourceCollection)
                 {
                     sourceCollection.CopyTo(array, index);
                 }
@@ -496,8 +491,7 @@ namespace System.Linq
 
             public override async Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken)
             {
-                var listProv = source as IIListProvider<TSource>;
-                if (listProv != null)
+                if (source is IIListProvider<TSource> listProv)
                 {
                     var count = await listProv.GetCountAsync(onlyIfCheap, cancellationToken).ConfigureAwait(false);
                     return count == -1 ? -1 : count + (appended == null ? 0 : appended.Count) + (prepended == null ? 0 : prepended.Count);

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/AsyncEnumerableHelpers.cs

@@ -24,8 +24,7 @@ namespace System.Collections.Generic
             var result = new ArrayWithLength<T>();
             // Check for short circuit optimizations. This one is very unlikely
             // but could be here as a group
-            var ic = source as ICollection<T>;
-            if (ic != null)
+            if (source is ICollection<T> ic)
             {
                 var count = ic.Count;
                 if (count != 0)

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/Cast.cs

@@ -17,8 +17,7 @@ namespace System.Linq
                 throw new ArgumentNullException(nameof(source));
 
             // Check to see if it already is and short-circuit
-            var typedSource = source as IAsyncEnumerable<TResult>;
-            if (typedSource != null)
+            if (source is IAsyncEnumerable<TResult> typedSource)
             {
                 return typedSource;
             }

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/Concatenate.cs

@@ -343,8 +343,7 @@ namespace System.Linq
                         return current.next;
                     }
 
-                    var prevN = current.previousConcat as ConcatNAsyncIterator<TSource>;
-                    if (prevN != null)
+                    if (current.previousConcat is ConcatNAsyncIterator<TSource> prevN)
                     {
                         current = prevN;
                         continue;

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/Count.cs

@@ -17,14 +17,12 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var collection = source as ICollection<TSource>;
-            if (collection != null)
+            if (source is ICollection<TSource> collection)
             {
                 return Task.FromResult(collection.Count);
             }
 
-            var listProv = source as IIListProvider<TSource>;
-            if (listProv != null)
+            if (source is IIListProvider<TSource> listProv)
             {
                 return listProv.GetCountAsync(false, cancellationToken);
             }

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/ElementAt.cs

@@ -51,8 +51,7 @@ namespace System.Linq
 
         private static async Task<TSource> ElementAt_<TSource>(IAsyncEnumerable<TSource> source, int index, CancellationToken cancellationToken)
         {
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
             {
                 return list[index];
             }

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/Last.cs

@@ -91,8 +91,7 @@ namespace System.Linq
             var last = default(TSource);
             var hasLast = false;
 
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
             {
                 var count = list.Count;
                 if (count > 0)
@@ -120,8 +119,7 @@ namespace System.Linq
             var last = default(TSource);
             var hasLast = false;
 
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
             {
                 var count = list.Count;
                 if (count > 0)

+ 7 - 5
Ix.NET/Source/System.Interactive.Async/Lookup.cs

@@ -267,11 +267,13 @@ namespace System.Linq.Internal
                 }
 
                 var index = hashCode%_groupings.Length;
-                var g = new Grouping<TKey, TElement>();
-                g._key = key;
-                g._hashCode = hashCode;
-                g._elements = new TElement[1];
-                g._hashNext = _groupings[index];
+                var g = new Grouping<TKey, TElement>
+                {
+                    _key = key,
+                    _hashCode = hashCode,
+                    _elements = new TElement[1],
+                    _hashNext = _groupings[index]
+                };
                 _groupings[index] = g;
                 if (_lastGrouping == null)
                 {

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/Reverse.cs

@@ -64,8 +64,7 @@ namespace System.Linq
             {
                 if (onlyIfCheap)
                 {
-                    var listProv = source as IIListProvider<TSource>;
-                    if (listProv != null)
+                    if (source is IIListProvider<TSource> listProv)
                     {
                         return listProv.GetCountAsync(true, cancellationToken);
                     }

+ 3 - 5
Ix.NET/Source/System.Interactive.Async/Select.cs

@@ -17,15 +17,13 @@ namespace System.Linq
                 throw new ArgumentNullException(nameof(source));
             if (selector == null)
                 throw new ArgumentNullException(nameof(selector));
-            
-            var iterator = source as AsyncIterator<TSource>;
-            if (iterator != null)
+
+            if (source is AsyncIterator<TSource> iterator)
             {
                 return iterator.Select(selector);
             }
 
-            var ilist = source as IList<TSource>;
-            if (ilist != null)
+            if (source is IList<TSource> ilist)
             {
                 return new SelectIListIterator<TSource, TResult>(ilist, selector);
             }

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/SequenceEqual.cs

@@ -60,11 +60,9 @@ namespace System.Linq
         private static async Task<bool> SequenceEqual_<TSource>(IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer,
                                                                 CancellationToken cancellationToken)
         {
-            var firstCol = first as ICollection<TSource>;
-            if (firstCol != null)
+            if (first is ICollection<TSource> firstCol)
             {
-                var secondCol = second as ICollection<TSource>;
-                if (secondCol != null && firstCol.Count != secondCol.Count)
+                if (second is ICollection<TSource> secondCol && firstCol.Count != secondCol.Count)
                 {
                     return false;
                 }

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/Single.cs

@@ -89,8 +89,7 @@ namespace System.Linq
 
         private static async Task<TSource> Single_<TSource>(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
         {
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
             {
                 switch (list.Count)
                 {
@@ -119,8 +118,7 @@ namespace System.Linq
 
         private static async Task<TSource> SingleOrDefault_<TSource>(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
         {
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
             {
                 switch (list.Count)
                 {

+ 0 - 5
Ix.NET/Source/System.Interactive.Async/System.Interactive.Async.v3.ncrunchproject

@@ -1,5 +0,0 @@
-<ProjectConfiguration>
-  <Settings>
-    <PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
-  </Settings>
-</ProjectConfiguration>

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/ToAsyncEnumerable.cs

@@ -18,12 +18,10 @@ namespace System.Linq
                 throw new ArgumentNullException(nameof(source));
 
             // optimize these adapters for lists and collections
-            var list = source as IList<TSource>;
-            if (list != null)
+            if (source is IList<TSource> list)
                 return new AsyncIListEnumerableAdapter<TSource>(list);
 
-            var collection = source as ICollection<TSource>;
-            if (collection != null)
+            if (source is ICollection<TSource> collection)
                 return new AsyncICollectionEnumerableAdapter<TSource>(collection);
 
             return new AsyncEnumerableAdapter<TSource>(source);

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/ToCollection.cs

@@ -25,8 +25,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var arrayProvider = source as IIListProvider<TSource>;
-            if (arrayProvider != null)
+            if (source is IIListProvider<TSource> arrayProvider)
                 return arrayProvider.ToArrayAsync(cancellationToken);
 
             return AsyncEnumerableHelpers.ToArray(source, cancellationToken);
@@ -145,8 +144,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
-            var listProvider = source as IIListProvider<TSource>;
-            if (listProvider != null)
+            if (source is IIListProvider<TSource> listProvider)
                 return listProvider.ToListAsync(cancellationToken);
 
             return source.Aggregate(new List<TSource>(), (list, x) =>

+ 1 - 2
Ix.NET/Source/System.Interactive.Async/Where.cs

@@ -18,8 +18,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            var iterator = source as AsyncIterator<TSource>;
-            if (iterator != null)
+            if (source is AsyncIterator<TSource> iterator)
             {
                 return iterator.Where(predicate);
             }

+ 3 - 6
Ix.NET/Source/System.Interactive.Providers/QueryableEx.cs

@@ -2401,13 +2401,11 @@ namespace System.Linq
 
             private static Expression Redir(Expression expression)
             {
-                var mce = expression as MethodCallExpression;
-                if (mce != null && mce.Method.DeclaringType == typeof(QueryableEx))
+                if (expression is MethodCallExpression mce && mce.Method.DeclaringType == typeof(QueryableEx))
                 {
                     if (mce.Arguments.Count >= 1 && typeof(IQueryProvider).IsAssignableFrom(mce.Arguments[0].Type))
                     {
-                        var ce = mce.Arguments[0] as ConstantExpression;
-                        if (ce != null)
+                        if (mce.Arguments[0] is ConstantExpression ce)
                         {
                             if (ce.Value is QueryProviderShim)
                             {
@@ -2525,8 +2523,7 @@ namespace System.Linq
 
         internal static Expression GetSourceExpression<TSource>(IEnumerable<TSource> source)
         {
-            var q = source as IQueryable<TSource>;
-            if (q != null)
+            if (source is IQueryable<TSource> q)
                 return q.Expression;
 
             return Expression.Constant(source, typeof(IEnumerable<TSource>));

+ 0 - 5
Ix.NET/Source/System.Interactive.Tests.Uwp.DeviceRunner/System.Interactive.Tests.Uwp.DeviceRunner.v3.ncrunchproject

@@ -1,5 +0,0 @@
-<ProjectConfiguration>
-  <Settings>
-    <IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
-  </Settings>
-</ProjectConfiguration>

+ 1 - 2
Ix.NET/Source/System.Interactive/Case.cs

@@ -53,8 +53,7 @@ namespace System.Linq
 
             return Defer(() =>
                          {
-                             IEnumerable<TResult> result;
-                             if (!sources.TryGetValue(selector(), out result))
+                             if (!sources.TryGetValue(selector(), out var result))
                                  result = defaultSource;
                              return result;
                          });

+ 1 - 2
Ix.NET/Source/System.Interactive/Memoize.cs

@@ -333,8 +333,7 @@ namespace System.Linq
             {
                 Debug.Assert(i < _count);
 
-                var res = default(RefCount);
-                if (!_list.TryGetValue(i, out res))
+                if (!_list.TryGetValue(i, out var res))
                     throw new InvalidOperationException("Element no longer available in the buffer.");
 
                 var val = res.Value;

+ 0 - 5
Ix.NET/Source/System.Interactive/System.Interactive.v3.ncrunchproject

@@ -1,5 +0,0 @@
-<ProjectConfiguration>
-  <Settings>
-    <PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
-  </Settings>
-</ProjectConfiguration>

+ 5 - 5
Ix.NET/Source/Tests/AsyncTests.Single.cs

@@ -1822,7 +1822,7 @@ namespace Tests
             var ys = xs.OrderBy(x => x);
 
             var e = ys.GetEnumerator();
-            for (int i = 0; i < 10; i++)
+            for (var i = 0; i < 10; i++)
                 HasNext(e, i);
             NoNext(e);
         }
@@ -1852,7 +1852,7 @@ namespace Tests
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 2, 6, 1, 5, 7, 8, 9, 3, 4, 0 }.ToAsyncEnumerable();
-            var ys = xs.OrderBy<int, int>(x => x).ThenBy<int, int>(x => { throw ex; });
+            var ys = xs.OrderBy(x => x).ThenBy<int, int>(x => { throw ex; });
 
             var e = ys.GetEnumerator();
             AssertThrows<Exception>(() => e.MoveNext().Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
@@ -1865,7 +1865,7 @@ namespace Tests
             var ys = xs.OrderByDescending(x => x);
 
             var e = ys.GetEnumerator();
-            for (int i = 9; i >= 0; i--)
+            for (var i = 9; i >= 0; i--)
                 HasNext(e, i);
             NoNext(e);
         }
@@ -2810,7 +2810,7 @@ namespace Tests
             {
                 if (ReferenceEquals(null, obj)) return false;
                 if (ReferenceEquals(this, obj)) return true;
-                if (obj.GetType() != this.GetType()) return false;
+                if (obj.GetType() != GetType()) return false;
                 return Equals((Kvp)obj);
             }
 
@@ -3445,7 +3445,7 @@ namespace Tests
         [Fact]
         public void TakeLast_BugFix_TakeLast_Zero_TakesForever()
         {
-            bool isSet = false;
+            var isSet = false;
             new int[] { 1, 2, 3, 4 }.ToAsyncEnumerable()
                 .TakeLast(0)
                 .ForEachAsync(_ => { isSet = true; })

+ 1 - 1
Ix.NET/Source/Tests/Tests.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>netcoreapp1.0;net461</TargetFrameworks>
+    <TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks>
     <NoWarn>$(NoWarn);CS0618</NoWarn>
   </PropertyGroup>
 

+ 0 - 5
Ix.NET/Source/Tests/Tests.v3.ncrunchproject

@@ -1,5 +0,0 @@
-<ProjectConfiguration>
-  <Settings>
-    <PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
-  </Settings>
-</ProjectConfiguration>

Some files were not shown because too many files changed in this diff