├── .gitignore ├── Core ├── CLSCompliant.cs ├── Core.csproj ├── GlobalSuppressions.cs ├── OpenSourceKey.snk ├── Properties │ └── AssemblyInfo.cs ├── System │ ├── Action.net30.cs │ ├── Action10.net35.cs │ ├── Action11.net35.cs │ ├── Action12.net35.cs │ ├── Action13.net35.cs │ ├── Action14.net35.cs │ ├── Action15.net35.cs │ ├── Action16.net35.cs │ ├── Action2.net30.cs │ ├── Action3.net30.cs │ ├── Action4.net30.cs │ ├── Action5.net35.cs │ ├── Action6.net35.cs │ ├── Action7.net35.cs │ ├── Action8.net35.cs │ ├── Action9.net35.cs │ ├── AggregateException.net35.cs │ ├── Collections │ │ ├── Concurrent │ │ │ ├── ConcurrentDictionary.net35.cs │ │ │ ├── ConcurrentQueue.net35.cs │ │ │ └── IProducerConsumerCollection.net35.cs │ │ ├── Generic │ │ │ ├── HashSet.net30.cs │ │ │ ├── IReadOnlyCollection.net40.cs │ │ │ ├── IReadOnlyDictionary.net40.cs │ │ │ ├── IReadOnlyList.net40.cs │ │ │ ├── ISet.net35.cs │ │ │ └── SortedSet.net35.cs │ │ ├── IStructuralComparable.net35.cs │ │ ├── IStructuralEquatable.net35.cs │ │ ├── ObjectModel │ │ │ ├── ObservableCollection.net20.cs │ │ │ ├── ReadOnlyDictionary.KeyCollection.net40.cs │ │ │ ├── ReadOnlyDictionary.ValueCollection.net40.cs │ │ │ └── ReadOnlyDictionary.net40.cs │ │ ├── Specialized │ │ │ ├── INotifyCollectionChanged.net30.cs │ │ │ ├── NotifyCollectionChangedAction.net30.cs │ │ │ ├── NotifyCollectionChangedEventArgs.net30.cs │ │ │ └── NotifyCollectionChangedEventHandler.net30.cs │ │ └── StructuralComparisons.net35.cs │ ├── Diagnostics │ │ └── Contracts │ │ │ ├── Contract.bcl.net35 .cs │ │ │ ├── Contract.net35.cs │ │ │ ├── ContractAbbreviatorAttribute.net40.cs │ │ │ ├── ContractArgumentValidatorAttribute.net40.cs │ │ │ ├── ContractClassAttribute.net35.cs │ │ │ ├── ContractClassForAttribute.net35.cs │ │ │ ├── ContractException.net40.cs │ │ │ ├── ContractFailedEventArgs.net35.cs │ │ │ ├── ContractFailureKind.net35.cs │ │ │ ├── ContractInvariantMethodAttribute.net35.cs │ │ │ ├── ContractOptionAttribute.net40.cs │ │ │ ├── ContractPublicPropertyNameAttribute.net35.cs │ │ │ ├── ContractReferenceAssemblyAttribute.net40.cs │ │ │ ├── ContractRuntimeIgnoredAttribute.net35.cs │ │ │ ├── ContractVerificationAttribute.net35.cs │ │ │ ├── Internal │ │ │ └── ContractHelper.net35.cs │ │ │ └── PureAttribute.net35.cs │ ├── Dynamic │ │ └── Utils │ │ │ ├── CacheDict.cs │ │ │ ├── ContractsUtil.cs │ │ │ ├── DelegateHelpers.cs │ │ │ ├── Error.cs │ │ │ ├── ExpressionUtils.cs │ │ │ ├── ExpressionVisitorUtils.cs │ │ │ ├── Helpers.cs │ │ │ ├── ListArgumentProvider.cs │ │ │ ├── RuntimeOps.ExpressionQuoter.cs │ │ │ ├── RuntimeOps.RuntimeVariableList.cs │ │ │ ├── Strings.cs │ │ │ └── TrueReadOnlyCollection.cs │ ├── Func1.net30.cs │ ├── Func10.net35.cs │ ├── Func11.net35.cs │ ├── Func12.net35.cs │ ├── Func13.net35.cs │ ├── Func14.net35.cs │ ├── Func15.net35.cs │ ├── Func16.net35.cs │ ├── Func17.net35.cs │ ├── Func2.net30.cs │ ├── Func3.net30.cs │ ├── Func4.net30.cs │ ├── Func5.net30.cs │ ├── Func6.net35.cs │ ├── Func7.net35.cs │ ├── Func8.net35.cs │ ├── Func9.net35.cs │ ├── IObservable.net35.cs │ ├── IObserver.net35.cs │ ├── IProgress.net40.cs │ ├── Lazy1.net35.cs │ ├── Lazy2.net35.cs │ ├── LazyThreadSafetyMode.net35.cs │ ├── Linq │ │ ├── Enumerable.groupby.net30.cs │ │ ├── Enumerable.groupjoin.net30.cs │ │ ├── Enumerable.join.net30.cs │ │ ├── Enumerable.net30.cs │ │ ├── Enumerable.numeric.net30.cs │ │ ├── EnumerableExecutor.net35.cs │ │ ├── EnumerableExecutor1.net35.cs │ │ ├── EnumerableQuery.cs │ │ ├── EnumerableQuery1.net35.cs │ │ ├── Expressions │ │ │ ├── BinaryExpression.net30.cs │ │ │ ├── BlockExpression.net30.cs │ │ │ ├── CatchBlock.net30.cs │ │ │ ├── Compiler │ │ │ │ ├── AnalyzedTree.net30.cs │ │ │ │ ├── AssemblyGen.cs │ │ │ │ ├── BoundConstants.net30.cs │ │ │ │ ├── CompilerScope.Storage.net30.cs │ │ │ │ ├── CompilerScope.net30.cs │ │ │ │ ├── ConstantCheck.cs │ │ │ │ ├── DelegateHelpers.Generated.cs │ │ │ │ ├── DelegateHelpers.cs │ │ │ │ ├── HoistedLocals.net30.cs │ │ │ │ ├── ILGen.cs │ │ │ │ ├── KeyedQueue.cs │ │ │ │ ├── LabelInfo.cs │ │ │ │ ├── LambdaCompiler.Address.net30.cs │ │ │ │ ├── LambdaCompiler.Binary.net30.cs │ │ │ │ ├── LambdaCompiler.ControlFlow.net30.cs │ │ │ │ ├── LambdaCompiler.Expressions.net30.cs │ │ │ │ ├── LambdaCompiler.Generated.net30.cs │ │ │ │ ├── LambdaCompiler.Lambda.net30.cs │ │ │ │ ├── LambdaCompiler.Logical.net30.cs │ │ │ │ ├── LambdaCompiler.Statements.net30.cs │ │ │ │ ├── LambdaCompiler.Unary.net30.cs │ │ │ │ ├── LambdaCompiler.net30.cs │ │ │ │ ├── StackSpiller.Bindings.net30.cs │ │ │ │ ├── StackSpiller.Generated.net30.cs │ │ │ │ ├── StackSpiller.Temps.net30.cs │ │ │ │ ├── StackSpiller.net30.cs │ │ │ │ └── VariableBinder.net30.cs │ │ │ ├── ConditionalExpression.net30.cs │ │ │ ├── ConstantExpression.net30.cs │ │ │ ├── DebugInfoExpression.net30.cs │ │ │ ├── DebugViewWriter.net30.cs │ │ │ ├── DefaultExpression.net30.cs │ │ │ ├── ElementInit.net30.cs │ │ │ ├── Error.cs │ │ │ ├── Expression.DebuggerProxy.net30.cs │ │ │ ├── Expression.net30.cs │ │ │ ├── ExpressionStringBuilder.net30.cs │ │ │ ├── ExpressionTransformer.cs │ │ │ ├── ExpressionType.net30.cs │ │ │ ├── ExpressionVisitor.net30.cs │ │ │ ├── Extensions.cs │ │ │ ├── GotoExpression.net30.cs │ │ │ ├── IArgumentProvider.net35.cs │ │ │ ├── IDynamicExpression.net35.cs │ │ │ ├── IndexExpression.net30.cs │ │ │ ├── Interpreter │ │ │ │ ├── AddInstruction.net30.cs │ │ │ │ ├── ArrayOperations.net30.cs │ │ │ │ ├── BranchLabel.net30.cs │ │ │ │ ├── CallInstruction.Generated.net30.cs │ │ │ │ ├── CallInstruction.net30.cs │ │ │ │ ├── ConstantCheck.cs │ │ │ │ ├── ControlFlowInstructions.net30.cs │ │ │ │ ├── DivInstruction.net30.cs │ │ │ │ ├── EqualInstruction.net30.cs │ │ │ │ ├── FieldOperations.net30.cs │ │ │ │ ├── GreaterThanInstruction.net30.cs │ │ │ │ ├── ILightCallSiteBinder.cs │ │ │ │ ├── Instruction.net30.cs │ │ │ │ ├── InstructionList.net30.cs │ │ │ │ ├── InterpretedFrame.net30.cs │ │ │ │ ├── Interpreter.net30.cs │ │ │ │ ├── LabelInfo.net30.cs │ │ │ │ ├── LessThanInstruction.net30.cs │ │ │ │ ├── LightCompiler.net30.cs │ │ │ │ ├── LightDelegateCreator.net30.cs │ │ │ │ ├── LightLambda.Generated.net30.cs │ │ │ │ ├── LightLambda.net30.cs │ │ │ │ ├── LocalAccess.net30.cs │ │ │ │ ├── LocalVariables.net30.cs │ │ │ │ ├── MulInstruction.net30.cs │ │ │ │ ├── NotEqualInstruction.net30.cs │ │ │ │ ├── NumericConvertInstruction.net30.cs │ │ │ │ ├── RuntimeVariables.cs │ │ │ │ ├── StackOperations.net30.cs │ │ │ │ ├── SubInstruction.net30.cs │ │ │ │ ├── TypeOperations.net30.cs │ │ │ │ └── Utilities.net30.cs │ │ │ ├── InvocationExpression.net30.cs │ │ │ ├── LabelExpression.net30.cs │ │ │ ├── LabelTarget.net35.cs │ │ │ ├── LambdaExpression.net30.cs │ │ │ ├── ListInitExpression.net30.cs │ │ │ ├── LoopExpression.net30.cs │ │ │ ├── MemberAssignment.net30.cs │ │ │ ├── MemberBinding.net30.cs │ │ │ ├── MemberExpression.net30.cs │ │ │ ├── MemberInitExpression.net30.cs │ │ │ ├── MemberListBinding.net30.cs │ │ │ ├── MemberMemberBinding.net30.cs │ │ │ ├── MethodCallExpression.net30.cs │ │ │ ├── NewArrayExpression.net30.cs │ │ │ ├── NewExpression.net30.cs │ │ │ ├── ParameterExpression.net30.cs │ │ │ ├── RuntimeVariablesExpression.net30.cs │ │ │ ├── Set.net30.cs │ │ │ ├── Strings.cs │ │ │ ├── SwitchCase.net30.cs │ │ │ ├── SwitchExpression.net30.cs │ │ │ ├── SymbolDocumentInfo.net35.cs │ │ │ ├── TryExpression.net30.cs │ │ │ ├── TypeBinaryExpression.net30.cs │ │ │ └── UnaryExpression.net30.cs │ │ ├── IGrouping.net30.cs │ │ ├── ILookup.net30.cs │ │ ├── IOrderedEnumerable.net30.cs │ │ ├── IOrderedQueryable.cs │ │ ├── IOrderedQueryable1.net30.cs │ │ ├── IQueryProvider.net30.cs │ │ ├── IQueryable.net30.cs │ │ ├── IQueryable1.net30.cs │ │ ├── LinqCheck.cs │ │ ├── Lookup.net30.cs │ │ ├── OrderedEnumerable.cs │ │ ├── OrderedSequence.cs │ │ ├── ParallelExecutionMode.net35.cs │ │ ├── ParallelMergeOptions.net35.cs │ │ ├── Queryable.net30.cs │ │ ├── QueryableEnumerable.cs │ │ ├── QueryableTransformer.cs │ │ ├── QuickSort.cs │ │ ├── SortContext.cs │ │ ├── SortDirection.cs │ │ └── SortSequenceContext.cs │ ├── Numerics │ │ ├── BigInteger.net35.cs │ │ ├── BigInteger.string.cs │ │ ├── BigIntegerBuilder.cs │ │ ├── BigNumberBuffer.cs │ │ ├── Complex.net35.cs │ │ ├── NumericsHelpers.cs │ │ └── ReverseStringBuilder.cs │ ├── Progress.net40.cs │ ├── Reflection │ │ ├── IntrospectionExtensions.net40.cs │ │ └── RuntimeReflectionExtensions.net40.cs │ ├── Runtime │ │ ├── CompilerServices │ │ │ ├── AsyncMethodBuilderAttribute.net40.cs │ │ │ ├── AsyncMethodBuilderCore.cs │ │ │ ├── AsyncMethodTaskCache.cs │ │ │ ├── AsyncStateMachineAttribute.net40.cs │ │ │ ├── AsyncTaskMethodBuilder.net40.cs │ │ │ ├── AsyncValueTaskMethodBuilder.net40.cs │ │ │ ├── AsyncVoidMethodBuilder.net40.cs │ │ │ ├── CallerFilePathAttribute.net40.cs │ │ │ ├── CallerLineNumberAttribute.net40.cs │ │ │ ├── CallerMemberNameAttribute.net40.cs │ │ │ ├── Closure.net35.cs │ │ │ ├── ConditionalWeakTable.net35.cs │ │ │ ├── ConfiguredTaskAwaitable.net40.cs │ │ │ ├── ConfiguredValueTaskAwaitable.net40.cs │ │ │ ├── ContractHelper.net40.cs │ │ │ ├── ContractHelperEx.cs │ │ │ ├── DynamicAttribute.net35.cs │ │ │ ├── ExecutionScope.net30.cs │ │ │ ├── ExtensionAttribute.net30.cs │ │ │ ├── IAsyncMethodBuilder.cs │ │ │ ├── IAsyncStateMachine.net40.cs │ │ │ ├── ICriticalNotifyCompletion.net40.cs │ │ │ ├── INotifyCompletion.net40.cs │ │ │ ├── IRuntimeVariables.net35.cs │ │ │ ├── IStrongBox.net30.cs │ │ │ ├── IteratorStateMachineAttribute.net40.cs │ │ │ ├── StateMachineAttribute.net40.cs │ │ │ ├── StrongBox.net30.cs │ │ │ ├── TaskAwaiter.net40.cs │ │ │ ├── TupleElementNamesAttribute.net40.cs │ │ │ ├── ValueTaskAwaiter.net40.cs │ │ │ ├── VoidTaskResult.cs │ │ │ └── YieldAwaitable.net40.cs │ │ ├── ExceptionServices │ │ │ └── ExceptionDispatchInfo.net40.cs │ │ └── TargetedPatchingOptOutAttribute.net35.cs │ ├── SR.cs │ ├── Threading │ │ ├── Barrier.net35.cs │ │ ├── CancellationToken.net35.cs │ │ ├── CancellationTokenRegistration.net35.cs │ │ ├── CancellationTokenSource.net35.cs │ │ ├── CountdownEvent.net35.cs │ │ ├── IThreadPoolWorkItem.cs │ │ ├── LazyInitializer.net35.cs │ │ ├── LockRecursionException.cs │ │ ├── LockRecursionPolicy.net30.cs │ │ ├── ManualResetEventSlim.net35.cs │ │ ├── ReaderWriterLockSlim.helpers.cs │ │ ├── ReaderWriterLockSlim.net35.cs │ │ ├── SemaphoreSlim.net35.cs │ │ ├── SpinLock.net35.cs │ │ ├── SpinWait.net35.cs │ │ ├── Tasks │ │ │ ├── AsyncCompatLibExtensions.net40.asyncbridge.cs │ │ │ ├── AwaitTaskContinuation.cs │ │ │ ├── ContinuationResultTaskFromResultTask.cs │ │ │ ├── ContinuationResultTaskFromTask.cs │ │ │ ├── ContinuationTaskFromResultTask.cs │ │ │ ├── ContinuationTaskFromTask.cs │ │ │ ├── IContinuationTask.cs │ │ │ ├── ITaskCompletionAction.cs │ │ │ ├── InternalSpecialCancelException.cs │ │ │ ├── InternalTaskOptions.cs │ │ │ ├── StandardTaskContinuation.cs │ │ │ ├── SynchronizationContextAwaitTaskContinuation.cs │ │ │ ├── Task.await.net35.cs │ │ │ ├── Task.continuation.net35.cs │ │ │ ├── Task.delay.net35.cs │ │ │ ├── Task.microsoft.net35.cs │ │ │ ├── Task.net35.cs │ │ │ ├── Task.promise.net35.cs │ │ │ ├── Task.run.net35.cs │ │ │ ├── Task.wait.net35.cs │ │ │ ├── Task.when.net35.cs │ │ │ ├── Task.yield.net35.cs │ │ │ ├── Task1.net35.cs │ │ │ ├── TaskCanceledException.net35.cs │ │ │ ├── TaskCompletionSource.net35.cs │ │ │ ├── TaskContinuation.net35.cs │ │ │ ├── TaskContinuationOptions.net35.cs │ │ │ ├── TaskCreationOption.net35.cs │ │ │ ├── TaskEx.asyncbridge.cs │ │ │ ├── TaskEx.net35.asyncbridge.cs │ │ │ ├── TaskExceptionHolder.net35.cs │ │ │ ├── TaskExtensions.net35.cs │ │ │ ├── TaskFactory.net35.cs │ │ │ ├── TaskScheduler.microsoft.net35.cs │ │ │ ├── TaskScheduler.net35.cs │ │ │ ├── TaskSchedulerAwaitTaskContinuation.net35.cs │ │ │ ├── TaskSchedulerException.net35.cs │ │ │ ├── TaskStatus.net35.cs │ │ │ ├── ThreadPoolTaskScheduler.net35.cs │ │ │ ├── UnobservedTaskExceptionEventArgs.net35.cs │ │ │ └── ValueTask.net40.cs │ │ ├── ThreadLocal.net35.cs │ │ └── Volatile.net40.cs │ ├── Tuple.net35.cs │ ├── Tuple1.net35.cs │ ├── Tuple2.net35.cs │ ├── Tuple3.net35.cs │ ├── Tuple4.net35.cs │ ├── Tuple5.net35.cs │ ├── Tuple6.net35.cs │ ├── Tuple7.net35.cs │ ├── Tuple8.net35.cs │ ├── TupleExtensions.net40.cs │ ├── ValueTuple.net40.cs │ └── WeakReference.net40.cs ├── Theraot │ ├── Collections │ │ ├── ConversionSet.cs │ │ ├── ConvertedObserver.cs │ │ ├── CustomObserver.cs │ │ ├── EmptyCollection.cs │ │ ├── EmptyList.cs │ │ ├── EmptySet.cs │ │ ├── ExtendedDictionary.cs │ │ ├── ExtendedList.cs │ │ ├── ExtendedQueue.cs │ │ ├── ExtendedReadOnlyCollection.cs │ │ ├── ExtendedReadOnlyCollection.extended.cs │ │ ├── ExtendedReadOnlyDictionary.cs │ │ ├── ExtendedReadOnlyList.cs │ │ ├── ExtendedReadOnlySet.cs │ │ ├── ExtendedSet.cs │ │ ├── ExtendedStack.cs │ │ ├── Extensions._.cs │ │ ├── Extensions.add.cs │ │ ├── Extensions.beforeafter.cs │ │ ├── Extensions.drop.cs │ │ ├── Extensions.extra.cs │ │ ├── Extensions.groupby.cs │ │ ├── Extensions.insert.cs │ │ ├── Extensions.interleave.cs │ │ ├── Extensions.interleave.tt │ │ ├── Extensions.numeric.cs │ │ ├── Extensions.operations.cs │ │ ├── Extensions.partition.cs │ │ ├── Extensions.zip.cs │ │ ├── Extensions.zip.tt │ │ ├── FilteredConvertedObserver.cs │ │ ├── FilteredObserver.cs │ │ ├── IDropPoint.cs │ │ ├── IExtendedCollection.cs │ │ ├── IExtendedDictionary.cs │ │ ├── IExtendedList.cs │ │ ├── IExtendedReadOnlyCollection.cs │ │ ├── IExtendedReadOnlyDictionary.cs │ │ ├── IExtendedReadOnlyList.cs │ │ ├── IExtendedReadOnlySet.cs │ │ ├── IExtendedSet.cs │ │ ├── IProxyObservable.cs │ │ ├── IReadOnlyDropPoint.cs │ │ ├── IReadOnlySet.cs │ │ ├── KeyValuePairComparer.cs │ │ ├── KeyValuePairEqualityComparer.cs │ │ ├── ObservableExtensions.cs │ │ ├── ProgressiveCollection.cs │ │ ├── ProgressiveCollection.extended.cs │ │ ├── ProgressiveDictionary.cs │ │ ├── ProgressiveList.cs │ │ ├── ProgressiveList.extended.cs │ │ ├── ProgressiveLookup.cs │ │ ├── ProgressiveSet.cs │ │ ├── ProgressiveSet.extended.cs │ │ ├── Progressor.cs │ │ ├── ProxyObservable.cs │ │ ├── Specialized │ │ │ ├── AVLTree.AVLNode.cs │ │ │ ├── AVLTree.cs │ │ │ ├── ConditionalExtendedEnumerable.cs │ │ │ ├── ConversionComparer.cs │ │ │ ├── ConversionEqualityComparer.cs │ │ │ ├── ConvertedValueCollection.cs │ │ │ ├── CustomComparer.cs │ │ │ ├── CustomEqualityComparer.cs │ │ │ ├── DelegatedCollection.cs │ │ │ ├── DelegatedCollection.extended.cs │ │ │ ├── EnumCollection.cs │ │ │ ├── EnumerableFromDelegate.cs │ │ │ ├── EnumerationCollection.cs │ │ │ ├── EnumerationCollection.extended.cs │ │ │ ├── EnumerationSet.cs │ │ │ ├── ExtendedEnumerable.cs │ │ │ ├── ExtendedEnumerableBase.cs │ │ │ ├── FlagArray.cs │ │ │ ├── Grouping.cs │ │ │ ├── KeyCollection.cs │ │ │ ├── NeedleConversionEqualityComparer.cs │ │ │ ├── NullAwareDictionary.cs │ │ │ ├── NullAwareDictionary.extended.cs │ │ │ ├── OrderedCollection.cs │ │ │ └── ValueCollection.cs │ │ ├── ThreadSafe │ │ │ ├── ArrayReservoir.cs │ │ │ ├── Bucket.cs │ │ │ ├── BucketCore.cs │ │ │ ├── BucketHelper.cs │ │ │ ├── CircularBucket.cs │ │ │ ├── DoAction.cs │ │ │ ├── FixedSizeBucket.cs │ │ │ ├── FixedSizeQueue.cs │ │ │ ├── IBucket.cs │ │ │ ├── NeedleBucket.cs │ │ │ ├── NeedleReservoir.cs │ │ │ ├── Pool.cs │ │ │ ├── ReentryGuardHelper.cs │ │ │ ├── SafeDictionary.cs │ │ │ ├── SafeQueue.cs │ │ │ ├── SafeSet.cs │ │ │ ├── WeakCancellableEvent.cs │ │ │ ├── WeakCollection.cs │ │ │ ├── WeakDelegateCollection.cs │ │ │ ├── WeakDictionary.cs │ │ │ └── WeakEvent.cs │ │ └── TryTake.cs │ ├── Core │ │ ├── ActionHelper.cs │ │ ├── ActionHelper.tt │ │ ├── AggregateExceptionHelper.cs │ │ ├── CancellationTokenHelper.cs │ │ ├── CharHelper.cs │ │ ├── Check.cs │ │ ├── CloneHelper.cs │ │ ├── ComparerExtensions.cs │ │ ├── DebugHelper.cs │ │ ├── DelegateDeepEqualityComparer.cs │ │ ├── DelegateEqualityComparer.cs │ │ ├── DelegateExtensions.cs │ │ ├── EnumHelper.cs │ │ ├── EnumerableHelper.cs │ │ ├── EnvironmentHelper.cs │ │ ├── EqualityComparerHelper.cs │ │ ├── FolderEnumeration.cs │ │ ├── FuncHelper._.cs │ │ ├── FuncHelper.cs │ │ ├── FuncHelper.predicate.cs │ │ ├── FuncHelper.tt │ │ ├── GraphHelper.cs │ │ ├── ICloneable.cs │ │ ├── ICloner.cs │ │ ├── IntPtrHelper.cs │ │ ├── MonitorHelper.cs │ │ ├── NewEventHandler.cs │ │ ├── NewOperationCanceledException.cs │ │ ├── NumericHelper.Binary.cs │ │ ├── NumericHelper.build.cs │ │ ├── NumericHelper.checked.cs │ │ ├── NumericHelper.checks.cs │ │ ├── NumericHelper.cs │ │ ├── NumericHelper.unchecked.cs │ │ ├── OrderedEnumerable.cs │ │ ├── PathHelper.cs │ │ ├── PrimeHelper.array.cs │ │ ├── PrimeHelper.cs │ │ ├── RAMStream.cs │ │ ├── Range.cs │ │ ├── RangeExtensions.cs │ │ ├── Reference.cs │ │ ├── ReferenceEqualityComparer.cs │ │ ├── StopwatchExtensions.cs │ │ ├── StreamExtensions.cs │ │ ├── StringBuilderExtensions.cs │ │ ├── StringHelper.cs │ │ ├── StringProcessor.cs │ │ ├── TraceRoute.cs │ │ ├── TracertNode.cs │ │ ├── TupleEqualityComparer.cs │ │ ├── TupleEqualityComparer.tt │ │ ├── TypeHelper.ConstructorHelper.cs │ │ ├── TypeHelper.ConstructorHelper.tt │ │ ├── TypeHelper.cs │ │ ├── TypeHelper.extra.cs │ │ ├── TypeHelper.util.cs │ │ ├── ValueActionClosure.cs │ │ ├── ValueActionClosure.tt │ │ ├── ValueFuncClosure.cs │ │ └── ValueFuncClosure.tt │ ├── Threading │ │ ├── AtomicBoolean.cs │ │ ├── CriticalDisposable.cs │ │ ├── CriticalDisposable.disposable.cs │ │ ├── Disposable.cs │ │ ├── Disposable.disposable.cs │ │ ├── Disposable.extended.cs │ │ ├── DisposableAkin.cs │ │ ├── DisposableExtensions.cs │ │ ├── GCMonitor.cs │ │ ├── GCMonitor.internal.cs │ │ ├── IExtendedDisposable.cs │ │ ├── IReadWriteLock.cs │ │ ├── IThreadLocal.cs │ │ ├── LockContext.cs │ │ ├── LockSlot.cs │ │ ├── NeedleLock.cs │ │ ├── Needles │ │ │ ├── CacheNeedle.cs │ │ │ ├── DefaultNeedle.cs │ │ │ ├── ExceptionStructNeedle.cs │ │ │ ├── FutureAction.cs │ │ │ ├── FutureDisposableNeedle.cs │ │ │ ├── FutureNeedle.cs │ │ │ ├── ICacheNeedle.cs │ │ │ ├── INeedle.cs │ │ │ ├── IPromise.cs │ │ │ ├── IReadOnlyNeedle.cs │ │ │ ├── IRecyclableNeedle.cs │ │ │ ├── LazyAction.cs │ │ │ ├── LazyDisposableNeedle.cs │ │ │ ├── LazyNeedle.cs │ │ │ ├── LockableContext.cs │ │ │ ├── LockableNeedle.cs │ │ │ ├── LockableSlot.cs │ │ │ ├── Needle.cs │ │ │ ├── NeedleHelper.cs │ │ │ ├── NotNull.cs │ │ │ ├── Promise.cs │ │ │ ├── PromiseNeedle1.cs │ │ │ ├── ReadOnlyDisposableNeedle.cs │ │ │ ├── ReadOnlyNeedle.cs │ │ │ ├── ReadOnlyPromise.cs │ │ │ ├── ReadOnlyPromiseNeedle.cs │ │ │ ├── ReadOnlyStructNeedle.cs │ │ │ ├── StructNeedle.cs │ │ │ ├── Transact.IResource.cs │ │ │ ├── Transact.Needle.cs │ │ │ ├── Transact.cs │ │ │ ├── Transact.disposable.cs │ │ │ ├── WeakDelegateNeedle.cs │ │ │ ├── WeakNeedle.cs │ │ │ ├── WeakNeedle.disposable.cs │ │ │ └── WeakNeedle.extended.cs │ │ ├── NoReentrantReadWriteLock.cs │ │ ├── NoReentrantReadWriteLock.disposable.cs │ │ ├── NoTrackingThreadLocal.cs │ │ ├── ReadWriteLock.cs │ │ ├── ReentrantReadWriteLock.cs │ │ ├── ReentrantReadWriteLock.disposable.cs │ │ ├── ReentryGuard.cs │ │ ├── RuntimeUniqueIdProdiver.cs │ │ ├── ThreadLocalHelper.cs │ │ ├── ThreadingHelper.SpinWait.cs │ │ ├── ThreadingHelper.cs │ │ ├── ThreadingHelper.extra.cs │ │ ├── Timeout.cs │ │ ├── TrackingThreadLocal.cs │ │ ├── VersionProvider.Target.cs │ │ ├── VersionProvider.VersionToken.cs │ │ └── VersionProvider.cs │ └── VoidStruct.cs └── packages.config ├── Image └── Img.png ├── README.md └── Unity-Serialize ├── CustomSerializer.cs ├── New ├── Attributes.cs ├── BinaryReader.cs ├── BitStream.cs ├── Interface.cs ├── Serializer.cs └── WriterUtility.cs ├── Properties └── AssemblyInfo.cs ├── UnityResources.cs ├── UnityResources.tt ├── Unity_Serialize.csproj ├── Utility ├── BlockExpression.cs ├── CustomSerializer.cs ├── IType.cs └── TypeUtility.cs └── WriterHelper ├── ArrayWriter.cs ├── BinaryWriter.cs ├── DynamicWriter.cs ├── GenericWriter.cs ├── SpecialWriter.cs └── ValueTypeWriter.cs /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj -------------------------------------------------------------------------------- /Core/CLSCompliant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [assembly: CLSCompliant(true)] -------------------------------------------------------------------------------- /Core/OpenSourceKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Difficulty-in-naming/DreamSerialize/c50f2916149a206eebbbfb3bb32f6fd2cfef3ef0/Core/OpenSourceKey.snk -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | 8 | #if !NETCOREAPP1_1 9 | [assembly: AssemblyCompany("Theraot")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyCopyright("Copyright 2010 - 2017 by Theraot")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | [assembly: AssemblyFileVersion("1.0.3.0")] 16 | [assembly: AssemblyProduct("Theraot.Core")] 17 | [assembly: AssemblyTitle("Theraot.Core")] 18 | [assembly: AssemblyVersion("1.0.3.0")] 19 | #endif 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("c9c38e25-42f4-460a-a956-fd605fba20e5")] -------------------------------------------------------------------------------- /Core/System/Action.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has no parameters and does not return a value. 6 | public delegate void Action(); 7 | } 8 | 9 | #endif -------------------------------------------------------------------------------- /Core/System/Action2.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 2 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The first parameter of the method that this delegate encapsulates. 11 | /// The second parameter of the method that this delegate encapsulates. 12 | #if NETCF 13 | 14 | public delegate void Action(T1 arg1, T2 arg2); 15 | 16 | #else 17 | 18 | public delegate void Action(T1 arg1, T2 arg2); 19 | 20 | #endif 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Action3.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 3 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The type of the third parameter of the method that this delegate encapsulates. 11 | /// The first parameter of the method that this delegate encapsulates. 12 | /// The second parameter of the method that this delegate encapsulates. 13 | /// The third parameter of the method that this delegate encapsulates. 14 | #if NETCF 15 | 16 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3); 17 | 18 | #else 19 | 20 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3); 21 | 22 | #endif 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /Core/System/Action4.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 4 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The type of the third parameter of the method that this delegate encapsulates. 11 | /// The type of the fourth parameter of the method that this delegate encapsulates. 12 | /// The first parameter of the method that this delegate encapsulates. 13 | /// The second parameter of the method that this delegate encapsulates. 14 | /// The third parameter of the method that this delegate encapsulates. 15 | /// The fourth parameter of the method that this delegate encapsulates. 16 | #if NETCF 17 | 18 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); 19 | 20 | #else 21 | 22 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); 23 | 24 | #endif 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/System/Action5.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 5 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The type of the third parameter of the method that this delegate encapsulates. 11 | /// The type of the fourth parameter of the method that this delegate encapsulates. 12 | /// The type of the fifth parameter of the method that this delegate encapsulates. 13 | /// The first parameter of the method that this delegate encapsulates. 14 | /// The second parameter of the method that this delegate encapsulates. 15 | /// The third parameter of the method that this delegate encapsulates. 16 | /// The fourth parameter of the method that this delegate encapsulates. 17 | /// The fifth parameter of the method that this delegate encapsulates. 18 | #if NETCF 19 | 20 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); 21 | 22 | #else 23 | 24 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); 25 | 26 | #endif 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /Core/System/Action6.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 6 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The type of the third parameter of the method that this delegate encapsulates. 11 | /// The type of the fourth parameter of the method that this delegate encapsulates. 12 | /// The type of the fifth parameter of the method that this delegate encapsulates. 13 | /// The type of the sixth parameter of the method that this delegate encapsulates. 14 | /// The first parameter of the method that this delegate encapsulates. 15 | /// The second parameter of the method that this delegate encapsulates. 16 | /// The third parameter of the method that this delegate encapsulates. 17 | /// The fourth parameter of the method that this delegate encapsulates. 18 | /// The fifth parameter of the method that this delegate encapsulates. 19 | /// The sixth parameter of the method that this delegate encapsulates. 20 | #if NETCF 21 | 22 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); 23 | 24 | #else 25 | 26 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); 27 | 28 | #endif 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Core/System/Action7.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// 6 | /// Encapsulates a method that has 7 parameters and does not return a value. 7 | /// 8 | /// The type of the first parameter of the method that this delegate encapsulates. 9 | /// The type of the second parameter of the method that this delegate encapsulates. 10 | /// The type of the third parameter of the method that this delegate encapsulates. 11 | /// The type of the fourth parameter of the method that this delegate encapsulates. 12 | /// The type of the fifth parameter of the method that this delegate encapsulates. 13 | /// The type of the sixth parameter of the method that this delegate encapsulates. 14 | /// The type of the seventh parameter of the method that this delegate encapsulates. 15 | /// The first parameter of the method that this delegate encapsulates. 16 | /// The second parameter of the method that this delegate encapsulates. 17 | /// The third parameter of the method that this delegate encapsulates. 18 | /// The fourth parameter of the method that this delegate encapsulates. 19 | /// The fifth parameter of the method that this delegate encapsulates. 20 | /// The sixth parameter of the method that this delegate encapsulates. 21 | /// The seventh parameter of the method that this delegate encapsulates. 22 | #if NETCF 23 | 24 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); 25 | 26 | #else 27 | 28 | public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); 29 | 30 | #endif 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Concurrent/IProducerConsumerCollection.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Core.System.Collections.Concurrent 7 | { 8 | public interface IProducerConsumerCollection : IEnumerable, ICollection 9 | { 10 | void CopyTo(T[] array, int index); 11 | 12 | T[] ToArray(); 13 | 14 | bool TryAdd(T item); 15 | 16 | bool TryTake(out T item); 17 | } 18 | } 19 | 20 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Generic/IReadOnlyCollection.net40.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Theraot.Core.System.Collections.Generic 4 | { 5 | #if NET40 6 | 7 | public interface IReadOnlyCollection : IEnumerable 8 | { 9 | int Count 10 | { 11 | get; 12 | } 13 | } 14 | 15 | #endif 16 | #if NET20 || NET30 || NET35 17 | 18 | public interface IReadOnlyCollection : IEnumerable 19 | { 20 | int Count { get; } 21 | } 22 | 23 | #endif 24 | } -------------------------------------------------------------------------------- /Core/System/Collections/Generic/IReadOnlyDictionary.net40.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Collections.Generic 6 | { 7 | public partial interface IReadOnlyDictionary : IReadOnlyCollection> 8 | { 9 | IEnumerable Keys { get; } 10 | 11 | IEnumerable Values { get; } 12 | } 13 | 14 | public partial interface IReadOnlyDictionary 15 | { 16 | TValue this[TKey key] { get; } 17 | } 18 | 19 | public partial interface IReadOnlyDictionary 20 | { 21 | bool ContainsKey(TKey key); 22 | 23 | bool TryGetValue(TKey key, out TValue value); 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Generic/IReadOnlyList.net40.cs: -------------------------------------------------------------------------------- 1 | namespace Theraot.Core.System.Collections.Generic 2 | { 3 | #if NET40 4 | 5 | public interface IReadOnlyList : IReadOnlyCollection 6 | { 7 | T this[int index] 8 | { 9 | get; 10 | } 11 | } 12 | #endif 13 | #if NET20 || NET30 || NET35 14 | 15 | public interface IReadOnlyList : IReadOnlyCollection 16 | { 17 | T this[int index] { get; } 18 | } 19 | 20 | #endif 21 | } -------------------------------------------------------------------------------- /Core/System/Collections/Generic/ISet.net35.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System.Collections.Generic 6 | { 7 | public interface ISet : ICollection 8 | { 9 | new bool Add(T item); 10 | 11 | void ExceptWith(IEnumerable other); 12 | 13 | void IntersectWith(IEnumerable other); 14 | 15 | bool IsProperSubsetOf(IEnumerable other); 16 | 17 | bool IsProperSupersetOf(IEnumerable other); 18 | 19 | bool IsSubsetOf(IEnumerable other); 20 | 21 | bool IsSupersetOf(IEnumerable other); 22 | 23 | bool Overlaps(IEnumerable other); 24 | 25 | bool SetEquals(IEnumerable other); 26 | 27 | void SymmetricExceptWith(IEnumerable other); 28 | 29 | void UnionWith(IEnumerable other); 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/IStructuralComparable.net35.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System.Collections 6 | { 7 | public interface IStructuralComparable 8 | { 9 | int CompareTo(object other, IComparer comparer); 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/IStructuralEquatable.net35.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System.Collections 6 | { 7 | public interface IStructuralEquatable 8 | { 9 | bool Equals(object other, IEqualityComparer comparer); 10 | 11 | int GetHashCode(IEqualityComparer comparer); 12 | } 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Specialized/INotifyCollectionChanged.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 2 | 3 | namespace Theraot.Core.System.Collections.Specialized 4 | { 5 | public interface INotifyCollectionChanged 6 | { 7 | event NotifyCollectionChangedEventHandler CollectionChanged; 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Specialized/NotifyCollectionChangedAction.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 2 | 3 | namespace Theraot.Core.System.Collections.Specialized 4 | { 5 | public enum NotifyCollectionChangedAction 6 | { 7 | Add, 8 | Remove, 9 | Replace, 10 | Move, 11 | Reset 12 | } 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /Core/System/Collections/Specialized/NotifyCollectionChangedEventHandler.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 2 | 3 | namespace Theraot.Core.System.Collections.Specialized 4 | { 5 | public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangedEventArgs e); 6 | } 7 | 8 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractAbbreviatorAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 || NET40 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Enables writing abbreviations for contracts that get copied to other methods 14 | /// 15 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 16 | [Conditional("CONTRACTS_FULL")] 17 | public sealed class ContractAbbreviatorAttribute : Attribute 18 | { 19 | // Empty 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractArgumentValidatorAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 || NET40 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Enables factoring legacy if-then-throw into separate methods for reuse and full control over 14 | /// thrown exception and arguments 15 | /// 16 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 17 | [Conditional("CONTRACTS_FULL")] 18 | public sealed class ContractArgumentValidatorAttribute : Attribute 19 | { 20 | // Empty 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractClassAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Types marked with this attribute specify that a separate type contains the contracts for this type. 14 | /// 15 | [Conditional("CONTRACTS_FULL")] 16 | [Conditional("DEBUG")] 17 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] 18 | public sealed class ContractClassAttribute : Attribute 19 | { 20 | private readonly Type _typeWithContracts; 21 | 22 | public ContractClassAttribute(Type typeContainingContracts) 23 | { 24 | _typeWithContracts = typeContainingContracts; 25 | } 26 | 27 | public Type TypeContainingContracts 28 | { 29 | get { return _typeWithContracts; } 30 | } 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractClassForAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Types marked with this attribute specify that they are a contract for the type that is the argument of the constructor. 14 | /// 15 | [Conditional("CONTRACTS_FULL")] 16 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 17 | public sealed class ContractClassForAttribute : Attribute 18 | { 19 | private readonly Type _typeIamAContractFor; 20 | 21 | public ContractClassForAttribute(Type typeContractsAreFor) 22 | { 23 | _typeIamAContractFor = typeContractsAreFor; 24 | } 25 | 26 | public Type TypeContractsAreFor 27 | { 28 | get { return _typeIamAContractFor; } 29 | } 30 | } 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractFailureKind.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. 6 | 7 | namespace Theraot.Core.System.Diagnostics.Contracts 8 | { 9 | public enum ContractFailureKind 10 | { 11 | Precondition, 12 | Postcondition, 13 | PostconditionOnException, 14 | Invariant, 15 | Assert, 16 | Assume, 17 | } 18 | } 19 | 20 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractInvariantMethodAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// This attribute is used to mark a method as being the invariant 14 | /// method for a class. The method can have any name, but it must 15 | /// return "void" and take no parameters. The body of the method 16 | /// must consist solely of one or more calls to the method 17 | /// Contract.Invariant. A suggested name for the method is 18 | /// "ObjectInvariant". 19 | /// 20 | [Conditional("CONTRACTS_FULL")] 21 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] 22 | public sealed class ContractInvariantMethodAttribute : Attribute 23 | { 24 | // Empty 25 | } 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractOptionAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 || NET40 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Allows setting contract and tool options at assembly, type, or method granularity. 14 | /// 15 | [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] 16 | [Conditional("CONTRACTS_FULL")] 17 | public sealed class ContractOptionAttribute : Attribute 18 | { 19 | private readonly string _category; 20 | private readonly string _setting; 21 | private readonly bool _enabled; 22 | private readonly string _value; 23 | 24 | public ContractOptionAttribute(string category, string setting, bool enabled) 25 | { 26 | _category = category; 27 | _setting = setting; 28 | _enabled = enabled; 29 | } 30 | 31 | public ContractOptionAttribute(string category, string setting, string value) 32 | { 33 | _category = category; 34 | _setting = setting; 35 | _value = value; 36 | } 37 | 38 | public string Category 39 | { 40 | get { return _category; } 41 | } 42 | 43 | public string Setting 44 | { 45 | get { return _setting; } 46 | } 47 | 48 | public bool Enabled 49 | { 50 | get { return _enabled; } 51 | } 52 | 53 | public string Value 54 | { 55 | get { return _value; } 56 | } 57 | } 58 | } 59 | 60 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractPublicPropertyNameAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Allows a field f to be used in the method contracts for a method m when f has less visibility than m. 14 | /// For instance, if the method is public, but the field is private. 15 | /// 16 | [Conditional("CONTRACTS_FULL")] 17 | [AttributeUsage(AttributeTargets.Field)] 18 | public sealed class ContractPublicPropertyNameAttribute : Attribute 19 | { 20 | private readonly string _publicName; 21 | 22 | public ContractPublicPropertyNameAttribute(string name) 23 | { 24 | _publicName = name; 25 | } 26 | 27 | public string Name 28 | { 29 | get { return _publicName; } 30 | } 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractReferenceAssemblyAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | // Licensed to the .NET Foundation under one or more agreements. 6 | // The .NET Foundation licenses this file to you under the MIT license. 7 | // See the LICENSE file in the project root for more information. 8 | 9 | namespace Theraot.Core.System.Diagnostics.Contracts 10 | { 11 | /// 12 | /// Attribute that specifies that an assembly is a reference assembly with contracts. 13 | /// 14 | [AttributeUsage(AttributeTargets.Assembly)] 15 | public sealed class ContractReferenceAssemblyAttribute : Attribute 16 | { 17 | // Empty 18 | } 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractRuntimeIgnoredAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Methods (and properties) marked with this attribute can be used within calls to Contract methods, but have no runtime behavior associated with them. 14 | /// 15 | [Conditional("CONTRACTS_FULL")] 16 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 17 | public sealed class ContractRuntimeIgnoredAttribute : Attribute 18 | { 19 | // Empty 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/ContractVerificationAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Instructs downstream tools whether to assume the correctness of this assembly, type or member without performing any verification or not. 14 | /// Can use [ContractVerification(false)] to explicitly mark assembly, type or member as one to *not* have verification performed on it. 15 | /// Most specific element found (member, type, then assembly) takes precedence. 16 | /// (That is useful if downstream tools allow a user to decide which polarity is the default, unmarked case.) 17 | /// 18 | /// 19 | /// Apply this attribute to a type to apply to all members of the type, including nested types. 20 | /// Apply this attribute to an assembly to apply to all types and members of the assembly. 21 | /// Apply this attribute to a property to apply to both the getter and setter. 22 | /// 23 | [Conditional("CONTRACTS_FULL")] 24 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] 25 | public sealed class ContractVerificationAttribute : Attribute 26 | { 27 | private readonly bool _value; 28 | 29 | public ContractVerificationAttribute(bool value) 30 | { 31 | _value = value; 32 | } 33 | 34 | public bool Value 35 | { 36 | get { return _value; } 37 | } 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/Internal/ContractHelper.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.Runtime.ConstrainedExecution; 10 | 11 | // Note: In .NET FX 4.5, we duplicated the ContractHelper class in the System.Runtime.CompilerServices 12 | // namespace to remove an ugly wart of a namespace from the Windows 8 profile. But we still need the 13 | // old locations left around, so we can support rewritten .NET FX 4.0 libraries. Consider removing 14 | // these from our reference assembly in a future version. 15 | namespace Theraot.Core.System.Diagnostics.Contracts.Internal 16 | { 17 | [Obsolete("Use the ContractHelper class in the System.Runtime.CompilerServices namespace instead.")] 18 | public static class ContractHelper 19 | { 20 | [DebuggerNonUserCode] 21 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] 22 | public static string RaiseContractFailedEvent(ContractFailureKind failureKind, string userMessage, string conditionText, Exception innerException) 23 | { 24 | return global::Theraot.Core.System.Runtime.CompilerServices.ContractHelper.RaiseContractFailedEvent(failureKind, userMessage, conditionText, innerException); 25 | } 26 | 27 | [DebuggerNonUserCode] 28 | [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] 29 | public static void TriggerFailure(ContractFailureKind kind, string displayMessage, string userMessage, string conditionText, Exception innerException) 30 | { 31 | global::Theraot.Core.System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, displayMessage, userMessage, conditionText, innerException); 32 | } 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Core/System/Diagnostics/Contracts/PureAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #if NET20 || NET30 || NET35 5 | 6 | // Licensed to the .NET Foundation under one or more agreements. 7 | // The .NET Foundation licenses this file to you under the MIT license. 8 | // See the LICENSE file in the project root for more information. 9 | 10 | namespace Theraot.Core.System.Diagnostics.Contracts 11 | { 12 | /// 13 | /// Methods and classes marked with this attribute can be used within calls to Contract methods. Such methods not make any visible state changes. 14 | /// 15 | [Conditional("CONTRACTS_FULL")] 16 | [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Delegate | AttributeTargets.Class | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] 17 | public sealed class PureAttribute : Attribute 18 | { 19 | // Empty 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Dynamic/Utils/ExpressionVisitorUtils.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | 6 | using Theraot.Core.System.Linq.Expressions; 7 | 8 | namespace Theraot.Core.System.Dynamic.Utils 9 | { 10 | internal static class ExpressionVisitorUtils 11 | { 12 | public static Expression[] VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) 13 | { 14 | Expression[] newNodes = null; 15 | var n = nodes.ArgumentCount; 16 | for (var i = 0; i < n; i++) 17 | { 18 | var curNode = nodes.GetArgument(i); 19 | var node = visitor.Visit(curNode); 20 | 21 | if (newNodes != null) 22 | { 23 | newNodes[i] = node; 24 | } 25 | else if (!ReferenceEquals(node, curNode)) 26 | { 27 | newNodes = new Expression[n]; 28 | for (var j = 0; j < i; j++) 29 | { 30 | newNodes[j] = nodes.GetArgument(j); 31 | } 32 | newNodes[i] = node; 33 | } 34 | } 35 | return newNodes; 36 | } 37 | } 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /Core/System/Dynamic/Utils/Helpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.Generic; 5 | using Theraot.Core.System.Collections.Generic; 6 | 7 | namespace Theraot.Core.System.Dynamic.Utils 8 | { 9 | // Miscellaneous helpers that don't belong anywhere else 10 | internal static class Helpers 11 | { 12 | internal static T CommonNode(T first, T second, Func parent) where T : class 13 | { 14 | // NOTICE this method has no null check 15 | var cmp = EqualityComparer.Default; 16 | if (cmp.Equals(first, second)) 17 | { 18 | return first; 19 | } 20 | var set = new HashSet(cmp); 21 | for (var t = first; t != null; t = parent(t)) 22 | { 23 | set.Add(t); 24 | } 25 | for (var t = second; t != null; t = parent(t)) 26 | { 27 | if (set.Contains(t)) 28 | { 29 | return t; 30 | } 31 | } 32 | return null; 33 | } 34 | 35 | internal static void IncrementCount(T key, Dictionary dict) 36 | { 37 | int count; 38 | dict.TryGetValue(key, out count); 39 | dict[key] = count + 1; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Core/System/Dynamic/Utils/TrueReadOnlyCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System.Collections.ObjectModel; 5 | 6 | namespace Theraot.Core.System.Dynamic.Utils 7 | { 8 | internal sealed class TrueReadOnlyCollection : ReadOnlyCollection 9 | { 10 | /// 11 | /// Creates instance of TrueReadOnlyCollection, wrapping passed in array. 12 | /// !!! DOES NOT COPY THE ARRAY !!! 13 | /// 14 | public TrueReadOnlyCollection(T[] list) 15 | : base(list) 16 | { 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Core/System/Func1.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has no parameters and returns a value of the type specified by the parameter. 6 | /// The return value of the method that this delegate encapsulates. 7 | /// The type of the return value of the method that this delegate encapsulates. 8 | #if NETCF 9 | 10 | public delegate TResult Func(); 11 | 12 | #else 13 | 14 | public delegate TResult Func(); 15 | 16 | #endif 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /Core/System/Func2.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has one parameter and returns a value of the type specified by the parameter. 6 | /// The type of the parameter of the method that this delegate encapsulates. 7 | /// The type of the return value of the method that this delegate encapsulates. 8 | /// The parameter of the method that this delegate encapsulates. 9 | /// The return value of the method that this delegate encapsulates. 10 | #if NETCF 11 | 12 | public delegate TResult Func(T arg); 13 | 14 | #else 15 | 16 | public delegate TResult Func(T arg); 17 | 18 | #endif 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /Core/System/Func3.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has two parameters and returns a value of the type specified by the parameter. 6 | /// The type of the first parameter of the method that this delegate encapsulates. 7 | /// The type of the second parameter of the method that this delegate encapsulates. 8 | /// The type of the return value of the method that this delegate encapsulates. 9 | /// The first parameter of the method that this delegate encapsulates. 10 | /// The second parameter of the method that this delegate encapsulates. 11 | /// The return value of the method that this delegate encapsulates. 12 | #if NETCF 13 | 14 | public delegate TResult Func(T1 arg1, T2 arg2); 15 | 16 | #else 17 | 18 | public delegate TResult Func(T1 arg1, T2 arg2); 19 | 20 | #endif 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Func4.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has three parameters and returns a value of the type specified by the parameter. 6 | /// The type of the first parameter of the method that this delegate encapsulates. 7 | /// The type of the second parameter of the method that this delegate encapsulates. 8 | /// The type of the third parameter of the method that this delegate encapsulates. 9 | /// The type of the return value of the method that this delegate encapsulates. 10 | /// The first parameter of the method that this delegate encapsulates. 11 | /// The second parameter of the method that this delegate encapsulates. 12 | /// The third parameter of the method that this delegate encapsulates. 13 | /// The return value of the method that this delegate encapsulates. 14 | #if NETCF 15 | 16 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); 17 | 18 | #else 19 | 20 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); 21 | 22 | #endif 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /Core/System/Func5.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has four parameters and returns a value of the type specified by the parameter. 6 | /// The type of the first parameter of the method that this delegate encapsulates. 7 | /// The type of the second parameter of the method that this delegate encapsulates. 8 | /// The type of the third parameter of the method that this delegate encapsulates. 9 | /// The type of the fourth parameter of the method that this delegate encapsulates. 10 | /// The type of the return value of the method that this delegate encapsulates. 11 | /// The first parameter of the method that this delegate encapsulates. 12 | /// The second parameter of the method that this delegate encapsulates. 13 | /// The third parameter of the method that this delegate encapsulates. 14 | /// The fourth parameter of the method that this delegate encapsulates. 15 | /// The return value of the method that this delegate encapsulates. 16 | #if NETCF 17 | 18 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); 19 | 20 | #else 21 | 22 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); 23 | 24 | #endif 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/System/Func6.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has five parameters and returns a value of the type specified by the parameter. 6 | /// The type of the first parameter of the method that this delegate encapsulates. 7 | /// The type of the second parameter of the method that this delegate encapsulates. 8 | /// The type of the third parameter of the method that this delegate encapsulates. 9 | /// The type of the fourth parameter of the method that this delegate encapsulates. 10 | /// The type of the fifth parameter of the method that this delegate encapsulates. 11 | /// The type of the return value of the method that this delegate encapsulates. 12 | /// The first parameter of the method that this delegate encapsulates. 13 | /// The second parameter of the method that this delegate encapsulates. 14 | /// The third parameter of the method that this delegate encapsulates. 15 | /// The fourth parameter of the method that this delegate encapsulates. 16 | /// The fifth parameter of the method that this delegate encapsulates. 17 | /// The return value of the method that this delegate encapsulates. 18 | #if NETCF 19 | 20 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); 21 | 22 | #else 23 | 24 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); 25 | 26 | #endif 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /Core/System/Func7.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | /// Encapsulates a method that has six parameters and returns a value of the type specified by the parameter. 6 | /// The type of the first parameter of the method that this delegate encapsulates. 7 | /// The type of the second parameter of the method that this delegate encapsulates. 8 | /// The type of the third parameter of the method that this delegate encapsulates. 9 | /// The type of the fourth parameter of the method that this delegate encapsulates. 10 | /// The type of the fifth parameter of the method that this delegate encapsulates. 11 | /// The type of the sixth parameter of the method that this delegate encapsulates. 12 | /// The type of the return value of the method that this delegate encapsulates. 13 | /// The first parameter of the method that this delegate encapsulates. 14 | /// The second parameter of the method that this delegate encapsulates. 15 | /// The third parameter of the method that this delegate encapsulates. 16 | /// The fourth parameter of the method that this delegate encapsulates. 17 | /// The fifth parameter of the method that this delegate encapsulates. 18 | /// The sixth parameter of the method that this delegate encapsulates. 19 | /// The return value of the method that this delegate encapsulates. 20 | #if NETCF 21 | 22 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); 23 | 24 | #else 25 | 26 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); 27 | 28 | #endif 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Core/System/IObservable.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System 6 | { 7 | /// Defines a provider for push-based notification. 8 | /// The object that provides notification information. 9 | #if NETCF 10 | 11 | public interface IObservable 12 | #else 13 | 14 | public interface IObservable 15 | #endif 16 | { 17 | /// Notifies the provider that an observer is to receive notifications. 18 | /// A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them. 19 | /// The object that is to receive notifications. 20 | IDisposable Subscribe(IObserver observer); 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /Core/System/IObserver.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System 6 | { 7 | /// Provides a mechanism for receiving push-based notifications. 8 | /// The object that provides notification information. 9 | #if NETCF 10 | 11 | public interface IObserver 12 | #else 13 | 14 | public interface IObserver 15 | #endif 16 | { 17 | /// Notifies the observer that the provider has finished sending push-based notifications. 18 | void OnCompleted(); 19 | 20 | /// Notifies the observer that the provider has experienced an error condition. 21 | /// An object that provides additional information about the error. 22 | void OnError(Exception error); 23 | 24 | /// Provides the observer with new data. 25 | /// The current notification information. 26 | void OnNext(T value); 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /Core/System/IProgress.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 ||NET40 2 | 3 | namespace Theraot.Core.System 4 | { 5 | #if NETCF 6 | 7 | public interface IProgress 8 | #else 9 | 10 | public interface IProgress 11 | #endif 12 | { 13 | void Report(T value); 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/System/Lazy2.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | public class Lazy : Lazy 6 | { 7 | private readonly TMetadata _metadata; 8 | 9 | public Lazy(TMetadata metadata) 10 | { 11 | _metadata = metadata; 12 | } 13 | 14 | public Lazy(Func valueFactory, TMetadata metadata) 15 | : base(valueFactory) 16 | { 17 | _metadata = metadata; 18 | } 19 | 20 | public Lazy(TMetadata metadata, bool isThreadSafe) 21 | : base(isThreadSafe) 22 | { 23 | _metadata = metadata; 24 | } 25 | 26 | public Lazy(TMetadata metadata, LazyThreadSafetyMode mode) 27 | : base(mode) 28 | { 29 | _metadata = metadata; 30 | } 31 | 32 | public Lazy(Func valueFactory, TMetadata metadata, bool isThreadSafe) 33 | : base(valueFactory, isThreadSafe) 34 | { 35 | _metadata = metadata; 36 | } 37 | 38 | public Lazy(Func valueFactory, TMetadata metadata, LazyThreadSafetyMode mode) 39 | : base(valueFactory, mode) 40 | { 41 | _metadata = metadata; 42 | } 43 | 44 | public TMetadata Metadata 45 | { 46 | get { return _metadata; } 47 | } 48 | } 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /Core/System/LazyThreadSafetyMode.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | public enum LazyThreadSafetyMode 6 | { 7 | None, 8 | PublicationOnly, 9 | ExecutionAndPublication 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/EnumerableExecutor.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Linq 4 | { 5 | public abstract class EnumerableExecutor 6 | { 7 | //Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/EnumerableExecutor1.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Linq 4 | { 5 | public abstract class EnumerableExecutor : EnumerableExecutor 6 | { 7 | //Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/EnumerableQuery.cs: -------------------------------------------------------------------------------- 1 | namespace Theraot.Core.System.Linq 2 | { 3 | public abstract class EnumerableQuery 4 | { 5 | // Empty 6 | } 7 | } -------------------------------------------------------------------------------- /Core/System/Linq/EnumerableQuery1.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using Theraot.Core.System.Linq.Expressions; 7 | 8 | namespace Theraot.Core.System.Linq 9 | { 10 | public class EnumerableQuery : EnumerableQuery, IOrderedQueryable, IQueryProvider 11 | { 12 | private readonly QueryableEnumerable _queryable; 13 | 14 | public EnumerableQuery(Expression expression) 15 | { 16 | _queryable = new QueryableEnumerable(expression); 17 | } 18 | 19 | public EnumerableQuery(IEnumerable enumerable) 20 | { 21 | _queryable = new QueryableEnumerable(enumerable); 22 | } 23 | 24 | Type IQueryable.ElementType 25 | { 26 | get { return _queryable.ElementType; } 27 | } 28 | 29 | Expression IQueryable.Expression 30 | { 31 | get { return _queryable.Expression; } 32 | } 33 | 34 | IQueryProvider IQueryable.Provider 35 | { 36 | get { return _queryable; } 37 | } 38 | 39 | IEnumerator IEnumerable.GetEnumerator() 40 | { 41 | return _queryable.GetEnumerator(); 42 | } 43 | 44 | IEnumerator IEnumerable.GetEnumerator() 45 | { 46 | return _queryable.GetEnumerator(); 47 | } 48 | 49 | IQueryable IQueryProvider.CreateQuery(Expression expression) 50 | { 51 | return _queryable.CreateQuery(expression); 52 | } 53 | 54 | IQueryable IQueryProvider.CreateQuery(Expression expression) 55 | { 56 | return new EnumerableQuery(expression); 57 | } 58 | 59 | object IQueryProvider.Execute(Expression expression) 60 | { 61 | return _queryable.Execute(expression); 62 | } 63 | 64 | TResult IQueryProvider.Execute(Expression expression) 65 | { 66 | return _queryable.Execute(expression); 67 | } 68 | 69 | public override string ToString() 70 | { 71 | return _queryable.ToString(); 72 | } 73 | } 74 | } 75 | 76 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/Compiler/AnalyzedTree.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | 6 | using System.Collections.Generic; 7 | 8 | namespace Theraot.Core.System.Linq.Expressions.Compiler 9 | { 10 | internal sealed class AnalyzedTree 11 | { 12 | internal readonly Dictionary Scopes = new Dictionary(); 13 | internal readonly Dictionary Constants = new Dictionary(); 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/IDynamicExpression.net35.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using System; 5 | 6 | namespace Theraot.Core.System.Linq.Expressions 7 | { 8 | public interface IDynamicExpression : IArgumentProvider 9 | { 10 | /// 11 | /// Gets the type of the delegate used by the CallSite />. 12 | /// 13 | Type DelegateType { get; } 14 | 15 | /// 16 | /// Rewrite this node replacing the args with the provided values. The 17 | /// number of the args needs to match the number of the current block. 18 | /// 19 | /// This helper is provided to allow re-writing of nodes to not depend on the specific 20 | /// class of DynamicExpression which is being used. 21 | /// 22 | Expression Rewrite(Expression[] args); 23 | 24 | /// 25 | /// Creates a CallSite for the node. 26 | /// 27 | object CreateCallSite(); 28 | } 29 | } -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/Interpreter/ILightCallSiteBinder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | namespace Theraot.Core.System.Linq.Expressions.Interpreter 5 | { 6 | internal interface ILightCallSiteBinder 7 | { 8 | bool AcceptsArgumentArray { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/Interpreter/LightDelegateCreator.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | 6 | using System; 7 | using Theraot.Core.System.Runtime.CompilerServices; 8 | 9 | namespace Theraot.Core.System.Linq.Expressions.Interpreter 10 | { 11 | /// 12 | /// Manages creation of interpreted delegates. These delegates will get 13 | /// compiled if they are executed often enough. 14 | /// 15 | internal sealed class LightDelegateCreator 16 | { 17 | // null if we are forced to compile 18 | private readonly Interpreter _interpreter; 19 | 20 | private readonly Expression _lambda; 21 | 22 | internal LightDelegateCreator(Interpreter interpreter, LambdaExpression lambda) 23 | { 24 | Assert.NotNull(lambda); 25 | _interpreter = interpreter; 26 | _lambda = lambda; 27 | } 28 | 29 | internal Interpreter Interpreter 30 | { 31 | get { return _interpreter; } 32 | } 33 | 34 | public Delegate CreateDelegate() 35 | { 36 | return CreateDelegate(null); 37 | } 38 | 39 | internal Delegate CreateDelegate(IStrongBox[] closure) 40 | { 41 | // we'll create an interpreted LightLambda 42 | return new LightLambda(this, closure).MakeDelegate(DelegateType); 43 | } 44 | 45 | private Type DelegateType 46 | { 47 | get 48 | { 49 | var le = _lambda as LambdaExpression; 50 | if (le != null) 51 | { 52 | return le.Type; 53 | } 54 | 55 | return null; 56 | } 57 | } 58 | } 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/Interpreter/RuntimeVariables.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | using Theraot.Core.System.Runtime.CompilerServices; 5 | 6 | namespace Theraot.Core.System.Linq.Expressions.Interpreter 7 | { 8 | internal sealed class RuntimeVariables : IRuntimeVariables 9 | { 10 | private readonly IStrongBox[] _boxes; 11 | 12 | private RuntimeVariables(IStrongBox[] boxes) 13 | { 14 | _boxes = boxes; 15 | } 16 | 17 | int IRuntimeVariables.Count 18 | { 19 | get { return _boxes.Length; } 20 | } 21 | 22 | object IRuntimeVariables.this[int index] 23 | { 24 | get { return _boxes[index].Value; } 25 | 26 | set { _boxes[index].Value = value; } 27 | } 28 | 29 | internal static IRuntimeVariables Create(IStrongBox[] boxes) 30 | { 31 | return new RuntimeVariables(boxes); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/MemberAssignment.net30.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Difficulty-in-naming/DreamSerialize/c50f2916149a206eebbbfb3bb32f6fd2cfef3ef0/Core/System/Linq/Expressions/MemberAssignment.net30.cs -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/MemberListBinding.net30.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Difficulty-in-naming/DreamSerialize/c50f2916149a206eebbbfb3bb32f6fd2cfef3ef0/Core/System/Linq/Expressions/MemberListBinding.net30.cs -------------------------------------------------------------------------------- /Core/System/Linq/Expressions/MemberMemberBinding.net30.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Difficulty-in-naming/DreamSerialize/c50f2916149a206eebbbfb3bb32f6fd2cfef3ef0/Core/System/Linq/Expressions/MemberMemberBinding.net30.cs -------------------------------------------------------------------------------- /Core/System/Linq/IGrouping.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.System.Linq 6 | { 7 | #if NETCF 8 | 9 | public interface IGrouping : IEnumerable 10 | #else 11 | 12 | public interface IGrouping : IEnumerable 13 | #endif 14 | { 15 | TKey Key { get; } 16 | } 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/ILookup.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.System.Linq 6 | { 7 | public interface ILookup : IEnumerable> 8 | { 9 | int Count { get; } 10 | 11 | IEnumerable this[TKey key] { get; } 12 | 13 | bool Contains(TKey key); 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/IOrderedEnumerable.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.System.Linq 6 | { 7 | public interface IOrderedEnumerable : IEnumerable 8 | { 9 | IOrderedEnumerable CreateOrderedEnumerable(Func keySelector, IComparer comparer, bool descending); 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/IOrderedQueryable.cs: -------------------------------------------------------------------------------- 1 | // Permission is hereby granted, free of charge, to any person obtaining 2 | // a copy of this software and associated documentation files (the 3 | // "Software"), to deal in the Software without restriction, including 4 | // without limitation the rights to use, copy, modify, merge, publish, 5 | // distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to 7 | // the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be 10 | // included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 13 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 14 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 16 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 18 | // 19 | // Authors: 20 | // Alejandro Serrano "Serras" (trupill@yahoo.es) 21 | namespace Theraot.Core.System.Linq 22 | { 23 | public interface IOrderedQueryable : IQueryable 24 | { 25 | // Empty 26 | } 27 | } -------------------------------------------------------------------------------- /Core/System/Linq/IOrderedQueryable1.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System.Linq 4 | { 5 | public interface IOrderedQueryable : IOrderedQueryable, IQueryable 6 | { 7 | //Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/IQueryProvider.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using Theraot.Core.System.Linq.Expressions; 4 | 5 | namespace Theraot.Core.System.Linq 6 | { 7 | public interface IQueryProvider 8 | { 9 | IQueryable CreateQuery(Expression expression); 10 | 11 | IQueryable CreateQuery(Expression expression); 12 | 13 | object Execute(Expression expression); 14 | 15 | TResult Execute(Expression expression); 16 | } 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/IQueryable.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System; 4 | using System.Collections; 5 | using Theraot.Core.System.Linq.Expressions; 6 | 7 | namespace Theraot.Core.System.Linq 8 | { 9 | public interface IQueryable : IEnumerable 10 | { 11 | Type ElementType { get; } 12 | 13 | Expression Expression { get; } 14 | 15 | IQueryProvider Provider { get; } 16 | } 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/IQueryable1.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.System.Linq 6 | { 7 | public interface IQueryable : IQueryable, IEnumerable 8 | { 9 | //Empty 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/ParallelExecutionMode.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Linq 4 | { 5 | public enum ParallelExecutionMode 6 | { 7 | Default = 0, 8 | ForceParallelism = 1 9 | } 10 | } 11 | 12 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/ParallelMergeOptions.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Linq 4 | { 5 | public enum ParallelMergeOptions 6 | { 7 | Default = 0, 8 | NotBuffered, 9 | AutoBuffered, 10 | FullyBuffered 11 | } 12 | } 13 | 14 | #endif -------------------------------------------------------------------------------- /Core/System/Linq/SortContext.cs: -------------------------------------------------------------------------------- 1 | // SortContext.cs 2 | // 3 | // Author: 4 | // Jb Evain (jbevain@novell.com) 5 | // 6 | // (C) 2008 Novell, Inc. (http://www.novell.com) 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining 9 | // a copy of this software and associated documentation files (the 10 | // "Software"), to deal in the Software without restriction, including 11 | // without limitation the rights to use, copy, modify, merge, publish, 12 | // distribute, sublicense, and/or sell copies of the Software, and to 13 | // permit persons to whom the Software is furnished to do so, subject to 14 | // the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | // Needed for NET30 28 | 29 | namespace Theraot.Core.System.Linq 30 | { 31 | internal abstract class SortContext 32 | { 33 | protected SortContext(SortDirection direction, SortContext childContext) 34 | { 35 | Direction = direction; 36 | ChildContext = childContext; 37 | } 38 | 39 | protected SortContext ChildContext { get; set; } 40 | 41 | protected SortDirection Direction { get; set; } 42 | 43 | public abstract int Compare(int firstIndex, int secondIndex); 44 | 45 | public abstract void Initialize(TElement[] elements); 46 | } 47 | } -------------------------------------------------------------------------------- /Core/System/Linq/SortDirection.cs: -------------------------------------------------------------------------------- 1 | // SortDirection.cs 2 | // 3 | // Author: 4 | // Jb Evain (jbevain@novell.com) 5 | // 6 | // (C) 2008 Novell, Inc. (http://www.novell.com) 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining 9 | // a copy of this software and associated documentation files (the 10 | // "Software"), to deal in the Software without restriction, including 11 | // without limitation the rights to use, copy, modify, merge, publish, 12 | // distribute, sublicense, and/or sell copies of the Software, and to 13 | // permit persons to whom the Software is furnished to do so, subject to 14 | // the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | // Needed for NET30 28 | 29 | namespace Theraot.Core.System.Linq 30 | { 31 | internal enum SortDirection 32 | { 33 | Ascending, 34 | Descending 35 | } 36 | } -------------------------------------------------------------------------------- /Core/System/Numerics/BigNumberBuffer.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System.Text; 4 | 5 | namespace Theraot.Core.System.Numerics 6 | { 7 | internal class BigNumberBuffer 8 | { 9 | public StringBuilder Digits; 10 | 11 | public bool Negative { get; set; } 12 | 13 | public int Scale { get; set; } 14 | 15 | public static BigNumberBuffer Create() 16 | { 17 | return new BigNumberBuffer 18 | { 19 | Digits = new StringBuilder() 20 | }; 21 | } 22 | } 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /Core/System/Progress.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | using System; 4 | using System.Threading; 5 | 6 | namespace Theraot.Core.System 7 | { 8 | // This class is new in .NET 4.5 9 | public class Progress : IProgress 10 | { 11 | private readonly Action _post; 12 | 13 | public Progress() 14 | { 15 | var context = SynchronizationContext.Current; 16 | if (context == null) 17 | { 18 | _post = value => 19 | { 20 | ThreadPool.QueueUserWorkItem(Callback, value); 21 | }; 22 | } 23 | else 24 | { 25 | _post = value => 26 | { 27 | context.Post(Callback, value); 28 | }; 29 | } 30 | } 31 | 32 | public Progress(Action handler) 33 | : this() 34 | { 35 | if (handler == null) 36 | { 37 | throw new ArgumentNullException("handler"); 38 | } 39 | ProgressChanged += (sender, args) => handler(args); 40 | } 41 | 42 | public event global::Theraot.Core.Theraot.Core.NewEventHandler ProgressChanged; 43 | 44 | public void Report(T value) 45 | { 46 | OnReport(value); 47 | } 48 | 49 | protected virtual void OnReport(T value) 50 | { 51 | if (ProgressChanged != null) 52 | { 53 | _post(value); 54 | } 55 | } 56 | 57 | private void Callback(object value) 58 | { 59 | var valueT = (T)value; 60 | var progressChanged = ProgressChanged; 61 | if (progressChanged != null) 62 | { 63 | progressChanged.Invoke(this, valueT); 64 | } 65 | } 66 | } 67 | } 68 | 69 | #endif -------------------------------------------------------------------------------- /Core/System/Reflection/IntrospectionExtensions.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Reflection 6 | { 7 | public static class IntrospectionExtensions 8 | { 9 | public static Type GetTypeInfo(this Type type) 10 | { 11 | return type; 12 | } 13 | } 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /Core/System/Reflection/RuntimeReflectionExtensions.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | #if NET20 || NET30 || NET35 || NET40 5 | 6 | namespace Theraot.Core.System.Reflection 7 | { 8 | public static class RuntimeReflectionExtensions 9 | { 10 | public static MethodInfo GetMethodInfo(this Delegate del) 11 | { 12 | return del.Method; 13 | } 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/AsyncMethodBuilderAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | // Licensed to the .NET Foundation under one or more agreements. 6 | // The .NET Foundation licenses this file to you under the MIT license. 7 | // See the LICENSE file in the project root for more information. 8 | 9 | namespace Theraot.Core.System.Runtime.CompilerServices 10 | { 11 | /// 12 | /// Indicates the type of the async method builder that should be used by a language compiler to 13 | /// build the attributed type when used as the return type of an async method. 14 | /// 15 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Delegate | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)] 16 | public sealed class AsyncMethodBuilderAttribute : Attribute 17 | { 18 | private readonly Type _builderType; 19 | 20 | /// Initializes the . 21 | /// The of the associated builder. 22 | public AsyncMethodBuilderAttribute(Type builderType) 23 | { 24 | _builderType = builderType; 25 | } 26 | 27 | /// Gets the of the associated builder. 28 | public Type BuilderType 29 | { 30 | get { return _builderType; } 31 | } 32 | } 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/AsyncStateMachineAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Identities the async state machine type for this method. 9 | /// 10 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] 11 | [Serializable] 12 | public sealed class AsyncStateMachineAttribute : StateMachineAttribute 13 | { 14 | /// 15 | /// Initializes the attribute. 16 | /// 17 | /// The type that implements the state machine. 18 | public AsyncStateMachineAttribute(Type stateMachineType) 19 | : base(stateMachineType) 20 | { 21 | } 22 | } 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/CallerFilePathAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Allows you to obtain the full path of the source file that contains the caller. This is the file path at the time of compile. 9 | /// 10 | /// 11 | /// You apply the CallerFilePath attribute to an optional parameter that has a default value. 12 | /// You must specify an explicit default value for the optional parameter. 13 | /// You can't apply this attribute to parameters that aren't specified as optional. 14 | /// 15 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] 16 | public sealed class CallerFilePathAttribute : Attribute 17 | { 18 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 19 | public CallerFilePathAttribute() 20 | { 21 | // Empty 22 | // This constructor is not redundant 23 | // You cannot put attributes on the default constructor 24 | } 25 | } 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/CallerLineNumberAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Allows you to obtain the line number in the source file at which the method is called. 9 | /// 10 | /// 11 | /// You apply the CallerFilePath attribute to an optional parameter that has a default value. 12 | /// You must specify an explicit default value for the optional parameter. 13 | /// You can't apply this attribute to parameters that aren't specified as optional. 14 | /// 15 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] 16 | public sealed class CallerLineNumberAttribute : Attribute 17 | { 18 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 19 | public CallerLineNumberAttribute() 20 | { 21 | // Empty 22 | // This constructor is not redundant 23 | // You cannot put attributes on the default constructor 24 | } 25 | } 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/CallerMemberNameAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | #if NET20 || NET30 || NET35 || NET40 5 | 6 | namespace Theraot.Core.System.Runtime.CompilerServices 7 | { 8 | /// 9 | /// Allows you to obtain the method or property name of the caller to the method. 10 | /// 11 | /// 12 | /// You apply the CallerMemberName attribute to an optional parameter that has a default value. 13 | /// You must specify an explicit default value for the optional parameter. 14 | /// You can't apply this attribute to parameters that aren't specified as optional. 15 | /// 16 | /// You can use the CallerMemberName attribute to avoid specifying the member name as a String argument to the called method. 17 | /// By using this technique, you avoid the problem that Rename Refactoring doesn't change the String values. 18 | /// This is especially useful for the following tasks: 19 | /// 20 | /// 21 | /// Using tracing and diagnostic routines. 22 | /// 23 | /// 24 | /// Implementing the interface when binding data. 25 | /// This interface allows the property of an object to notify a bound control that the property has changed, 26 | /// so that the control can display the updated information. 27 | /// Without the CallerMemberName attribute, you must specify the property name as a literal. 28 | /// 29 | /// 30 | /// 31 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] 32 | public sealed class CallerMemberNameAttribute : Attribute 33 | { 34 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 35 | public CallerMemberNameAttribute() 36 | { 37 | // Empty 38 | // This constructor is not redundant 39 | // You cannot put attributes on the default constructor 40 | } 41 | } 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/Closure.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | 6 | using System.ComponentModel; 7 | using System.Diagnostics; 8 | 9 | namespace Theraot.Core.System.Runtime.CompilerServices 10 | { 11 | /// 12 | /// This API supports the .NET Framework infrastructure and is not intended to be used directly from your code. 13 | /// Represents the runtime state of a dynamically generated method. 14 | /// 15 | [EditorBrowsable(EditorBrowsableState.Never), DebuggerStepThrough] 16 | public sealed class Closure 17 | { 18 | /// 19 | /// Represents the non-trivial constants and locally executable expressions that are referenced by a dynamically generated method. 20 | /// 21 | public readonly object[] Constants; 22 | 23 | /// 24 | /// Represents the hoisted local variables from the parent context. 25 | /// 26 | public readonly object[] Locals; 27 | 28 | /// 29 | /// Creates an object to hold state of a dynamically generated method. 30 | /// 31 | /// The constant values used by the method. 32 | /// The hoisted local variables from the parent context. 33 | public Closure(object[] constants, object[] locals) 34 | { 35 | Constants = constants; 36 | Locals = locals; 37 | } 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/DynamicAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Core.System.Runtime.CompilerServices 7 | { 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue)] 9 | public sealed class DynamicAttribute : Attribute 10 | { 11 | private static readonly IList _empty = Array.AsReadOnly(new[] { true }); 12 | 13 | private readonly IList _transformFlags; 14 | 15 | public DynamicAttribute() 16 | { 17 | _transformFlags = _empty; 18 | } 19 | 20 | public DynamicAttribute(bool[] transformFlags) 21 | { 22 | if (transformFlags == null) 23 | { 24 | throw new ArgumentNullException("transformFlags"); 25 | } 26 | _transformFlags = transformFlags; 27 | } 28 | 29 | public IList TransformFlags 30 | { 31 | get { return _transformFlags; } 32 | } 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/ExecutionScope.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System; 4 | using Theraot.Core.System.Linq.Expressions; 5 | 6 | namespace Theraot.Core.System.Runtime.CompilerServices 7 | { 8 | [Obsolete("do not use this type", true)] 9 | public partial class ExecutionScope 10 | { 11 | //These fields are accessed via Reflection 12 | public object[] Globals; 13 | 14 | public object[] Locals; 15 | 16 | public ExecutionScope Parent; 17 | } 18 | 19 | public partial class ExecutionScope 20 | { 21 | public Delegate CreateDelegate(int indexLambda, object[] locals) 22 | { 23 | GC.KeepAlive(indexLambda); 24 | GC.KeepAlive(locals); 25 | throw new NotSupportedException(); 26 | } 27 | 28 | public object[] CreateHoistedLocals() 29 | { 30 | throw new NotSupportedException(); 31 | } 32 | 33 | public Expression IsolateExpression(Expression expression, object[] locals) 34 | { 35 | GC.KeepAlive(expression); 36 | GC.KeepAlive(locals); 37 | throw new NotSupportedException(); 38 | } 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/ExtensionAttribute.net30.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 4 | 5 | namespace System.Runtime.CompilerServices 6 | { 7 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 8 | public sealed class ExtensionAttribute : Attribute 9 | { 10 | //Empty 11 | } 12 | } 13 | 14 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/IAsyncMethodBuilder.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | namespace Theraot.Core.System.Runtime.CompilerServices 4 | { 5 | /// 6 | /// Represents an asynchronous method builder. 7 | /// 8 | internal interface IAsyncMethodBuilder 9 | { 10 | void PreBoxInitialization(); 11 | } 12 | } 13 | 14 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/IAsyncStateMachine.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | namespace Theraot.Core.System.Runtime.CompilerServices 4 | { 5 | /// 6 | /// Represents state machines generated for asynchronous methods. This type is intended for compiler use only. 7 | /// 8 | public interface IAsyncStateMachine 9 | { 10 | /// 11 | /// Moves the state machine to its next state. 12 | /// 13 | void MoveNext(); 14 | 15 | /// 16 | /// Configures the state machine with a heap-allocated replica. 17 | /// 18 | /// The heap-allocated replica. 19 | void SetStateMachine(IAsyncStateMachine stateMachine); 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/ICriticalNotifyCompletion.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | using System.Security; 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | public interface ICriticalNotifyCompletion : INotifyCompletion 8 | { 9 | [SecurityCritical] 10 | void UnsafeOnCompleted(Action continuation); 11 | } 12 | } 13 | 14 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/INotifyCompletion.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | namespace Theraot.Core.System.Runtime.CompilerServices 4 | { 5 | public interface INotifyCompletion 6 | { 7 | void OnCompleted(Action continuation); 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/IRuntimeVariables.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | // Copyright (c) Microsoft. All rights reserved. 4 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | 6 | namespace Theraot.Core.System.Runtime.CompilerServices 7 | { 8 | /// 9 | /// An interface to represent values of runtime variables. 10 | /// 11 | public interface IRuntimeVariables 12 | { 13 | /// 14 | /// Count of the variables. 15 | /// 16 | int Count { get; } 17 | 18 | /// 19 | /// An indexer to get/set the values of the runtime variables. 20 | /// 21 | /// An index of the runtime variable. 22 | /// The value of the runtime variable. 23 | object this[int index] { get; set; } 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/IStrongBox.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System.Runtime.CompilerServices 4 | { 5 | public interface IStrongBox 6 | { 7 | object Value { get; set; } 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/IteratorStateMachineAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Identities the iterator state machine type for this method. 9 | /// 10 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] 11 | [Serializable] 12 | public sealed class IteratorStateMachineAttribute : StateMachineAttribute 13 | { 14 | /// 15 | /// Initializes the attribute. 16 | /// 17 | /// The type that implements the state machine. 18 | public IteratorStateMachineAttribute(Type stateMachineType) 19 | : base(stateMachineType) 20 | { 21 | } 22 | } 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/StateMachineAttribute.net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 || NET40 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Identities the state machine type for this method. 9 | /// 10 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] 11 | [Serializable] 12 | public class StateMachineAttribute : Attribute 13 | { 14 | /// 15 | /// Gets the type that implements the state machine. 16 | /// 17 | public Type StateMachineType { get; private set; } 18 | 19 | /// 20 | /// Initializes the attribute. 21 | /// 22 | /// The type that implements the state machine. 23 | public StateMachineAttribute(Type stateMachineType) 24 | { 25 | StateMachineType = stateMachineType; 26 | } 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/StrongBox.net30.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | namespace Theraot.Core.System.Runtime.CompilerServices 4 | { 5 | public class StrongBox : IStrongBox 6 | { 7 | public T Value; 8 | 9 | public StrongBox() 10 | { 11 | // Empty 12 | } 13 | 14 | public StrongBox(T value) 15 | { 16 | Value = value; 17 | } 18 | 19 | object IStrongBox.Value 20 | { 21 | get { return Value; } 22 | 23 | set { Value = (T)value; } 24 | } 25 | } 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/ValueTaskAwaiter.net40.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. 6 | 7 | using Theraot.Core.System.Threading.Tasks; 8 | 9 | namespace Theraot.Core.System.Runtime.CompilerServices 10 | { 11 | /// Provides an awaiter for a . 12 | public struct ValueTaskAwaiter : ICriticalNotifyCompletion 13 | { 14 | /// The value being awaited. 15 | private readonly ValueTask _value; 16 | 17 | /// Initializes the awaiter. 18 | /// The value to be awaited. 19 | internal ValueTaskAwaiter(ValueTask value) { _value = value; } 20 | 21 | /// Gets whether the has completed. 22 | public bool IsCompleted { get { return _value.IsCompleted; } } 23 | 24 | /// Gets the result of the ValueTask. 25 | public TResult GetResult() 26 | { 27 | return _value._task == null ? 28 | _value._result : 29 | _value._task.GetAwaiter().GetResult(); 30 | } 31 | 32 | /// Schedules the continuation action for this ValueTask. 33 | public void OnCompleted(Action continuation) 34 | { 35 | _value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().OnCompleted(continuation); 36 | } 37 | 38 | /// Schedules the continuation action for this ValueTask. 39 | public void UnsafeOnCompleted(Action continuation) 40 | { 41 | _value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().UnsafeOnCompleted(continuation); 42 | } 43 | } 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/CompilerServices/VoidTaskResult.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 || NET40 2 | 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Theraot.Core.System.Runtime.CompilerServices 6 | { 7 | /// 8 | /// Used with Task(of void) 9 | /// 10 | [StructLayout(LayoutKind.Sequential, Size = 1)] 11 | internal struct VoidTaskResult 12 | { 13 | } 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /Core/System/Runtime/TargetedPatchingOptOutAttribute.net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System.Runtime 6 | { 7 | /// Indicates that the .NET Framework class library method to which this attribute is applied is unlikely to be affected by servicing releases, and therefore is eligible to be inlined across Native Image Generator (NGen) images. 8 | [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)] 9 | public sealed class TargetedPatchingOptOutAttribute : Attribute 10 | { 11 | private readonly string _reason; 12 | 13 | /// Gets the reason why the method to which this attribute is applied is considered to be eligible for inlining across Native Image Generator (NGen) images. 14 | /// The reason why the method is considered to be eligible for inlining across NGen images. 15 | public string Reason 16 | { 17 | get { return _reason; } 18 | } 19 | 20 | /// Initializes a new instance of the class. 21 | /// The reason why the method to which the attribute is applied is considered to be eligible for inlining across Native Image Generator (NGen) images. 22 | public TargetedPatchingOptOutAttribute(string reason) 23 | { 24 | _reason = reason; 25 | } 26 | } 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/IThreadPoolWorkItem.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System.Security; 4 | using System.Threading; 5 | 6 | namespace Theraot.Core.System.Threading 7 | { 8 | internal interface IThreadPoolWorkItem 9 | { 10 | [SecurityCritical] 11 | void ExecuteWorkItem(); 12 | 13 | [SecurityCritical] 14 | void MarkAborted(ThreadAbortException exception); 15 | } 16 | 17 | internal static class ThreadPoolAdapter 18 | { 19 | internal static void QueueWorkItem(IThreadPoolWorkItem item) 20 | { 21 | ThreadPool.QueueUserWorkItem 22 | ( 23 | _ => 24 | { 25 | try 26 | { 27 | item.ExecuteWorkItem(); 28 | } 29 | catch (ThreadAbortException exception) 30 | { 31 | item.MarkAborted(exception); 32 | } 33 | } 34 | ); 35 | } 36 | } 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/LockRecursionException.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 2 | 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | namespace Theraot.Core.System.Threading 7 | { 8 | [Serializable] 9 | public class LockRecursionException : Exception 10 | { 11 | public LockRecursionException() 12 | { 13 | //Empty 14 | } 15 | 16 | public LockRecursionException(string message) 17 | : base(message) 18 | { 19 | //Empty 20 | } 21 | 22 | public LockRecursionException(string message, Exception inner) 23 | : base(message, inner) 24 | { 25 | //Empty 26 | } 27 | 28 | protected LockRecursionException(SerializationInfo info, StreamingContext context) 29 | : base(info, context) 30 | { 31 | //Empty 32 | } 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/LockRecursionPolicy.net30.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 4 | 5 | namespace Theraot.Core.System.Threading 6 | { 7 | [Serializable] 8 | public enum LockRecursionPolicy 9 | { 10 | NoRecursion, 11 | SupportsRecursion 12 | } 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/ReaderWriterLockSlim.helpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 4 | 5 | namespace Theraot.Core.System.Threading 6 | { 7 | internal static class ReaderWriterLockSlimExtensions 8 | { 9 | internal static bool Has(this LockState state, LockState value) 10 | { 11 | return (state & value) > 0; 12 | } 13 | 14 | internal static bool IsSet(this ManualResetEventSlim self) 15 | { 16 | return self.IsSet; 17 | } 18 | } 19 | 20 | [Flags] 21 | internal enum LockState 22 | { 23 | None = 0, 24 | Upgradable = 1, 25 | Read = 2, 26 | Write = 4, 27 | UpgradedRead = Upgradable | Read, 28 | UpgradedWrite = Upgradable | Write 29 | } 30 | 31 | internal class ThreadLockState 32 | { 33 | public LockState LockState; 34 | public int ReaderRecursiveCount; 35 | public int UpgradeableRecursiveCount; 36 | public int WriterRecursiveCount; 37 | } 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/IContinuationTask.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Threading.Tasks 4 | { 5 | internal interface IContinuationTask 6 | { 7 | Task Antecedent { get; } 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/InternalSpecialCancelException.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System; 4 | using System.Runtime.Serialization; 5 | 6 | namespace Theraot.Core.System.Threading.Tasks 7 | { 8 | [Serializable] 9 | internal class InternalSpecialCancelException : Exception 10 | { 11 | public InternalSpecialCancelException() 12 | { 13 | // Empty 14 | } 15 | 16 | public InternalSpecialCancelException(string message) 17 | : base(message) 18 | { 19 | // Empty 20 | } 21 | 22 | public InternalSpecialCancelException(string message, Exception inner) 23 | : base(message, inner) 24 | { 25 | // EMpty 26 | } 27 | 28 | protected InternalSpecialCancelException(SerializationInfo info, StreamingContext context) 29 | : base(info, context) 30 | { 31 | // Empty 32 | } 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/InternalTaskOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if NET20 || NET30 || NET35 4 | 5 | namespace Theraot.Core.System.Threading.Tasks 6 | { 7 | /// 8 | /// Task creation flags which are only used internally. 9 | /// 10 | [Flags] 11 | [Serializable] 12 | internal enum InternalTaskOptions 13 | { 14 | /// Specifies "No internal task options" 15 | None, 16 | 17 | /// Used to filter out internal vs. public task creation options. 18 | InternalOptionsMask = 0x0000FF00, 19 | 20 | ChildReplica = 0x0100, 21 | ContinuationTask = 0x0200, 22 | PromiseTask = 0x0400, 23 | SelfReplicating = 0x0800, 24 | 25 | /// 26 | /// Store the presence of TaskContinuationOptions.LazyCancellation, since it does not directly 27 | /// translate into any TaskCreationOptions. 28 | /// 29 | LazyCancellation = 0x1000, 30 | 31 | /// Specifies that the task will be queued by the runtime before handing it over to the user. 32 | /// This flag will be used to skip the cancellationtoken registration step, which is only meant for unstarted tasks. 33 | QueuedByRuntime = 0x2000, 34 | 35 | /// 36 | /// Denotes that Dispose should be a complete nop for a Task. Used when constructing tasks that are meant to be cached/reused. 37 | /// 38 | DoNotDispose = 0x4000 39 | } 40 | } 41 | 42 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/Task.yield.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using Theraot.Core.System.Runtime.CompilerServices; 4 | 5 | namespace Theraot.Core.System.Threading.Tasks 6 | { 7 | public partial class Task 8 | { 9 | /// 10 | /// Creates an awaitable that asynchronously yields back to the current context when awaited. 11 | /// 12 | /// 13 | /// 14 | /// A context that, when awaited, will asynchronously transition back into the current context. 15 | /// If SynchronizationContext.Current is non-null, that is treated as the current context. 16 | /// Otherwise, TaskScheduler.Current is treated as the current context. 17 | /// 18 | /// 19 | public static YieldAwaitable Yield() 20 | { 21 | return new YieldAwaitable(); 22 | } 23 | } 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/TaskContinuation.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | using System; 4 | using Theraot.Core.System.Diagnostics.Contracts; 5 | 6 | namespace Theraot.Core.System.Threading.Tasks 7 | { 8 | internal abstract class TaskContinuation 9 | { 10 | internal abstract void Run(Task completedTask, bool canInlineContinuationTask); 11 | 12 | protected static void InlineIfPossibleOrElseQueue(Task task) 13 | { 14 | Contract.Requires(task != null); 15 | var scheduler = task.ExecutingTaskScheduler; 16 | if (scheduler == null) 17 | { 18 | Contract.Assert(false); 19 | throw new InvalidOperationException(); 20 | } 21 | task.Start(task.ExecutingTaskScheduler, true, false); 22 | } 23 | } 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /Core/System/Threading/Tasks/TaskStatus.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System.Threading.Tasks 4 | { 5 | /// 6 | /// Represents the current stage in the lifecycle of a . 7 | /// 8 | public enum TaskStatus 9 | { 10 | /// 11 | /// The task has been initialized but has not yet been scheduled. 12 | /// 13 | Created = 0, 14 | 15 | /// 16 | /// The task is waiting to be activated and scheduled internally by the .NET Framework infrastructure. 17 | /// 18 | WaitingForActivation = 1, 19 | 20 | /// 21 | /// The task has been scheduled for execution but has not yet begun executing. 22 | /// 23 | WaitingToRun = 2, 24 | 25 | /// 26 | /// The task is running but has not yet completed. 27 | /// 28 | Running = 3, 29 | 30 | /// 31 | /// The task has finished executing and is implicitly waiting for 32 | /// attached child tasks to complete. 33 | /// 34 | WaitingForChildrenToComplete = 4, 35 | 36 | /// 37 | /// The task completed execution successfully. 38 | /// 39 | RanToCompletion = 5, 40 | 41 | /// 42 | /// The task acknowledged cancellation by throwing an OperationCanceledException with its own CancellationToken 43 | /// while the token was in signaled state, or the task's CancellationToken was already signaled before the 44 | /// task started executing. 45 | /// 46 | Canceled = 6, 47 | 48 | /// 49 | /// The task completed due to an unhandled exception. 50 | /// 51 | Faulted = 7 52 | } 53 | } 54 | 55 | #endif -------------------------------------------------------------------------------- /Core/System/Tuple.net35.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET30 || NET35 2 | 3 | namespace Theraot.Core.System 4 | { 5 | public static class Tuple 6 | { 7 | public static Tuple Create(T1 item1) 8 | { 9 | return new Tuple(item1); 10 | } 11 | 12 | public static Tuple Create(T1 item1, T2 item2) 13 | { 14 | return new Tuple(item1, item2); 15 | } 16 | 17 | public static Tuple Create(T1 item1, T2 item2, T3 item3) 18 | { 19 | return new Tuple(item1, item2, item3); 20 | } 21 | 22 | public static Tuple Create(T1 item1, T2 item2, T3 item3, T4 item4) 23 | { 24 | return new Tuple(item1, item2, item3, item4); 25 | } 26 | 27 | public static Tuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) 28 | { 29 | return new Tuple(item1, item2, item3, item4, item5); 30 | } 31 | 32 | public static Tuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) 33 | { 34 | return new Tuple(item1, item2, item3, item4, item5, item6); 35 | } 36 | 37 | public static Tuple Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) 38 | { 39 | return new Tuple(item1, item2, item3, item4, item5, item6, item7); 40 | } 41 | 42 | public static Tuple> Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) 43 | { 44 | return new Tuple>(item1, item2, item3, item4, item5, item6, item7, new Tuple(item8)); 45 | } 46 | } 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ConversionSet.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | using Theraot.Core; 7 | 8 | namespace Theraot.Collections 9 | { 10 | [System.Diagnostics.DebuggerNonUserCode] 11 | public class ConversionSet : ProgressiveSet 12 | { 13 | public ConversionSet(IEnumerable wrapped, Func converter) 14 | : base(BuildEnumerable(wrapped, converter)) 15 | { 16 | //Empty 17 | } 18 | 19 | public ConversionSet(IEnumerable wrapped, Func converter, Predicate filter) 20 | : base(BuildEnumerable(wrapped, converter, filter)) 21 | { 22 | //Empty 23 | } 24 | 25 | private static IEnumerable BuildEnumerable(IEnumerable wrapped, Func converter) 26 | { 27 | if (wrapped == null) 28 | { 29 | throw new ArgumentNullException("wrapped"); 30 | } 31 | if (converter == null) 32 | { 33 | throw new ArgumentNullException("converter"); 34 | } 35 | foreach (var item in wrapped) 36 | { 37 | yield return converter(item); 38 | } 39 | } 40 | 41 | private static IEnumerable BuildEnumerable(IEnumerable wrapped, Func converter, Predicate filter) 42 | { 43 | if (wrapped == null) 44 | { 45 | throw new ArgumentNullException("wrapped"); 46 | } 47 | if (converter == null) 48 | { 49 | throw new ArgumentNullException("converter"); 50 | } 51 | if (filter == null) 52 | { 53 | throw new ArgumentNullException("filter"); 54 | } 55 | foreach (var item in wrapped) 56 | { 57 | if (filter(item)) 58 | { 59 | yield return converter(item); 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ConvertedObserver.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | 6 | namespace Theraot.Core.Theraot.Collections 7 | { 8 | [Serializable] 9 | public sealed class ConvertedObserver : IObserver 10 | { 11 | private readonly Func _converter; 12 | private readonly IObserver _observer; 13 | 14 | public ConvertedObserver(IObserver observer, Func converter) 15 | { 16 | if (observer == null) 17 | { 18 | throw new ArgumentNullException("observer"); 19 | } 20 | _observer = observer; 21 | if (converter == null) 22 | { 23 | throw new ArgumentNullException("converter"); 24 | } 25 | _converter = converter; 26 | } 27 | 28 | public void OnCompleted() 29 | { 30 | _observer.OnCompleted(); 31 | } 32 | 33 | public void OnError(Exception error) 34 | { 35 | _observer.OnError(error); 36 | } 37 | 38 | public void OnNext(TInput value) 39 | { 40 | _observer.OnNext(_converter.Invoke(value)); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/CustomObserver.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | using Theraot.Core.Theraot.Core; 6 | 7 | namespace Theraot.Core.Theraot.Collections 8 | { 9 | [Serializable] 10 | public sealed class CustomObserver : IObserver 11 | { 12 | private readonly Action _onCompleted; 13 | private readonly Action _onError; 14 | private readonly Action _onNext; 15 | 16 | public CustomObserver(Action onNext) 17 | { 18 | _onCompleted = ActionHelper.GetNoopAction(); 19 | _onError = ActionHelper.GetNoopAction(); 20 | _onNext = onNext ?? ActionHelper.GetNoopAction(); 21 | } 22 | 23 | public CustomObserver(Action onCompleted, Action onError, Action onNext) 24 | { 25 | _onCompleted = onCompleted ?? ActionHelper.GetNoopAction(); 26 | _onError = onError ?? ActionHelper.GetNoopAction(); 27 | _onNext = onNext ?? ActionHelper.GetNoopAction(); 28 | } 29 | 30 | public void OnCompleted() 31 | { 32 | var onCompleted = _onCompleted; 33 | onCompleted(); 34 | } 35 | 36 | public void OnError(Exception error) 37 | { 38 | var onError = _onError; 39 | onError(error); 40 | } 41 | 42 | public void OnNext(T value) 43 | { 44 | var onNext = _onNext; 45 | onNext(value); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/EmptyCollection.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET30 2 | 3 | using System.Collections.ObjectModel; 4 | using Theraot.Core.System.Collections.Generic; 5 | using Theraot.Core.Theraot.Collections.ThreadSafe; 6 | 7 | namespace Theraot.Core.Theraot.Collections 8 | { 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | public sealed class EmptyCollection : ReadOnlyCollection, IReadOnlyCollection 11 | { 12 | private static readonly EmptyCollection _instance = new EmptyCollection(); 13 | 14 | private EmptyCollection() 15 | : base(ArrayReservoir.EmptyArray) 16 | { 17 | } 18 | 19 | public static EmptyCollection Instance 20 | { 21 | get { return _instance; } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/EmptyList.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | [System.Diagnostics.DebuggerNonUserCode] 8 | public sealed class EmptyList : ProgressiveList, IEnumerable 9 | { 10 | private static readonly EmptyList _instance = new EmptyList(); 11 | 12 | private EmptyList() 13 | : base(BuildEmptyEnumerable()) 14 | { 15 | Progressor.AsEnumerable().Consume(); 16 | } 17 | 18 | public static EmptyList Instance 19 | { 20 | get { return _instance; } 21 | } 22 | 23 | private static IEnumerable BuildEmptyEnumerable() 24 | { 25 | yield break; 26 | } 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/EmptySet.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | [System.Diagnostics.DebuggerNonUserCode] 8 | public sealed class EmptySet : ProgressiveSet, IEnumerable 9 | { 10 | private static readonly EmptySet _instance = new EmptySet(); 11 | 12 | private EmptySet() 13 | : base(BuildEmptyEnumerable()) 14 | { 15 | Progressor.AsEnumerable().Consume(); 16 | } 17 | 18 | public static EmptySet Instance 19 | { 20 | get { return _instance; } 21 | } 22 | 23 | private static IEnumerable BuildEmptyEnumerable() 24 | { 25 | yield break; 26 | } 27 | } 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ExtendedReadOnlyCollection.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Collections 7 | { 8 | public sealed partial class ExtendedReadOnlyCollection : IExtendedReadOnlyCollection, IExtendedCollection 9 | { 10 | bool IExtendedCollection.Remove(T item, IEqualityComparer comparer) 11 | { 12 | throw new NotSupportedException(); 13 | } 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Extensions.add.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Core.Theraot.Collections 7 | { 8 | public static partial class Extensions 9 | { 10 | public static int AddRange(this ICollection collection, IEnumerable items) 11 | { 12 | if (collection == null) 13 | { 14 | throw new ArgumentNullException("collection"); 15 | } 16 | if (items == null) 17 | { 18 | throw new ArgumentNullException("items"); 19 | } 20 | var count = 0; 21 | foreach (var item in items) 22 | { 23 | collection.Add(item); 24 | count++; 25 | } 26 | return count; 27 | } 28 | 29 | public static IEnumerable AddRangeEnumerable(this ICollection collection, IEnumerable items) 30 | { 31 | if (collection == null) 32 | { 33 | throw new ArgumentNullException("collection"); 34 | } 35 | if (items == null) 36 | { 37 | throw new ArgumentNullException("items"); 38 | } 39 | foreach (var item in items) 40 | { 41 | collection.Add(item); 42 | yield return item; 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Extensions.extra.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Theraot.Collections.Specialized; 6 | 7 | namespace Theraot.Collections 8 | { 9 | public static partial class Extensions 10 | { 11 | public static IEnumerable Append(this IEnumerable target, IEnumerable append) 12 | { 13 | return new ExtendedEnumerable(target, append); 14 | } 15 | 16 | public static IEnumerable Append(this IEnumerable target, T append) 17 | { 18 | return new ExtendedEnumerable(target, AsUnaryEnumerable(append)); 19 | } 20 | 21 | public static IEnumerable Cycle(this IEnumerable source) 22 | { 23 | if (source == null) 24 | { 25 | throw new ArgumentNullException("source"); 26 | } 27 | var progressive = new ProgressiveCollection(source); 28 | while (true) 29 | { 30 | foreach (var item in progressive) 31 | { 32 | yield return item; 33 | } 34 | } 35 | // Infinite Loop - This method creates an endless IEnumerable 36 | } 37 | 38 | public static IEnumerable Prepend(this IEnumerable target, IEnumerable prepend) 39 | { 40 | return new ExtendedEnumerable(prepend, target); 41 | } 42 | 43 | public static IEnumerable Prepend(this IEnumerable target, T prepend) 44 | { 45 | return new ExtendedEnumerable(AsUnaryEnumerable(prepend), target); 46 | } 47 | } 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Extensions.interleave.tt: -------------------------------------------------------------------------------- 1 | <#@ template language="C#" #>// 2 | 3 | #if FAT 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace Theraot.Collections 9 | { 10 | public static partial class Extensions 11 | {<# 12 | for (var indice = 2; indice < 17; indice++) 13 | {#> 14 | 15 | public static IEnumerable Interleave(<# if (indice != 0) { if (indice == 1) #>IEnumerable obj<# else for (var subindice = 1; subindice <= indice; subindice++){ if (subindice != 1) {#>, <#}#>IEnumerable arg<#=subindice#><#}}#>) 16 | { 17 | <# 18 | for (var subindice = 1; subindice <= indice; subindice++) 19 | {#> 20 | if (arg<#=subindice#> == null) 21 | { 22 | throw new ArgumentNullException("arg<#=subindice#>"); 23 | } 24 | <# 25 | }#> 26 | var ok = true; 27 | <# 28 | for (var subindice = 1; subindice <= indice; subindice++) 29 | {#> 30 | using (var enumerator<#=subindice#> = arg<#=subindice#>.GetEnumerator()) 31 | <# 32 | }#> 33 | { 34 | while (ok) 35 | { 36 | ok = false; 37 | <# 38 | for (var subindice = 1; subindice <= indice; subindice++) 39 | {#> 40 | if (enumerator<#=subindice#>.MoveNext()) 41 | { 42 | yield return enumerator<#=subindice#>.Current; 43 | ok = true; 44 | } 45 | <# 46 | }#> 47 | } 48 | } 49 | } 50 | <# 51 | }#> } 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Extensions.partition.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | namespace Theraot.Core.Theraot.Collections 8 | { 9 | public static partial class Extensions 10 | { 11 | public static IEnumerable> Partition(this IEnumerable items, int partitionSize) 12 | { 13 | if (items == null) 14 | { 15 | throw new ArgumentNullException("items"); 16 | } 17 | if (partitionSize < 1) 18 | { 19 | throw new ArgumentOutOfRangeException("partitionSize"); 20 | } 21 | return new PartitionEnumerable(items, partitionSize); 22 | } 23 | 24 | internal class PartitionEnumerable : IEnumerable> 25 | { 26 | private readonly IEnumerable _source; 27 | private readonly int _partitionSize; 28 | 29 | public PartitionEnumerable(IEnumerable source, int partitionSize) 30 | { 31 | _source = source; 32 | _partitionSize = partitionSize; 33 | } 34 | 35 | public IEnumerator> GetEnumerator() 36 | { 37 | var group = new List(); 38 | var count = _partitionSize; 39 | foreach (var item in _source) 40 | { 41 | group.Add(item); 42 | count--; 43 | if (count == 0) 44 | { 45 | yield return group; 46 | group = new List(); 47 | count = _partitionSize; 48 | } 49 | } 50 | if (count < _partitionSize) 51 | { 52 | yield return group; 53 | } 54 | } 55 | 56 | IEnumerator IEnumerable.GetEnumerator() 57 | { 58 | return GetEnumerator(); 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/FilteredConvertedObserver.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | 6 | namespace Theraot.Core.Theraot.Collections 7 | { 8 | [Serializable] 9 | public sealed class FilteredConvertedObserver : IObserver 10 | { 11 | private readonly Func _converter; 12 | private readonly IObserver _observer; 13 | private readonly Predicate _filter; 14 | 15 | public FilteredConvertedObserver(IObserver observer, Predicate filter, Func converter) 16 | { 17 | if (observer == null) 18 | { 19 | throw new ArgumentNullException("observer"); 20 | } 21 | if (converter == null) 22 | { 23 | throw new ArgumentNullException("converter"); 24 | } 25 | if (filter == null) 26 | { 27 | throw new ArgumentNullException("filter"); 28 | } 29 | _observer = observer; 30 | _converter = converter; 31 | _filter = filter; 32 | } 33 | 34 | public void OnCompleted() 35 | { 36 | _observer.OnCompleted(); 37 | } 38 | 39 | public void OnError(Exception error) 40 | { 41 | _observer.OnError(error); 42 | } 43 | 44 | public void OnNext(TInput value) 45 | { 46 | var filter = _filter; 47 | if (filter(value)) 48 | { 49 | _observer.OnNext(_converter.Invoke(value)); 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/FilteredObserver.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | 6 | namespace Theraot.Core.Theraot.Collections 7 | { 8 | [Serializable] 9 | public sealed class FilteredObserver : IObserver 10 | { 11 | private readonly IObserver _observer; 12 | private readonly Predicate _filter; 13 | 14 | public FilteredObserver(IObserver observer, Predicate filter) 15 | { 16 | if (observer == null) 17 | { 18 | throw new ArgumentNullException("observer"); 19 | } 20 | if (filter == null) 21 | { 22 | throw new ArgumentNullException("filter"); 23 | } 24 | _observer = observer; 25 | _filter = filter; 26 | } 27 | 28 | public void OnCompleted() 29 | { 30 | _observer.OnCompleted(); 31 | } 32 | 33 | public void OnError(Exception error) 34 | { 35 | _observer.OnError(error); 36 | } 37 | 38 | public void OnNext(T value) 39 | { 40 | var filter = _filter; 41 | if (filter(value)) 42 | { 43 | _observer.OnNext(value); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/IDropPoint.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Collections 4 | { 5 | public interface IDropPoint : IReadOnlyDropPoint 6 | { 7 | bool Add(T item); 8 | 9 | void Clear(); 10 | 11 | bool TryTake(out T item); 12 | } 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedCollection.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedCollection : ICollection, IExtendedReadOnlyCollection 8 | { 9 | // Collides ICollection with IExtendedReadOnlyCollection 10 | IReadOnlyCollection AsReadOnly { get; } 11 | 12 | new int Count { get; } 13 | 14 | bool Remove(T item, IEqualityComparer comparer); 15 | } 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedDictionary.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedDictionary : IDictionary, IExtendedReadOnlyDictionary 8 | { 9 | // Collides IDictionary with IExtendedReadOnlyDictionary 10 | new IReadOnlyDictionary AsReadOnly { get; } 11 | } 12 | } 13 | 14 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedList.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedList : IExtendedCollection, IExtendedReadOnlyList, IList 8 | { 9 | new IReadOnlyList AsReadOnly { get; } 10 | 11 | new int Count { get; } 12 | 13 | new T this[int index] { get; set; } 14 | 15 | void Move(int oldIndex, int newIndex); 16 | 17 | void RemoveRange(int index, int count); 18 | 19 | void Reverse(); 20 | 21 | void Reverse(int index, int count); 22 | 23 | void Sort(IComparer comparer); 24 | 25 | void Sort(int index, int count, IComparer comparer); 26 | 27 | void Swap(int indexA, int indexB); 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedReadOnlyCollection.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedReadOnlyCollection : IReadOnlyCollection 8 | { 9 | // Intended to collide with ICollection 10 | bool Contains(T item); 11 | 12 | bool Contains(T item, IEqualityComparer comparer); 13 | 14 | void CopyTo(T[] array); 15 | 16 | void CopyTo(T[] array, int arrayIndex); 17 | 18 | void CopyTo(T[] array, int arrayIndex, int countLimit); 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedReadOnlyDictionary.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedReadOnlyDictionary : IReadOnlyDictionary, IReadOnlyCollection>, IExtendedCollection> 8 | { 9 | // Intended to collide with IDictionary 10 | new IReadOnlyCollection Keys { get; } 11 | 12 | new IReadOnlyCollection Values { get; } 13 | } 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedReadOnlyList.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedReadOnlyList : IReadOnlyList 8 | { 9 | int IndexOf(T item); 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedReadOnlySet.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Collections 4 | { 5 | public interface IExtendedReadOnlySet : IReadOnlySet, IExtendedReadOnlyCollection 6 | { 7 | //Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IExtendedSet.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IExtendedSet : IReadOnlySet, ISet 8 | { 9 | IReadOnlySet AsReadOnly { get; } 10 | 11 | new int Count { get; } 12 | 13 | new bool Add(T item); 14 | 15 | new bool IsProperSubsetOf(IEnumerable other); 16 | 17 | new bool IsProperSupersetOf(IEnumerable other); 18 | 19 | new bool IsSubsetOf(IEnumerable other); 20 | 21 | new bool IsSupersetOf(IEnumerable other); 22 | 23 | new bool Overlaps(IEnumerable other); 24 | 25 | bool Remove(T item, IEqualityComparer comparer); 26 | 27 | new bool SetEquals(IEnumerable other); 28 | } 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IProxyObservable.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using Theraot.Core.System; 4 | 5 | namespace Theraot.Core.Theraot.Collections 6 | { 7 | public interface IProxyObservable : IObservable, IObserver 8 | { 9 | // Empty 10 | } 11 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/IReadOnlyDropPoint.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IReadOnlyDropPoint : IReadOnlyCollection 8 | { 9 | T Item { get; } 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/IReadOnlySet.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public interface IReadOnlySet : IReadOnlyCollection 8 | { 9 | bool IsProperSubsetOf(IEnumerable other); 10 | 11 | bool IsProperSupersetOf(IEnumerable other); 12 | 13 | bool IsSubsetOf(IEnumerable other); 14 | 15 | bool IsSupersetOf(IEnumerable other); 16 | 17 | bool Overlaps(IEnumerable other); 18 | 19 | bool SetEquals(IEnumerable other); 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/KeyValuePairComparer.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections 6 | { 7 | public class KeyValuePairComparer : IComparer> 8 | { 9 | private readonly IComparer _keyComparer; 10 | private readonly IComparer _valueComparer; 11 | 12 | public KeyValuePairComparer(IComparer keyComparer, IComparer valueComparer) 13 | { 14 | _keyComparer = keyComparer ?? Comparer.Default; 15 | _valueComparer = valueComparer ?? Comparer.Default; 16 | } 17 | 18 | public int Compare(KeyValuePair x, KeyValuePair y) 19 | { 20 | var result = _keyComparer.Compare(x.Key, y.Key); 21 | return result == 0 ? _valueComparer.Compare(x.Value, y.Value) : result; 22 | } 23 | } 24 | } 25 | 26 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/KeyValuePairEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Theraot.Core.Theraot.Collections 4 | { 5 | public class KeyValuePairEqualityComparer : IEqualityComparer> 6 | { 7 | private readonly IEqualityComparer _keyComparer; 8 | private readonly IEqualityComparer _valueComparer; 9 | 10 | public KeyValuePairEqualityComparer(IEqualityComparer keyComparer, IEqualityComparer valueComparer) 11 | { 12 | _keyComparer = keyComparer ?? EqualityComparer.Default; 13 | _valueComparer = valueComparer ?? EqualityComparer.Default; 14 | } 15 | 16 | public bool Equals(KeyValuePair x, KeyValuePair y) 17 | { 18 | return _keyComparer.Equals(x.Key, y.Key) && _valueComparer.Equals(x.Value, y.Value); 19 | } 20 | 21 | public int GetHashCode(KeyValuePair obj) 22 | { 23 | return (_keyComparer.GetHashCode(obj.Key) * 13) + _valueComparer.GetHashCode(obj.Value); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/ProgressiveCollection.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Collections 7 | { 8 | public partial class ProgressiveCollection : IExtendedCollection 9 | { 10 | IReadOnlyCollection IExtendedCollection.AsReadOnly 11 | { 12 | get { return this; } 13 | } 14 | 15 | bool IExtendedCollection.Remove(T item, IEqualityComparer comparer) 16 | { 17 | throw new NotSupportedException(); 18 | } 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ProgressiveList.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Collections 7 | { 8 | public partial class ProgressiveList : IExtendedList 9 | { 10 | IReadOnlyList IExtendedList.AsReadOnly 11 | { 12 | get { return this; } 13 | } 14 | 15 | T IExtendedList.this[int index] 16 | { 17 | get { return this[index]; } 18 | 19 | set { throw new NotSupportedException(); } 20 | } 21 | 22 | bool IExtendedCollection.Remove(T item, IEqualityComparer comparer) 23 | { 24 | throw new NotSupportedException(); 25 | } 26 | 27 | void IExtendedList.Move(int oldIndex, int newIndex) 28 | { 29 | throw new NotSupportedException(); 30 | } 31 | 32 | void IExtendedList.RemoveRange(int index, int count) 33 | { 34 | throw new NotSupportedException(); 35 | } 36 | 37 | void IExtendedList.Reverse() 38 | { 39 | throw new NotSupportedException(); 40 | } 41 | 42 | void IExtendedList.Reverse(int index, int count) 43 | { 44 | throw new NotSupportedException(); 45 | } 46 | 47 | void IExtendedList.Sort(IComparer comparer) 48 | { 49 | throw new NotSupportedException(); 50 | } 51 | 52 | void IExtendedList.Sort(int index, int count, IComparer comparer) 53 | { 54 | throw new NotSupportedException(); 55 | } 56 | 57 | void IExtendedList.Swap(int indexA, int indexB) 58 | { 59 | throw new NotSupportedException(); 60 | } 61 | } 62 | } 63 | 64 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ProgressiveSet.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Collections 7 | { 8 | public partial class ProgressiveSet : IExtendedReadOnlySet, IExtendedSet 9 | { 10 | IReadOnlySet IExtendedSet.AsReadOnly 11 | { 12 | get { return this; } 13 | } 14 | 15 | bool IExtendedSet.Add(T item) 16 | { 17 | throw new NotSupportedException(); 18 | } 19 | 20 | bool IExtendedSet.Remove(T item, IEqualityComparer comparer) 21 | { 22 | throw new NotSupportedException(); 23 | } 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ProxyObservable.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | using Theraot.Core.Theraot.Collections.ThreadSafe; 6 | using Theraot.Core.Theraot.Threading; 7 | using Theraot.Core.Theraot.Threading.Needles; 8 | 9 | namespace Theraot.Core.Theraot.Collections 10 | { 11 | [Serializable] 12 | public sealed class ProxyObservable : IObservable, IObserver, IProxyObservable 13 | { 14 | private readonly SafeSet>> _observers; 15 | 16 | public ProxyObservable() 17 | { 18 | _observers = new SafeSet>>(); 19 | } 20 | 21 | public void OnCompleted() 22 | { 23 | foreach (var item in _observers) 24 | { 25 | item.Value.OnCompleted(); 26 | } 27 | } 28 | 29 | public void OnError(Exception error) 30 | { 31 | foreach (var item in _observers) 32 | { 33 | item.Value.OnError(error); 34 | } 35 | } 36 | 37 | public void OnNext(T value) 38 | { 39 | foreach (var item in _observers) 40 | { 41 | item.Value.OnNext(value); 42 | } 43 | } 44 | 45 | public IDisposable Subscribe(IObserver observer) 46 | { 47 | var needle = new Needle>(observer); 48 | _observers.AddNew(needle); 49 | return Disposable.Create(() => _observers.Remove(needle)); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/ConditionalExtendedEnumerable.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET30 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Theraot.Core.System; 6 | using Theraot.Core.Theraot.Core; 7 | 8 | namespace Theraot.Core.Theraot.Collections.Specialized 9 | { 10 | [global::System.Diagnostics.DebuggerNonUserCode] 11 | public sealed class ConditionalExtendedEnumerable : ExtendedEnumerableBase, IEnumerable 12 | { 13 | private readonly Func _enumerateAppend; 14 | private readonly Func _enumerateTarget; 15 | 16 | public ConditionalExtendedEnumerable(IEnumerable target, IEnumerable append, Func enumerateTarget, Func enumerateAppend) 17 | : base(target, append) 18 | { 19 | if (enumerateTarget == null) 20 | { 21 | throw new ArgumentNullException("enumerateTarget"); 22 | } 23 | _enumerateTarget = enumerateTarget; 24 | _enumerateAppend = enumerateAppend ?? (null == append ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); 25 | } 26 | 27 | public override IEnumerator GetEnumerator() 28 | { 29 | if (_enumerateTarget.Invoke()) 30 | { 31 | foreach (var item in Target) 32 | { 33 | yield return item; 34 | } 35 | } 36 | if (_enumerateAppend.Invoke()) 37 | { 38 | foreach (var item in Append) 39 | { 40 | yield return item; 41 | } 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/ConversionComparer.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | using Theraot.Core; 7 | 8 | namespace Theraot.Collections.Specialized 9 | { 10 | [System.Diagnostics.DebuggerNonUserCode] 11 | public class ConversionComparer : IComparer 12 | { 13 | private readonly IComparer _comparer; 14 | private readonly Func _converter; 15 | 16 | public ConversionComparer(IComparer comparer, Func converter) 17 | { 18 | if (comparer == null) 19 | { 20 | throw new ArgumentNullException("comparer"); 21 | } 22 | _comparer = comparer; 23 | if (converter == null) 24 | { 25 | throw new ArgumentNullException("converter"); 26 | } 27 | _converter = converter; 28 | } 29 | 30 | public int Compare(TInput x, TInput y) 31 | { 32 | return _comparer.Compare(_converter(x), _converter(y)); 33 | } 34 | } 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/ConversionEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (ConditionalWeakTable) 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Theraot.Core.System; 6 | 7 | namespace Theraot.Core.Theraot.Collections.Specialized 8 | { 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | public class ConversionEqualityComparer : IEqualityComparer 11 | { 12 | private readonly IEqualityComparer _comparer; 13 | private readonly Func _converter; 14 | 15 | public ConversionEqualityComparer(IEqualityComparer comparer, Func converter) 16 | { 17 | _comparer = comparer ?? EqualityComparer.Default; 18 | if (converter == null) 19 | { 20 | throw new ArgumentNullException("converter"); 21 | } 22 | _converter = converter; 23 | } 24 | 25 | public bool Equals(TInput x, TInput y) 26 | { 27 | return _comparer.Equals(_converter.Invoke(x), _converter.Invoke(y)); 28 | } 29 | 30 | public int GetHashCode(TInput obj) 31 | { 32 | return _comparer.GetHashCode(_converter.Invoke(obj)); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/CustomComparer.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workaround 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Theraot.Core.System; 6 | 7 | namespace Theraot.Core.Theraot.Collections.Specialized 8 | { 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | public class CustomComparer : IComparer 11 | { 12 | private readonly Func _comparison; 13 | 14 | public CustomComparer(Func comparison) 15 | { 16 | if (comparison == null) 17 | { 18 | throw new ArgumentNullException("comparison"); 19 | } 20 | _comparison = comparison; 21 | } 22 | 23 | public CustomComparer(Comparison comparison) 24 | { 25 | if (comparison == null) 26 | { 27 | throw new ArgumentNullException("comparison"); 28 | } 29 | _comparison = comparison.Invoke; 30 | } 31 | 32 | public int Compare(T x, T y) 33 | { 34 | return _comparison.Invoke(x, y); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/DelegatedCollection.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Collections.Specialized 4 | { 5 | public partial class DelegatedCollection : IExtendedCollection 6 | { 7 | // Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/EnumCollection.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Globalization; 6 | using System.Reflection; 7 | 8 | namespace Theraot.Collections.Specialized 9 | { 10 | public sealed class EnumCollection : ProgressiveCollection 11 | { 12 | private static readonly EnumCollection _instance = new EnumCollection(); 13 | 14 | private EnumCollection() 15 | : base(GetEnumerable()) 16 | { 17 | //Empty 18 | } 19 | 20 | public static EnumCollection Instance 21 | { 22 | get { return _instance; } 23 | } 24 | 25 | public static IEnumerable GetEnumerable() 26 | { 27 | var type = CheckType(); 28 | foreach (var item in Enum.GetValues(type)) 29 | { 30 | yield return (TEnum)item; 31 | } 32 | } 33 | 34 | public static string ToString(TEnum value) 35 | { 36 | var type = CheckType(); 37 | return Enum.GetName(type, value); 38 | } 39 | 40 | private static Type CheckType() 41 | { 42 | var type = typeof(TEnum); 43 | var info = type.GetTypeInfo(); 44 | if (info.IsEnum) 45 | { 46 | return type; 47 | } 48 | else 49 | { 50 | throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} is not an Enum", type.Name)); 51 | } 52 | } 53 | } 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/EnumerableFromDelegate.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using Theraot.Core.System; 7 | using Theraot.Core.Theraot.Core; 8 | 9 | namespace Theraot.Core.Theraot.Collections.Specialized 10 | { 11 | public class EnumerableFromDelegate : IEnumerable 12 | { 13 | private readonly Func> _getEnumerator; 14 | 15 | public EnumerableFromDelegate(Func getEnumerator) 16 | { 17 | // Specify the type arguments explicitly 18 | _getEnumerator = getEnumerator.ChainConversion>(ConvertEnumerator); 19 | } 20 | 21 | public IEnumerator GetEnumerator() 22 | { 23 | return _getEnumerator.Invoke(); 24 | } 25 | 26 | IEnumerator IEnumerable.GetEnumerator() 27 | { 28 | return _getEnumerator.Invoke(); 29 | } 30 | 31 | private static IEnumerator ConvertEnumerator(IEnumerator enumerator) 32 | { 33 | if (enumerator == null) 34 | { 35 | return null; 36 | } 37 | var genericEnumerator = enumerator as IEnumerator; 38 | if (genericEnumerator != null) 39 | { 40 | return genericEnumerator; 41 | } 42 | return ConvertEnumeratorExtracted(enumerator); 43 | } 44 | 45 | private static IEnumerator ConvertEnumeratorExtracted(IEnumerator enumerator) 46 | { 47 | try 48 | { 49 | while (enumerator.MoveNext()) 50 | { 51 | var element = enumerator.Current; 52 | if (element is T) 53 | { 54 | yield return (T)element; 55 | } 56 | } 57 | } 58 | finally 59 | { 60 | var disposable = enumerator as IDisposable; 61 | if (disposable != null) 62 | { 63 | disposable.Dispose(); 64 | } 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/EnumerationCollection.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Collections.Specialized 7 | { 8 | public partial class EnumerationCollection : IExtendedCollection 9 | { 10 | IReadOnlyCollection IExtendedCollection.AsReadOnly 11 | { 12 | get { return this; } 13 | } 14 | 15 | bool IExtendedCollection.Remove(T item, IEqualityComparer comparer) 16 | { 17 | throw new NotSupportedException(); 18 | } 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/ExtendedEnumerable.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (BigInteger) 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.Theraot.Collections.Specialized 6 | { 7 | [global::System.Diagnostics.DebuggerNonUserCode] 8 | public sealed class ExtendedEnumerable : ExtendedEnumerableBase, IEnumerable 9 | { 10 | public ExtendedEnumerable(IEnumerable target, IEnumerable append) 11 | : base(target, append) 12 | { 13 | //Empty 14 | } 15 | 16 | public override IEnumerator GetEnumerator() 17 | { 18 | foreach (var item in Target) 19 | { 20 | yield return item; 21 | } 22 | foreach (var item in Append) 23 | { 24 | yield return item; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/ExtendedEnumerableBase.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET30 2 | 3 | using System.Collections.Generic; 4 | using Theraot.Core.Theraot.Collections.ThreadSafe; 5 | 6 | namespace Theraot.Core.Theraot.Collections.Specialized 7 | { 8 | [global::System.Diagnostics.DebuggerNonUserCode] 9 | public abstract class ExtendedEnumerableBase : IEnumerable 10 | { 11 | private readonly IEnumerable _append; 12 | private readonly IEnumerable _target; 13 | 14 | protected ExtendedEnumerableBase(IEnumerable target, IEnumerable append) 15 | { 16 | _target = target ?? ArrayReservoir.EmptyArray; 17 | _append = append ?? ArrayReservoir.EmptyArray; 18 | } 19 | 20 | protected IEnumerable Append 21 | { 22 | get { return _append; } 23 | } 24 | 25 | protected IEnumerable Target 26 | { 27 | get { return _target; } 28 | } 29 | 30 | public abstract IEnumerator GetEnumerator(); 31 | 32 | global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() 33 | { 34 | return GetEnumerator(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/Grouping.cs: -------------------------------------------------------------------------------- 1 | // Permission is hereby granted, free of charge, to any person obtaining 2 | // a copy of this software and associated documentation files (the 3 | // "Software"), to deal in the Software without restriction, including 4 | // without limitation the rights to use, copy, modify, merge, publish, 5 | // distribute, sublicense, and/or sell copies of the Software, and to 6 | // permit persons to whom the Software is furnished to do so, subject to 7 | // the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be 10 | // included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 13 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 14 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 16 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 18 | // 19 | // Authors: 20 | // Alejandro Serrano "Serras" (trupill@yahoo.es) 21 | 22 | #if FAT 23 | 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | 28 | namespace Theraot.Collections.Specialized 29 | { 30 | internal class Grouping : IGrouping 31 | { 32 | private readonly IEnumerable _group; 33 | 34 | public Grouping(TK key, IEnumerable group) 35 | { 36 | _group = group; 37 | Key = key; 38 | } 39 | 40 | public TK Key { get; set; } 41 | 42 | public IEnumerator GetEnumerator() 43 | { 44 | return _group.GetEnumerator(); 45 | } 46 | 47 | IEnumerator IEnumerable.GetEnumerator() 48 | { 49 | return _group.GetEnumerator(); 50 | } 51 | } 52 | } 53 | 54 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/NeedleConversionEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (ConditionalWeakTable) 2 | 3 | using System.Collections.Generic; 4 | using Theraot.Core.Theraot.Threading.Needles; 5 | 6 | namespace Theraot.Core.Theraot.Collections.Specialized 7 | { 8 | [global::System.Diagnostics.DebuggerNonUserCode] 9 | public sealed class NeedleConversionEqualityComparer : ConversionEqualityComparer, IEqualityComparer 10 | where TNeedle : INeedle 11 | { 12 | public NeedleConversionEqualityComparer(IEqualityComparer comparer) 13 | : base(comparer, Conversion) 14 | { 15 | // Empty 16 | } 17 | 18 | private static T Conversion(TNeedle needle) 19 | { 20 | if (ReferenceEquals(needle, null)) 21 | { 22 | return default(T); 23 | } 24 | return needle.Value; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/Specialized/NullAwareDictionary.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Collections.Specialized 6 | { 7 | [System.Diagnostics.DebuggerDisplay("Count={Count}")] 8 | public sealed partial class NullAwareDictionary : IExtendedDictionary 9 | { 10 | IEnumerable IReadOnlyDictionary.Keys 11 | { 12 | get { return _keys; } 13 | } 14 | 15 | IEnumerable IReadOnlyDictionary.Values 16 | { 17 | get { return _values; } 18 | } 19 | 20 | IReadOnlyCollection> IExtendedCollection>.AsReadOnly 21 | { 22 | get { return _readOnly; } 23 | } 24 | 25 | IReadOnlyCollection IExtendedReadOnlyDictionary.Keys 26 | { 27 | get { return _keys; } 28 | } 29 | 30 | IReadOnlyCollection IExtendedReadOnlyDictionary.Values 31 | { 32 | get { return _values; } 33 | } 34 | } 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/ThreadSafe/DoAction.cs: -------------------------------------------------------------------------------- 1 | namespace Theraot.Core.Theraot.Collections.ThreadSafe 2 | { 3 | internal delegate bool DoAction(ref object value); 4 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/ThreadSafe/IBucket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Theraot.Core.System; 4 | 5 | namespace Theraot.Core.Theraot.Collections.ThreadSafe 6 | { 7 | public interface IBucket : IEnumerable 8 | { 9 | int Count { get; } 10 | 11 | void CopyTo(T[] array, int arrayIndex); 12 | 13 | bool Exchange(int index, T item, out T previous); 14 | 15 | bool Insert(int index, T item); 16 | 17 | bool Insert(int index, T item, out T previous); 18 | 19 | bool RemoveAt(int index); 20 | 21 | bool RemoveAt(int index, out T previous); 22 | 23 | bool RemoveAt(int index, Predicate check); 24 | 25 | void Set(int index, T item, out bool isNew); 26 | 27 | bool TryGet(int index, out T value); 28 | 29 | bool Update(int index, Func itemUpdateFactory, Predicate check, out bool isEmpty); 30 | 31 | IEnumerable Where(Predicate check); 32 | } 33 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/ThreadSafe/ReentryGuardHelper.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System.Collections.Generic; 5 | using Theraot.Core.Theraot.Threading; 6 | 7 | namespace Theraot.Core.Theraot.Collections.ThreadSafe 8 | { 9 | internal static class ReentryGuardHelper 10 | { 11 | [ThreadStatic] 12 | private static HashSet _guard; 13 | 14 | public static bool Enter(RuntimeUniqueIdProdiver.UniqueId id) 15 | { 16 | // Assume anything could have been set to null, start no sync operation, this could be running during DomainUnload 17 | var guard = _guard; 18 | if (guard == null) 19 | { 20 | _guard = new HashSet { id }; 21 | return true; 22 | } 23 | if (!guard.Contains(id)) 24 | { 25 | guard.Add(id); 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | public static bool IsTaken(RuntimeUniqueIdProdiver.UniqueId id) 32 | { 33 | return _guard.Contains(id); 34 | } 35 | 36 | public static void Leave(RuntimeUniqueIdProdiver.UniqueId id) 37 | { 38 | // Assume anything could have been set to null, start no sync operation, this could be running during DomainUnload 39 | var guard = _guard; 40 | if (guard != null) 41 | { 42 | guard.Remove(id); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Core/Theraot/Collections/ThreadSafe/WeakCancellableEvent.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.ComponentModel; 4 | 5 | namespace Theraot.Collections.ThreadSafe 6 | { 7 | [System.Diagnostics.DebuggerNonUserCode] 8 | public class WeakCancellableEvent : WeakEvent 9 | where TCancelEventArgs : CancelEventArgs 10 | { 11 | public WeakCancellableEvent() 12 | { 13 | //Empty 14 | } 15 | 16 | public WeakCancellableEvent(bool reentryGuard) 17 | : base(reentryGuard) 18 | { 19 | //Empty 20 | } 21 | 22 | public override void Invoke(object sender, TCancelEventArgs eventArgs) 23 | { 24 | foreach (var handler in EventHandlers) 25 | { 26 | handler.DynamicInvoke(eventArgs); 27 | if (eventArgs.Cancel) 28 | { 29 | break; 30 | } 31 | } 32 | } 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Collections/TryTake.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Collections 4 | { 5 | public delegate bool TryTake(out T item); 6 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/AggregateExceptionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Theraot.Core.System; 3 | 4 | namespace Theraot.Core.Theraot.Core 5 | { 6 | public static class AggregateExceptionHelper 7 | { 8 | public static void AddException(ref AggregateException target, Exception source) 9 | { 10 | target = ReferenceEquals(target, null) ? new AggregateException(source) : (new AggregateException(source, target)).Flatten(); 11 | } 12 | 13 | public static void AddException(ref Exception target, Exception source) 14 | { 15 | target = ReferenceEquals(target, null) ? new AggregateException(source) : (new AggregateException(source, target)).Flatten(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/CancellationTokenHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Theraot.Core.System.Threading; 3 | 4 | namespace Theraot.Core.Theraot.Core 5 | { 6 | public static class CancellationTokenHelper 7 | { 8 | public static void ThrowIfSourceDisposed(this CancellationToken cancellationToken) 9 | { 10 | //CancellationToken.WaitHandle is documented to throw ObjectDispodesException if the source of the CancellationToken is disposed. 11 | GC.KeepAlive(cancellationToken.WaitHandle); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/CharHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Theraot.Core.Theraot.Core 2 | { 3 | public static class CharHelper 4 | { 5 | private static readonly string _classicWhitespace = 6 | "\u0009" + // Tab 7 | "\u000A" + // NewLine 8 | "\u000B" + // Vertical Tab 9 | "\u000C" + // Form Feed 10 | "\u000D" + // Carriage return 11 | "\u0020"; // Space 12 | 13 | public static bool IsClassicWhitespace(char character) 14 | { 15 | return _classicWhitespace.IndexOf(character) >= 0; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/Check.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | [global::System.Diagnostics.DebuggerNonUserCode] 8 | public static class Check 9 | { 10 | public static TArgument CheckArgument(TArgument argument, Predicate check, string parameterName) 11 | { 12 | if (check == null || !check(argument)) 13 | { 14 | throw new ArgumentException(parameterName, parameterName); 15 | } 16 | return argument; 17 | } 18 | 19 | public static TArgument InRangeArgument(TArgument argument, Predicate isInRange, string parameterName) 20 | { 21 | if (isInRange == null || !isInRange(argument)) 22 | { 23 | throw new ArgumentOutOfRangeException(parameterName, argument, parameterName + " is out of range."); 24 | } 25 | return argument; 26 | } 27 | 28 | public static T NotNullArgument(T argument, string parameterName) 29 | { 30 | if (ReferenceEquals(argument, null)) 31 | { 32 | throw new ArgumentNullException(parameterName, parameterName + " is null."); 33 | } 34 | return argument; 35 | } 36 | 37 | public static string NotNullNotEmpty(string text, string parameterName) 38 | { 39 | if (text == null) 40 | { 41 | throw new ArgumentNullException(parameterName, parameterName + " is null."); 42 | } 43 | if (string.IsNullOrEmpty(text)) 44 | { 45 | throw new ArgumentOutOfRangeException(parameterName, parameterName + " is empty."); 46 | } 47 | return text; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/DebugHelper.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Diagnostics; 4 | 5 | namespace Theraot.Core 6 | { 7 | [DebuggerNonUserCode] 8 | public static class DebugHelper 9 | { 10 | [Conditional("DEBUG")] 11 | public static void Break() 12 | { 13 | Debugger.Launch(); 14 | Debugger.Break(); 15 | } 16 | } 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/DelegateEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | 7 | namespace Theraot.Core 8 | { 9 | public sealed class DelegateEqualityComparer : IEqualityComparer 10 | { 11 | private static readonly DelegateEqualityComparer _default = new DelegateEqualityComparer(); 12 | 13 | private DelegateEqualityComparer() 14 | { 15 | // Empty 16 | } 17 | 18 | public static DelegateEqualityComparer Default 19 | { 20 | get { return _default; } 21 | } 22 | 23 | public bool Equals(Delegate x, Delegate y) 24 | { 25 | return CompareInternal(x, y); 26 | } 27 | 28 | public int GetHashCode(Delegate obj) 29 | { 30 | // obj can be null 31 | return ReferenceEquals(obj, null) ? 0 : ReferenceEquals(obj.Target, null) ? obj.GetMethodInfo().GetHashCode() : obj.GetMethodInfo().GetHashCode() ^ obj.Target.GetHashCode(); 32 | } 33 | 34 | private static bool CompareInternal(Delegate x, Delegate y) 35 | { 36 | return ReferenceEquals(x, null) ? ReferenceEquals(y, null) : !ReferenceEquals(y, null) && ReferenceEquals(x.Target, y.Target) && x.GetMethodInfo() == y.GetMethodInfo(); 37 | } 38 | } 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/EnvironmentHelper.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workaround 2 | 3 | using System; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | public static class EnvironmentHelper 8 | { 9 | // Every request to Environment.ProcessorCount will result in an external call 10 | // EnvironmentHelper.ProcessorCount is a cached result. 11 | // TODO: can this value change for a running process / without reboot? 12 | private static readonly int _processorCount = Environment.ProcessorCount; 13 | 14 | public static bool Is64BitProcess 15 | { 16 | get 17 | { 18 | // "The value of this property is 4 in a 32-bit process, and 8 in a 64-bit process." -- MSDN 19 | return IntPtr.Size == 8; 20 | } 21 | } 22 | 23 | public static bool IsSingleCPU 24 | { 25 | get { return _processorCount == 1; } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/ICloneable.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Core 6 | { 7 | #if NETCF 8 | 9 | public interface ICloneable 10 | #if !NETCOREAPP1_1 11 | : ICloneable 12 | #endif 13 | #else 14 | 15 | public interface ICloneable 16 | #if !NETCOREAPP1_1 17 | : ICloneable 18 | #endif 19 | #endif 20 | { 21 | #if !NETCOREAPP1_1 22 | new 23 | #endif 24 | 25 | T Clone(); 26 | } 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/ICloner.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Core 4 | { 5 | public interface ICloner 6 | { 7 | T Clone(T target); 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/NewEventHandler.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Core 4 | { 5 | #if NETCF 6 | 7 | public delegate void NewEventHandler(object sender, TEventArgs value); 8 | 9 | #else 10 | 11 | public delegate void NewEventHandler(object sender, TEventArgs value); 12 | 13 | #endif 14 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/NumericHelper.checked.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | #if FAT 4 | 5 | namespace Theraot.Core 6 | { 7 | public static partial class NumericHelper 8 | { 9 | public static int CheckedDecrement(this int value) 10 | { 11 | checked 12 | { 13 | value--; 14 | return value; 15 | } 16 | } 17 | 18 | public static short CheckedDecrement(this short value) 19 | { 20 | checked 21 | { 22 | value--; 23 | return value; 24 | } 25 | } 26 | 27 | public static long CheckedDecrement(this long value) 28 | { 29 | checked 30 | { 31 | value--; 32 | return value; 33 | } 34 | } 35 | 36 | public static int CheckedIncrement(this int value) 37 | { 38 | checked 39 | { 40 | value++; 41 | return value; 42 | } 43 | } 44 | 45 | public static short CheckedIncrement(this short value) 46 | { 47 | checked 48 | { 49 | value++; 50 | return value; 51 | } 52 | } 53 | 54 | public static long CheckedIncrement(this long value) 55 | { 56 | checked 57 | { 58 | value++; 59 | return value; 60 | } 61 | } 62 | } 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/NumericHelper.checks.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | public static partial class NumericHelper 8 | { 9 | public static bool AreBinaryEquals(double left, double right) 10 | { 11 | var leftBits = unchecked((ulong)BitConverter.DoubleToInt64Bits(left)); 12 | var rightBits = unchecked((ulong)BitConverter.DoubleToInt64Bits(right)); 13 | return leftBits == rightBits; 14 | } 15 | 16 | public static bool AreBinaryEquals(float left, float right) 17 | { 18 | var leftBits = unchecked(SingleAsUInt32(left)); 19 | var rightBits = unchecked(SingleAsUInt32(right)); 20 | return leftBits == rightBits; 21 | } 22 | 23 | public static bool IsOne(double value) 24 | { 25 | var test = unchecked((ulong)BitConverter.DoubleToInt64Bits(value)); 26 | return test == 0x3ff0000000000000ul; 27 | } 28 | 29 | public static bool IsOne(float value) 30 | { 31 | var test = unchecked(SingleAsUInt32(value)); 32 | return test == 0x3f800000; 33 | } 34 | 35 | public static bool IsZero(double value) 36 | { 37 | var test = unchecked((ulong)BitConverter.DoubleToInt64Bits(value)); 38 | return test == 0x0000000000000000ul || test == 0x8000000000000000ul; 39 | } 40 | 41 | public static bool IsZero(float value) 42 | { 43 | var test = unchecked(SingleAsUInt32(value)); 44 | return test == 0x00000000 || test == 0x80000000; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/NumericHelper.unchecked.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | #if FAT 4 | 5 | namespace Theraot.Core 6 | { 7 | public static partial class NumericHelper 8 | { 9 | public static int UncheckedDecrement(this int value) 10 | { 11 | unchecked 12 | { 13 | value--; 14 | return value; 15 | } 16 | } 17 | 18 | public static short UncheckedDecrement(this short value) 19 | { 20 | unchecked 21 | { 22 | value--; 23 | return value; 24 | } 25 | } 26 | 27 | public static long UncheckedDecrement(this long value) 28 | { 29 | unchecked 30 | { 31 | value--; 32 | return value; 33 | } 34 | } 35 | 36 | public static int UncheckedIncrement(this int value) 37 | { 38 | unchecked 39 | { 40 | value++; 41 | return value; 42 | } 43 | } 44 | 45 | public static short UncheckedIncrement(this short value) 46 | { 47 | unchecked 48 | { 49 | value++; 50 | return value; 51 | } 52 | } 53 | 54 | public static long UncheckedIncrement(this long value) 55 | { 56 | unchecked 57 | { 58 | value++; 59 | return value; 60 | } 61 | } 62 | } 63 | } 64 | 65 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/Reference.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Reflection; 4 | 5 | namespace Theraot.Core 6 | { 7 | public static class Reference 8 | { 9 | public static bool Equals(T objA, T objB) 10 | { 11 | var info = typeof(T).GetTypeInfo(); 12 | return info.IsValueType ? false : ReferenceEquals(objA, objB); 13 | } 14 | 15 | public static bool IsNull(T objA) 16 | { 17 | var info = typeof(T).GetTypeInfo(); 18 | return info.IsValueType ? false : ReferenceEquals(objA, null); 19 | } 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Core/ReferenceEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET30 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | public static class ReferenceEqualityComparer 8 | { 9 | private static readonly ReferenceEqualityComparer _default = ReferenceEqualityComparer.Instance; 10 | 11 | public static ReferenceEqualityComparer Default 12 | { 13 | get { return _default; } 14 | } 15 | } 16 | 17 | public class ReferenceEqualityComparer : IEqualityComparer 18 | { 19 | private static readonly ReferenceEqualityComparer _instance = new ReferenceEqualityComparer(); 20 | 21 | private ReferenceEqualityComparer() 22 | { 23 | // Empty 24 | } 25 | 26 | public static ReferenceEqualityComparer Instance 27 | { 28 | get { return _instance; } 29 | } 30 | 31 | public int GetHashCode(T obj) 32 | { 33 | return obj.GetHashCode(); 34 | } 35 | 36 | bool IEqualityComparer.Equals(T x, T y) 37 | { 38 | return ReferenceEquals(x, y); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/StopwatchExtensions.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workaround 2 | 3 | using System.Diagnostics; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | public static class StopwatchExtensions 8 | { 9 | public static void Restart(this Stopwatch stopwatch) 10 | { 11 | stopwatch.Reset(); 12 | stopwatch.Start(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/StringBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workadound 2 | 3 | using System.Text; 4 | 5 | namespace Theraot.Core.Theraot.Core 6 | { 7 | public static class StringBuilderExtensions 8 | { 9 | public static void Clear(this StringBuilder stringBuilder) 10 | { 11 | stringBuilder.Length = 0; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Core/Theraot/Core/TracertNode.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System.Net; 4 | using System.Net.NetworkInformation; 5 | 6 | namespace Theraot.Core 7 | { 8 | [System.Diagnostics.DebuggerNonUserCode] 9 | public class TracertNode 10 | { 11 | private readonly IPAddress _address; 12 | private readonly IPStatus _status; 13 | private readonly int _ttl; 14 | 15 | internal TracertNode(IPAddress address, IPStatus status, int Ttl) 16 | { 17 | _address = address; 18 | _status = status; 19 | _ttl = Ttl; 20 | } 21 | 22 | public int Ttl 23 | { 24 | get { return _ttl; } 25 | } 26 | 27 | internal IPAddress Address 28 | { 29 | get { return _address; } 30 | } 31 | 32 | internal IPStatus Status 33 | { 34 | get { return _status; } 35 | } 36 | } 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/CriticalDisposable.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | using Theraot.Core; 6 | 7 | namespace Theraot.Threading 8 | { 9 | [System.Diagnostics.DebuggerNonUserCode] 10 | public sealed partial class CriticalDisposable 11 | #if !NETCOREAPP1_1 12 | : System.Runtime.ConstrainedExecution.CriticalFinalizerObject 13 | #endif 14 | { 15 | private Action _release; 16 | 17 | private CriticalDisposable(Action release) 18 | { 19 | if (release == null) 20 | { 21 | throw new ArgumentNullException("release"); 22 | } 23 | _release = release; 24 | } 25 | 26 | public static CriticalDisposable Create(Action release) 27 | { 28 | return new CriticalDisposable(release); 29 | } 30 | 31 | public bool Dispose(Func condition) 32 | { 33 | if (condition == null) 34 | { 35 | throw new ArgumentNullException("condition"); 36 | } 37 | Func temp = condition; 38 | return DisposedConditional 39 | ( 40 | FuncHelper.GetFallacyFunc(), 41 | () => 42 | { 43 | if (condition.Invoke()) 44 | { 45 | Dispose(); 46 | return true; 47 | } 48 | else 49 | { 50 | return false; 51 | } 52 | } 53 | ); 54 | } 55 | } 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Disposable.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | using Theraot.Core.Theraot.Core; 6 | 7 | namespace Theraot.Core.Theraot.Threading 8 | { 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | public sealed partial class Disposable 11 | { 12 | private Action _release; 13 | 14 | private Disposable(Action release) 15 | { 16 | if (release == null) 17 | { 18 | throw new ArgumentNullException("release"); 19 | } 20 | _release = release; 21 | } 22 | 23 | public static Disposable Create() 24 | { 25 | return new Disposable(ActionHelper.GetNoopAction()); 26 | } 27 | 28 | public static Disposable Create(Action release) 29 | { 30 | return new Disposable(release); 31 | } 32 | 33 | public bool Dispose(Func condition) 34 | { 35 | if (condition == null) 36 | { 37 | throw new ArgumentNullException("condition"); 38 | } 39 | return DisposedConditional 40 | ( 41 | FuncHelper.GetFallacyFunc(), 42 | () => 43 | { 44 | if (condition.Invoke()) 45 | { 46 | Dispose(); 47 | return true; 48 | } 49 | else 50 | { 51 | return false; 52 | } 53 | } 54 | ); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Disposable.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Threading 4 | { 5 | public sealed partial class Disposable : IExtendedDisposable 6 | { 7 | //Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/GCMonitor.internal.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workaround 2 | 3 | using System; 4 | using System.Threading; 5 | using Theraot.Core.System.Threading; 6 | using Theraot.Core.Theraot.Collections.ThreadSafe; 7 | 8 | namespace Theraot.Core.Theraot.Threading 9 | { 10 | public static partial class GCMonitor 11 | { 12 | private static class Internal 13 | { 14 | private static readonly WeakDelegateCollection _collectedEventHandlers; 15 | private static readonly WaitCallback _work; 16 | 17 | static Internal() 18 | { 19 | _work = _ => RaiseCollected(); 20 | _collectedEventHandlers = new WeakDelegateCollection(false, false, _maxProbingHint); 21 | } 22 | 23 | public static WeakDelegateCollection CollectedEventHandlers 24 | { 25 | get { return _collectedEventHandlers; } 26 | } 27 | 28 | public static void Invoke() 29 | { 30 | ThreadPool.QueueUserWorkItem(_work); 31 | } 32 | 33 | private static void RaiseCollected() 34 | { 35 | var check = Volatile.Read(ref _status); 36 | if (check == _statusReady) 37 | { 38 | try 39 | { 40 | _collectedEventHandlers.RemoveDeadItems(); 41 | _collectedEventHandlers.Invoke(null, new EventArgs()); 42 | } 43 | catch (Exception exception) 44 | { 45 | // Catch'em all 46 | GC.KeepAlive(exception); 47 | } 48 | Volatile.Write(ref _status, _statusReady); 49 | } 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/IExtendedDisposable.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Threading 6 | { 7 | public interface IExtendedDisposable : IDisposable 8 | { 9 | bool IsDisposed { get; } 10 | 11 | void DisposedConditional(Action whenDisposed, Action whenNotDisposed); 12 | 13 | TReturn DisposedConditional(Func whenDisposed, Func whenNotDisposed); 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/IReadWriteLock.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Threading 6 | { 7 | internal interface IReadWriteLock : IDisposable 8 | { 9 | bool HasReader { get; } 10 | 11 | bool HasWriter { get; } 12 | 13 | bool IsCurrentThreadReader { get; } 14 | 15 | bool IsCurrentThreadWriter { get; } 16 | 17 | IDisposable EnterRead(); 18 | 19 | IDisposable EnterWrite(); 20 | 21 | bool TryEnterRead(out IDisposable engagement); 22 | 23 | bool TryEnterWrite(out IDisposable engagement); 24 | } 25 | } 26 | 27 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/IThreadLocal.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (ThreadLocal) 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Core.Theraot.Threading 7 | { 8 | internal interface IThreadLocal : IDisposable 9 | { 10 | bool IsValueCreated { get; } 11 | 12 | T Value { get; set; } 13 | 14 | T ValueForDebugDisplay { get; } 15 | 16 | IList Values { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/DefaultNeedle.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Theraot.Threading.Needles 7 | { 8 | [System.Diagnostics.DebuggerNonUserCode] 9 | public sealed class DefaultNeedle : IReadOnlyNeedle 10 | { 11 | private static readonly DefaultNeedle _instance = new DefaultNeedle(); 12 | 13 | private DefaultNeedle() 14 | { 15 | //Empty 16 | } 17 | 18 | public static DefaultNeedle Instance 19 | { 20 | get { return _instance; } 21 | } 22 | 23 | bool IReadOnlyNeedle.IsAlive 24 | { 25 | get { return true; } 26 | } 27 | 28 | public T Value 29 | { 30 | get { return default(T); } 31 | } 32 | 33 | public static explicit operator T(DefaultNeedle needle) 34 | { 35 | if (needle == null) 36 | { 37 | throw new ArgumentNullException("needle"); 38 | } 39 | return needle.Value; 40 | } 41 | 42 | public static bool operator !=(DefaultNeedle left, DefaultNeedle right) 43 | { 44 | return false; 45 | } 46 | 47 | public static bool operator ==(DefaultNeedle left, DefaultNeedle right) 48 | { 49 | return true; 50 | } 51 | 52 | public override bool Equals(object obj) 53 | { 54 | return obj is DefaultNeedle; 55 | } 56 | 57 | public override int GetHashCode() 58 | { 59 | return EqualityComparer.Default.GetHashCode(default(T)); 60 | } 61 | 62 | public override string ToString() 63 | { 64 | return Value.ToString(); 65 | } 66 | } 67 | } 68 | 69 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/FutureDisposableNeedle.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Threading; 5 | 6 | namespace Theraot.Threading.Needles 7 | { 8 | [Serializable] 9 | [System.Diagnostics.DebuggerNonUserCode] 10 | public class FutureDisposableNeedle : LazyDisposableNeedle 11 | where T : IDisposable 12 | { 13 | private int _status; 14 | 15 | public FutureDisposableNeedle(Func valueFactory) 16 | : base(valueFactory) 17 | { 18 | Schedule(); 19 | } 20 | 21 | public FutureDisposableNeedle(Func valueFactory, bool schedule) 22 | : base(valueFactory) 23 | { 24 | if (schedule) 25 | { 26 | Schedule(); 27 | } 28 | } 29 | 30 | public override void Initialize() 31 | { 32 | if (Volatile.Read(ref _status) == 1) 33 | { 34 | base.Wait(); 35 | } 36 | else 37 | { 38 | base.Initialize(); 39 | } 40 | } 41 | 42 | public bool Schedule() 43 | { 44 | if (Interlocked.CompareExchange(ref _status, 1, 0) != 0) 45 | { 46 | return false; 47 | } 48 | var waitCallback = new WaitCallback(_ => Initialize()); 49 | ThreadPool.QueueUserWorkItem(waitCallback); 50 | return true; 51 | } 52 | 53 | public override void Wait() 54 | { 55 | Initialize(); 56 | } 57 | } 58 | } 59 | 60 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/ICacheNeedle.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Threading.Needles 4 | { 5 | public interface ICacheNeedle : INeedle, IPromise 6 | { 7 | bool TryGetValue(out T value); 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/INeedle.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Threading.Needles 4 | { 5 | public interface INeedle : IReadOnlyNeedle 6 | { 7 | new T Value { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/IPromise.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | 5 | namespace Theraot.Core.Theraot.Threading.Needles 6 | { 7 | public interface IPromise 8 | { 9 | Exception Exception { get; } 10 | 11 | bool IsCanceled { get; } 12 | 13 | bool IsCompleted { get; } 14 | 15 | bool IsFaulted { get; } 16 | } 17 | 18 | #if NETCF 19 | 20 | public interface IPromise : IPromise, IReadOnlyNeedle 21 | #else 22 | 23 | public interface IPromise : IPromise, IReadOnlyNeedle 24 | #endif 25 | { 26 | // Empty 27 | } 28 | 29 | public interface IWaitablePromise : IPromise 30 | { 31 | void Wait(); 32 | } 33 | 34 | #if NETCF 35 | 36 | public interface IWaitablePromise : IPromise, IWaitablePromise 37 | #else 38 | 39 | public interface IWaitablePromise : IPromise, IWaitablePromise 40 | #endif 41 | { 42 | // Empty 43 | } 44 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/IReadOnlyNeedle.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Threading.Needles 4 | { 5 | #if NETCF 6 | 7 | public interface IReadOnlyNeedle 8 | #else 9 | 10 | public interface IReadOnlyNeedle 11 | #endif 12 | { 13 | bool IsAlive { get; } 14 | 15 | T Value { get; } 16 | } 17 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/IRecyclableNeedle.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | namespace Theraot.Core.Theraot.Threading.Needles 4 | { 5 | public interface IRecyclableNeedle : INeedle 6 | { 7 | void Free(); 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/LockableContext.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | using System.Threading; 5 | 6 | namespace Theraot.Threading.Needles 7 | { 8 | public sealed class LockableContext 9 | { 10 | internal readonly LockContext Context; 11 | private readonly StructNeedle> _slots; 12 | 13 | public LockableContext(int capacity) 14 | { 15 | Context = new LockContext(capacity); 16 | _slots.Value = new TrackingThreadLocal(() => null); 17 | } 18 | 19 | internal LockableSlot Slot 20 | { 21 | get { return _slots.Value.Value; } 22 | 23 | set { _slots.Value.Value = value; } 24 | } 25 | 26 | public IDisposable Enter() 27 | { 28 | return new LockableSlot(this); 29 | } 30 | 31 | internal bool TryGetSlot(out LockableSlot slot) 32 | { 33 | return _slots.Value.TryGetValue(Thread.CurrentThread, out slot) && slot != null; 34 | } 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/NotNull.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Threading.Needles 6 | { 7 | public sealed class NotNull : Needle 8 | { 9 | public NotNull(T target) 10 | : base(target) 11 | { 12 | if (ReferenceEquals(target, null)) 13 | { 14 | throw new ArgumentNullException("target", "NotNull cannot have a null value."); 15 | } 16 | } 17 | 18 | public override T Value 19 | { 20 | get { return base.Value; } 21 | 22 | set 23 | { 24 | if (ReferenceEquals(value, null)) 25 | { 26 | throw new ArgumentNullException("value", "NotNull cannot have a null value."); 27 | } 28 | else 29 | { 30 | SetTargetValue(value); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/ReadOnlyPromise.cs: -------------------------------------------------------------------------------- 1 | // Needed for Workaround 2 | 3 | using System; 4 | using Theraot.Core.System; 5 | 6 | namespace Theraot.Core.Theraot.Threading.Needles 7 | { 8 | [Serializable] 9 | [global::System.Diagnostics.DebuggerNonUserCode] 10 | public class ReadOnlyPromise : IWaitablePromise 11 | { 12 | private readonly IPromise _promised; 13 | private readonly Action _wait; 14 | 15 | public ReadOnlyPromise(IPromise promised, bool allowWait) 16 | { 17 | _promised = promised; 18 | if (allowWait) 19 | { 20 | var promise = _promised as IWaitablePromise; 21 | if (promise != null) 22 | { 23 | _wait = promise.Wait; 24 | } 25 | else 26 | { 27 | _wait = () => ThreadingHelper.SpinWaitUntil(() => _promised.IsCompleted); 28 | } 29 | } 30 | else 31 | { 32 | _wait = () => 33 | { 34 | throw new InvalidOperationException(); 35 | }; 36 | } 37 | } 38 | 39 | public Exception Exception 40 | { 41 | get { return _promised.Exception; } 42 | } 43 | 44 | public bool IsCanceled 45 | { 46 | get { return _promised.IsCanceled; } 47 | } 48 | 49 | public bool IsCompleted 50 | { 51 | get { return _promised.IsCompleted; } 52 | } 53 | 54 | public bool IsFaulted 55 | { 56 | get { return _promised.IsFaulted; } 57 | } 58 | 59 | public override int GetHashCode() 60 | { 61 | return _promised.GetHashCode(); 62 | } 63 | 64 | public override string ToString() 65 | { 66 | return string.Format("{{Promise: {0}}}", _promised); 67 | } 68 | 69 | public void Wait() 70 | { 71 | _wait(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/Transact.IResource.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Threading.Needles 4 | { 5 | public sealed partial class Transact 6 | { 7 | private interface IResource 8 | { 9 | bool Capture(); 10 | 11 | bool CheckCapture(); 12 | 13 | bool CheckValue(); 14 | 15 | bool Commit(); 16 | 17 | void Release(); 18 | } 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/Transact.disposable.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Threading.Needles 6 | { 7 | public sealed partial class Transact : IDisposable 8 | { 9 | private int _status; 10 | 11 | [System.Diagnostics.DebuggerNonUserCode] 12 | ~Transact() 13 | { 14 | try 15 | { 16 | // Empty 17 | } 18 | finally 19 | { 20 | try 21 | { 22 | Dispose(false); 23 | } 24 | catch (Exception exception) 25 | { 26 | // Fields may be partially collected. 27 | GC.KeepAlive(exception); 28 | } 29 | } 30 | } 31 | 32 | [System.Diagnostics.DebuggerNonUserCode] 33 | public void Dispose() 34 | { 35 | Dispose(true); 36 | GC.SuppressFinalize(this); 37 | } 38 | 39 | [System.Diagnostics.DebuggerNonUserCode] 40 | private void Dispose(bool disposeManagedResources) 41 | { 42 | if (TakeDisposalExecution()) 43 | { 44 | if (disposeManagedResources) 45 | { 46 | Release(true); 47 | } 48 | } 49 | } 50 | 51 | private bool TakeDisposalExecution() 52 | { 53 | return _status != -1 && ThreadingHelper.SpinWaitSetUnless(ref _status, -1, 0, -1); 54 | } 55 | } 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/Needles/WeakNeedle.extended.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Threading.Needles 4 | { 5 | public partial class WeakNeedle : IExtendedDisposable 6 | { 7 | // Empty 8 | } 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/ReadWriteLock.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | using System; 4 | 5 | namespace Theraot.Threading 6 | { 7 | public sealed class ReadWriteLock : IReadWriteLock 8 | { 9 | private readonly IReadWriteLock _wrapped; 10 | 11 | public ReadWriteLock() 12 | { 13 | _wrapped = new NoReentrantReadWriteLock(); 14 | } 15 | 16 | public ReadWriteLock(bool reentrant) 17 | { 18 | _wrapped = (IReadWriteLock)(reentrant ? (object)new ReentrantReadWriteLock() : new NoReentrantReadWriteLock()); 19 | } 20 | 21 | public bool HasReader 22 | { 23 | get { return _wrapped.HasReader; } 24 | } 25 | 26 | public bool HasWriter 27 | { 28 | get { return _wrapped.HasWriter; } 29 | } 30 | 31 | public bool IsCurrentThreadReader 32 | { 33 | get { return _wrapped.IsCurrentThreadReader; } 34 | } 35 | 36 | public bool IsCurrentThreadWriter 37 | { 38 | get { return _wrapped.IsCurrentThreadWriter; } 39 | } 40 | 41 | public void Dispose() 42 | { 43 | _wrapped.Dispose(); 44 | } 45 | 46 | public IDisposable EnterRead() 47 | { 48 | return _wrapped.EnterRead(); 49 | } 50 | 51 | public IDisposable EnterWrite() 52 | { 53 | return _wrapped.EnterWrite(); 54 | } 55 | 56 | public bool TryEnterRead(out IDisposable engagement) 57 | { 58 | return _wrapped.TryEnterRead(out engagement); 59 | } 60 | 61 | public bool TryEnterWrite(out IDisposable engagement) 62 | { 63 | return _wrapped.TryEnterWrite(out engagement); 64 | } 65 | } 66 | } 67 | 68 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/RuntimeUniqueIdProdiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Threading; 4 | 5 | namespace Theraot.Core.Theraot.Threading 6 | { 7 | [global::System.Diagnostics.DebuggerNonUserCode] 8 | public static class RuntimeUniqueIdProdiver 9 | { 10 | private static int _lastId = int.MinValue; 11 | 12 | public static UniqueId GetNextId() 13 | { 14 | return new UniqueId(Interlocked.Increment(ref _lastId)); 15 | } 16 | 17 | public struct UniqueId : IEquatable 18 | { 19 | private readonly int _id; 20 | 21 | internal UniqueId(int id) 22 | { 23 | _id = id; 24 | } 25 | 26 | public static bool operator !=(UniqueId x, UniqueId y) 27 | { 28 | return !x.Equals(y); 29 | } 30 | 31 | public static bool operator ==(UniqueId x, UniqueId y) 32 | { 33 | return x.Equals(y); 34 | } 35 | 36 | public bool Equals(UniqueId other) 37 | { 38 | return other._id.Equals(_id); 39 | } 40 | 41 | public override bool Equals(object obj) 42 | { 43 | if (obj is UniqueId) 44 | { 45 | return Equals((UniqueId)obj); 46 | } 47 | return false; 48 | } 49 | 50 | public override int GetHashCode() 51 | { 52 | return _id; 53 | } 54 | 55 | public override string ToString() 56 | { 57 | return _id.ToString(CultureInfo.InvariantCulture); 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/ThreadLocalHelper.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (ThreadLocal) 2 | 3 | using System; 4 | using Theraot.Core.Theraot.Threading.Needles; 5 | 6 | namespace Theraot.Core.Theraot.Threading 7 | { 8 | internal static class ThreadLocalHelper 9 | { 10 | private static readonly Exception _recursionGuardException; 11 | 12 | static ThreadLocalHelper() 13 | { 14 | _recursionGuardException = GetInvalidOperationException(); 15 | } 16 | 17 | public static Exception RecursionGuardException 18 | { 19 | get { return _recursionGuardException; } 20 | } 21 | 22 | private static InvalidOperationException GetInvalidOperationException() 23 | { 24 | return new InvalidOperationException("Recursion"); 25 | } 26 | } 27 | 28 | internal static class ThreadLocalHelper 29 | { 30 | private static readonly INeedle _recursionGuardNeedle = new ExceptionStructNeedle(ThreadLocalHelper.RecursionGuardException); 31 | 32 | public static INeedle RecursionGuardNeedle 33 | { 34 | get { return _recursionGuardNeedle; } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/ThreadingHelper.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET40 2 | 3 | using System; 4 | using System.Threading; 5 | 6 | namespace Theraot.Core.Theraot.Threading 7 | { 8 | [global::System.Diagnostics.DebuggerNonUserCode] 9 | public static partial class ThreadingHelper 10 | { 11 | internal const int _sleepCountHint = 10; 12 | private const int _maxTime = 200; 13 | 14 | public static void MemoryBarrier() 15 | { 16 | #if NETCOREAPP1_1 17 | Interlocked.MemoryBarrier(); 18 | #else 19 | Thread.MemoryBarrier(); 20 | #endif 21 | } 22 | 23 | internal static long Milliseconds(long ticks) 24 | { 25 | return ticks / TimeSpan.TicksPerMillisecond; 26 | } 27 | 28 | internal static long TicksNow() 29 | { 30 | return DateTime.Now.Ticks; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Core/Theraot/Threading/ThreadingHelper.extra.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Threading 4 | { 5 | public static partial class ThreadingHelper 6 | { 7 | // Leaked 8 | private static readonly TrackingThreadLocal _threadRuntimeUniqueId = new TrackingThreadLocal(RuntimeUniqueIdProdiver.GetNextId); 9 | 10 | public static bool HasThreadUniqueId 11 | { 12 | get { return _threadRuntimeUniqueId.IsValueCreated; } 13 | } 14 | 15 | public static RuntimeUniqueIdProdiver.UniqueId ThreadUniqueId 16 | { 17 | get { return _threadRuntimeUniqueId.Value; } 18 | } 19 | } 20 | } 21 | 22 | #endif -------------------------------------------------------------------------------- /Core/Theraot/Threading/VersionProvider.cs: -------------------------------------------------------------------------------- 1 | #if FAT 2 | 3 | namespace Theraot.Threading 4 | { 5 | /// 6 | /// Provides a mechanism to get an object that represents a version of a mutable resource 7 | /// 8 | public sealed partial class VersionProvider 9 | { 10 | private Target _target; 11 | private Advancer _tryAdvance; 12 | 13 | /// 14 | /// Creates a new VersionProvider 15 | /// 16 | public VersionProvider() 17 | { 18 | _target = new Target(out _tryAdvance); 19 | } 20 | 21 | internal delegate bool Advancer(out long number); 22 | 23 | /// 24 | /// Advances the current up to date version 25 | /// 26 | public void Advance() 27 | { 28 | long number; 29 | if (!_tryAdvance.Invoke(out number)) 30 | { 31 | _target = new Target(out _tryAdvance); 32 | } 33 | } 34 | 35 | /// 36 | /// Advances the current up to date version and returns a VersionToken for the new version 37 | /// 38 | /// A VersionToken representing the advanced version 39 | public VersionToken AdvanceNewToken() 40 | { 41 | long number; 42 | if (!_tryAdvance.Invoke(out number)) 43 | { 44 | _target = new Target(out _tryAdvance); 45 | } 46 | return new VersionToken(this, _target, number); 47 | } 48 | 49 | /// 50 | /// Creates a new VersionToken, it should be considered to be out of date 51 | /// 52 | /// A new VersionToken 53 | public VersionToken NewToken() 54 | { 55 | return new VersionToken(this); 56 | } 57 | } 58 | } 59 | 60 | #endif -------------------------------------------------------------------------------- /Core/Theraot/VoidStruct.cs: -------------------------------------------------------------------------------- 1 | // Needed for NET35 (TASK) 2 | 3 | namespace Theraot.Core.Theraot 4 | { 5 | public struct VoidStruct 6 | { 7 | // Empty 8 | } 9 | } -------------------------------------------------------------------------------- /Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Image/Img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Difficulty-in-naming/DreamSerialize/c50f2916149a206eebbbfb3bb32f6fd2cfef3ef0/Image/Img.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DreamSerialize 2 | fast Serialize and Deserialize 3 | Thanks for https://github.com/theraot/Theraot to support expression in .net2.0 4 | 5 | Warning!!! 6 | 7 | please DO NOT use this build for your project!! 8 | Because IOS Can not pass 9 | ![index](https://github.com/pk27602017/DreamSerialize/raw/master/Image/Img.png) 10 | 11 | 关于IOS的支持可以了解一下这个库[csharp-eval]https://github.com/deniszykov/csharp-eval-unity3d 12 | -------------------------------------------------------------------------------- /Unity-Serialize/CustomSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DreamSerialize.New; 4 | 5 | namespace DreamSerialize.Utility 6 | { 7 | /// 8 | /// 自定义序列化类型 9 | /// 10 | public class CustomSerializer 11 | { 12 | internal static Dictionary Custom = new Dictionary(); 13 | 14 | public static void Add(Type type) 15 | { 16 | if (type != null) 17 | { 18 | var @base = type.BaseType; 19 | if (@base.GetGenericTypeDefinition() != typeof(SupportSerializable<>)) 20 | throw new Exception("自定义序列化基类必须继承自SupportSerializable,如 public class GameObjectSerializer:SupportSerializable"); 21 | var genericType = @base.GetGenericArguments()[0]; 22 | if (!Custom.ContainsKey(genericType)) 23 | Custom.Add(genericType, type); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Unity-Serialize/New/Attributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DreamSerialize.New 4 | { 5 | [AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct)] 6 | public class SerializerContract : Attribute 7 | { 8 | } 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public class Index : Attribute 11 | { 12 | public int index; 13 | public bool SupportPrivate = false; 14 | public Index(int i) 15 | { 16 | index = i; 17 | } 18 | 19 | public Index(int i, bool supportPrivate) 20 | { 21 | index = i; 22 | SupportPrivate = supportPrivate; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Unity-Serialize/New/BitStream.cs: -------------------------------------------------------------------------------- 1 | namespace DreamSerialize.New 2 | { 3 | public class BitStream 4 | { 5 | public byte[] Bytes; 6 | public int Offset; 7 | public int Head = 0; 8 | public BitStream(byte[] bytes, int offset) 9 | { 10 | Bytes = bytes; 11 | Offset = offset; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Unity-Serialize/New/Interface.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace DreamSerialize.New 3 | { 4 | public interface ISerializable 5 | { 6 | int Serialize(ref byte[] bytes,ref int offset); 7 | T Deserialize(byte[] bytes,ref int offset); 8 | } 9 | 10 | public abstract class SupportSerializable 11 | { 12 | 13 | public static SupportSerializable Default; 14 | public SupportSerializable() 15 | { 16 | Default = this; 17 | } 18 | 19 | //public virtual int Serialize(ref byte[] bytes, ref int offset, T value); 20 | //public abstract T Deserialize(byte[] bytes, ref int offset); 21 | 22 | public abstract BitStream Serialize(BitStream stream, T value); 23 | public abstract T Deserialize(BitStream stream); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Unity-Serialize/New/Serializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Cryptography; 3 | using DreamSerialize.WriterHelper; 4 | 5 | namespace DreamSerialize.New 6 | { 7 | public static class DreamSerializer 8 | { 9 | public static byte[] Serializer(T obj) 10 | { 11 | var bit = new BitStream(new byte[64], 0); 12 | DynamicWriter.Write(bit,obj); 13 | Array.Resize(ref bit.Bytes,bit.Offset); 14 | return bit.Bytes; 15 | } 16 | 17 | public static T Deserializer(byte[] bytes) where T : new() 18 | { 19 | var bit = new BitStream(bytes,0); 20 | return DynamicWriter.Read(bit); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Unity-Serialize/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Serialize")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Serialize")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("7c05896f-20c7-4345-81e8-30ddd28e903b")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Unity-Serialize/Utility/CustomSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DreamSerialize.New; 4 | 5 | namespace DreamSerialize.Utility 6 | { 7 | /// 8 | /// 自定义序列化类型 9 | /// 10 | public class CustomSerializer 11 | { 12 | internal static Dictionary Custom = new Dictionary(); 13 | 14 | public static void Add(Type type) 15 | { 16 | if (type != null) 17 | { 18 | var @base = type.BaseType; 19 | if (@base.GetGenericTypeDefinition() != typeof(SupportSerializable<>)) 20 | throw new Exception("自定义序列化基类必须继承自SupportSerializable,如 public class GameObjectSerializer:SupportSerializable"); 21 | var genericType = @base.GetGenericArguments()[0]; 22 | if (!Custom.ContainsKey(genericType)) 23 | Custom.Add(genericType, type); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Unity-Serialize/Utility/IType.cs: -------------------------------------------------------------------------------- 1 | namespace DreamSerialize.Utility 2 | { 3 | public enum IType :uint 4 | { 5 | Variable32 = 0, 6 | Variable64 = 1, 7 | Fixed32 = 2, 8 | Fixed64 = 3, 9 | Dynamic = 4, 10 | EndGroup = 5, 11 | } 12 | } -------------------------------------------------------------------------------- /Unity-Serialize/WriterHelper/SpecialWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DreamSerialize.New; 3 | 4 | namespace DreamSerialize.WriterHelper 5 | { 6 | public class WriteForType : SupportSerializable 7 | { 8 | public override BitStream Serialize(BitStream stream, Type value) 9 | { 10 | var assembly = value.Assembly.FullName; 11 | BinaryWriter.Write(stream,value.FullName + "," + assembly.Substring(0,assembly.IndexOf(","))); 12 | return stream; 13 | } 14 | 15 | public override Type Deserialize(BitStream stream) 16 | { 17 | return Type.GetType(BinaryReader.ReadString(stream)); 18 | } 19 | } 20 | } 21 | --------------------------------------------------------------------------------