| | 1 | | /* |
| | 2 | | * Copyright 2018 Stanislav Muhametsin. All rights Reserved. |
| | 3 | | * |
| | 4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | 5 | | * you may not use this file except in compliance with the License. |
| | 6 | | * You may obtain a copy of the License at |
| | 7 | | * |
| | 8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | 9 | | * |
| | 10 | | * Unless required by applicable law or agreed to in writing, software |
| | 11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | 12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| | 13 | | * implied. |
| | 14 | | * |
| | 15 | | * See the License for the specific language governing permissions and |
| | 16 | | * limitations under the License. |
| | 17 | | */ |
| | 18 | | using System; |
| | 19 | | using System.Collections.Generic; |
| | 20 | | using System.Threading.Tasks; |
| | 21 | | using TTypeInfo = |
| | 22 | | #if NET40 |
| | 23 | | System.Type |
| | 24 | | #else |
| | 25 | | System.Reflection.TypeInfo |
| | 26 | | #endif |
| | 27 | | ; |
| | 28 | |
|
| | 29 | | namespace AsyncEnumeration.Abstractions |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// This interface contains methods of <see cref="IAsyncEnumerable{T}"/> which do not require type argument, and are |
| | 33 | | /// </summary> |
| | 34 | | public interface IAsyncEnumerable |
| | 35 | | { |
| | 36 | | /// <summary> |
| | 37 | | /// Gets the <see cref="IAsyncProvider"/> of this<see cref="IAsyncEnumerable"/>. |
| | 38 | | /// </summary> |
| | 39 | | /// <value>The <see cref="IAsyncProvider"/> of this<see cref="IAsyncEnumerable"/>.</value> |
| | 40 | | /// <seealso cref="IAsyncProvider"/> |
| | 41 | | IAsyncProvider AsyncProvider { get; } |
| | 42 | |
|
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// This interface contains method which are like LINQ but for <see cref="IAsyncEnumerable{T}"/>. |
| | 47 | | /// These methods allow the creators of <see cref="IAsyncEnumerable{T}"/> to customize how the created <see cref="IAs |
| | 48 | | /// </summary> |
| | 49 | | public partial interface IAsyncProvider |
| | 50 | | { |
| | 51 | |
|
| | 52 | | } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// This class contains common utilities for implementations of <see cref="IAsyncProvider"/>. |
| | 56 | | /// </summary> |
| | 57 | | public static class AsyncProviderUtilities |
| | 58 | | { |
| | 59 | | /// <summary> |
| | 60 | | /// This method creates a new instance of exception with message informing that there are no elements in the seque |
| | 61 | | /// </summary> |
| | 62 | | /// <returns>A new instance of <see cref="InvalidOperationException"/>.</returns> |
| 4 | 63 | | public static InvalidOperationException EmptySequenceException() => new InvalidOperationException( "Empty sequence |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// This method creates a new instance of exception with message informing that <see cref="IAsyncEnumerable.AsyncP |
| | 67 | | /// </summary> |
| | 68 | | /// <returns>A new instance of <see cref="InvalidOperationException"/>.</returns> |
| 0 | 69 | | public static InvalidOperationException NoAsyncProviderException() => new InvalidOperationException( "No async pro |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// This method checks whether type given as second parameter is assignable from type given as first parameter (or |
| | 73 | | /// This check, however, only results to <c>true</c> when both are not structs and not generic parameters. |
| | 74 | | /// </summary> |
| | 75 | | /// <param name="t">The first type.</param> |
| | 76 | | /// <param name="u">The second type.</param> |
| | 77 | | /// <returns><c>true</c> if <paramref name="t"/> is same as <paramref name="u"/>, or if neither are structs and ge |
| | 78 | | /// <exception cref="NullReferenceException">If either of <paramref name="t"/> or <paramref name="u"/> is <c>null< |
| | 79 | | public static Boolean IsOfType( |
| | 80 | | TTypeInfo t, |
| | 81 | | TTypeInfo u |
| | 82 | | ) |
| | 83 | | { |
| | 84 | | // When both types are non-structs and non-generic-parameters, and u is supertype of t, then we don't need new |
| 7 | 85 | | return Equals( t, u ) || ( !t.IsValueType && !u.IsValueType && !t.IsGenericParameter && !u.IsGenericParameter & |
| | 86 | | } |
| | 87 | | } |
| | 88 | |
|
| | 89 | | } |