Added ListSegment class which is analogous to StringSegment and ArraySegment, but for IList<T>

git-svn-id: file:///srv/devel/repo-conversion/nusu@336 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2022-11-02 18:05:04 +00:00
parent 207a17712e
commit c7dd57f59f
5 changed files with 907 additions and 397 deletions

View File

@ -1,346 +1,348 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{00567408-4F44-4C00-866E-B04A99E482F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Nuclex.Support</RootNamespace>
<AssemblyName>Nuclex.Support</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net-4.0\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Debug\Nuclex.Support.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net-4.0\Release\</OutputPath>
<DefineConstants>TRACE;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Release\Nuclex.Support.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\Foundation.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="NMock.StrongNamed">
<HintPath>..\References\nmock\net-4.0\NMock.StrongNamed.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\nunit\net-4.0\framework\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Source\Async\AsyncStatus.cs" />
<Compile Include="Source\Async\AsyncStatusEventArgs.cs" />
<Compile Include="Source\Async\IAsyncAction.cs" />
<Compile Include="Source\Async\IAsyncSwitch.cs" />
<Compile Include="Source\Async\IAsyncTask.cs" />
<Compile Include="Source\Async\ICancellable.cs" />
<Compile Include="Source\Async\IProgressSource.cs" />
<Compile Include="Source\Cloning\CloneFactoryTest.cs" />
<Compile Include="Source\Cloning\ExpressionTreeCloner.cs" />
<Compile Include="Source\Cloning\ExpressionTreeCloner.FieldBased.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ExpressionTreeCloner.PropertyBased.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ExpressionTreeCloner.Test.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\IStateCopier.cs" />
<Compile Include="Source\Cloning\ReflectionCloner.cs" />
<Compile Include="Source\Cloning\ReflectionCloner.Test.cs">
<DependentUpon>ReflectionCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ICloneFactory.cs" />
<Compile Include="Source\Cloning\SerializationCloner.cs" />
<Compile Include="Source\Cloning\SerializationCloner.Test.cs">
<DependentUpon>SerializationCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Constants.cs" />
<Compile Include="Source\Collections\Constants.Test.cs">
<DependentUpon>Constants.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.cs" />
<Compile Include="Source\Collections\Deque.Insertion.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Interfaces.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Removal.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Search.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Test.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\IMultiDictionary.cs" />
<Compile Include="Source\Collections\IObservableCollection.cs" />
<Compile Include="Source\Collections\IRecyclable.cs" />
<Compile Include="Source\Collections\ItemEventArgs.cs" />
<Compile Include="Source\Collections\ItemEventArgs.Test.cs">
<DependentUpon>ItemEventArgs.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ItemReplaceEventArgs.cs" />
<Compile Include="Source\Collections\ItemReplaceEventArgs.Test.cs">
<DependentUpon>ItemReplaceEventArgs.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\MultiDictionary.cs" />
<Compile Include="Source\Collections\MultiDictionary.ValueCollection.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\MultiDictionary.Interfaces.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\MultiDictionary.Test.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableCollection.cs" />
<Compile Include="Source\Collections\ObservableCollection.Test.cs">
<DependentUpon>ObservableCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableDictionary.cs" />
<Compile Include="Source\Collections\ObservableDictionary.Test.cs">
<DependentUpon>ObservableDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableList.cs" />
<Compile Include="Source\Collections\ObservableList.Test.cs">
<DependentUpon>ObservableList.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableSet.cs" />
<Compile Include="Source\Collections\ObservableSet.Test.cs">
<DependentUpon>ObservableSet.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PairPriorityQueue.cs" />
<Compile Include="Source\Collections\PairPriorityQueue.Test.cs">
<DependentUpon>PairPriorityQueue.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Parentable.cs" />
<Compile Include="Source\Collections\Parentable.Test.cs">
<DependentUpon>Parentable.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ParentingCollection.cs" />
<Compile Include="Source\Collections\ParentingCollection.Test.cs">
<DependentUpon>ParentingCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Pool.cs" />
<Compile Include="Source\Collections\Pool.Test.cs">
<DependentUpon>Pool.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PriorityItemPair.cs" />
<Compile Include="Source\Collections\PriorityItemPair.Test.cs">
<DependentUpon>PriorityItemPair.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PriorityQueue.cs" />
<Compile Include="Source\Collections\PriorityQueue.Test.cs">
<DependentUpon>PriorityQueue.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyCollection.cs" />
<Compile Include="Source\Collections\ReadOnlyCollection.Test.cs">
<DependentUpon>ReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyDictionary.cs" />
<Compile Include="Source\Collections\ReadOnlyDictionary.Test.cs">
<DependentUpon>ReadOnlyDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyList.cs" />
<Compile Include="Source\Collections\ReadOnlyList.Test.cs">
<DependentUpon>ReadOnlyList.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlySet.cs" />
<Compile Include="Source\Collections\ReadOnlySet.Test.cs">
<DependentUpon>ReadOnlySet.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReverseComparer.cs" />
<Compile Include="Source\Collections\ReverseComparer.Test.cs">
<DependentUpon>ReverseComparer.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.cs" />
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Interfaces.cs">
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Test.cs">
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Variegator.cs" />
<Compile Include="Source\Collections\Variegator.Test.cs">
<DependentUpon>Variegator.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\WeakCollection.cs" />
<Compile Include="Source\Collections\WeakCollection.Interfaces.cs">
<DependentUpon>WeakCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\WeakCollection.Test.cs">
<DependentUpon>WeakCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ConfigurationFileStore.cs" />
<Compile Include="Source\Settings\ConfigurationFileStore.Parsing.cs">
<DependentUpon>ConfigurationFileStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ConfigurationFileStore.Test.cs">
<DependentUpon>ConfigurationFileStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ISettingsStore.cs" />
<Compile Include="Source\Settings\MemoryStore.cs" />
<Compile Include="Source\Settings\MemoryStore.Test.cs">
<DependentUpon>MemoryStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\OptionInfo.cs" />
<Compile Include="Source\Settings\WindowsRegistryStore.cs" />
<Compile Include="Source\Settings\WindowsRegistryStore.Test.cs">
<DependentUpon>WindowsRegistryStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\GarbagePolicy.cs" />
<Compile Include="Source\IO\PartialStream.cs" />
<Compile Include="Source\IO\PartialStream.Test.cs">
<DependentUpon>PartialStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\IO\RingMemoryStream.cs" />
<Compile Include="Source\IO\RingMemoryStream.Test.cs">
<DependentUpon>RingMemoryStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\IO\ChainStream.cs" />
<Compile Include="Source\IO\ChainStream.Test.cs">
<DependentUpon>ChainStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\Licensing\LicenseKey.cs" />
<Compile Include="Source\Licensing\LicenseKey.Test.cs">
<DependentUpon>LicenseKey.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.cs" />
<Compile Include="Source\Parsing\CommandLine.Argument.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Formatter.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Test.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Parser.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\ParserHelper.cs" />
<Compile Include="Source\Parsing\ParserHelper.Test.cs">
<DependentUpon>ParserHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\PropertyChangedEventArgsHelper.cs" />
<Compile Include="Source\PropertyChangedEventArgsHelper.Test.cs">
<DependentUpon>PropertyChangedEventArgsHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\EnumHelper.cs" />
<Compile Include="Source\EnumHelper.Test.cs">
<DependentUpon>EnumHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Observable.cs" />
<Compile Include="Source\Observable.Test.cs">
<DependentUpon>Observable.cs</DependentUpon>
</Compile>
<Compile Include="Source\ObservableHelper.cs" />
<Compile Include="Source\ObservableHelper.Test.cs">
<DependentUpon>ObservableHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\AffineThreadPool.cs" />
<Compile Include="Source\Threading\AffineThreadPool.Test.cs">
<DependentUpon>AffineThreadPool.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\CancellableAction.cs" />
<Compile Include="Source\Threading\ParallelBackgroundWorker.cs" />
<Compile Include="Source\Threading\ParallelBackgroundWorker.Test.cs">
<DependentUpon>ParallelBackgroundWorker.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\ThreadRunner.cs" />
<Compile Include="Source\Threading\ThreadRunner.Test.cs">
<DependentUpon>ThreadRunner.cs</DependentUpon>
</Compile>
<Compile Include="Source\TypeHelper.cs" />
<Compile Include="Source\TypeHelper.Test.cs">
<DependentUpon>TypeHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\FloatHelper.cs" />
<Compile Include="Source\FloatHelper.Test.cs">
<DependentUpon>FloatHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\IntegerHelper.cs" />
<Compile Include="Source\IntegerHelper.Test.cs">
<DependentUpon>IntegerHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\PathHelper.cs" />
<Compile Include="Source\PathHelper.Test.cs">
<DependentUpon>PathHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Shared.cs" />
<Compile Include="Source\Shared.Test.cs">
<DependentUpon>Shared.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringBuilderHelper.cs" />
<Compile Include="Source\StringBuilderHelper.Test.cs">
<DependentUpon>StringBuilderHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringHelper.cs" />
<Compile Include="Source\StringHelper.Test.cs">
<DependentUpon>StringHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringSegment.cs" />
<Compile Include="Source\StringSegment.Test.cs">
<DependentUpon>StringSegment.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\XmlHelper.cs" />
<Compile Include="Source\XmlHelper.Test.cs">
<DependentUpon>XmlHelper.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\Foundation.snk">
<Link>Foundation.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Documents\DoubleConverter.txt" />
<Content Include="Documents\Nuclex.Support.txt" />
<Content Include="Documents\Request Framework.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{00567408-4F44-4C00-866E-B04A99E482F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Nuclex.Support</RootNamespace>
<AssemblyName>Nuclex.Support</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net-4.0\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Debug\Nuclex.Support.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net-4.0\Release\</OutputPath>
<DefineConstants>TRACE;UNITTEST;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\net-4.0\Release\Nuclex.Support.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\Foundation.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="NMock.StrongNamed">
<HintPath>..\References\nmock\net-4.0\NMock.StrongNamed.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\nunit\net-4.0\framework\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Source\Async\AsyncStatus.cs" />
<Compile Include="Source\Async\AsyncStatusEventArgs.cs" />
<Compile Include="Source\Async\IAsyncAction.cs" />
<Compile Include="Source\Async\IAsyncSwitch.cs" />
<Compile Include="Source\Async\IAsyncTask.cs" />
<Compile Include="Source\Async\ICancellable.cs" />
<Compile Include="Source\Async\IProgressSource.cs" />
<Compile Include="Source\Cloning\CloneFactoryTest.cs" />
<Compile Include="Source\Cloning\ExpressionTreeCloner.cs" />
<Compile Include="Source\Cloning\ExpressionTreeCloner.FieldBased.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ExpressionTreeCloner.PropertyBased.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ExpressionTreeCloner.Test.cs">
<DependentUpon>ExpressionTreeCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\IStateCopier.cs" />
<Compile Include="Source\Cloning\ReflectionCloner.cs" />
<Compile Include="Source\Cloning\ReflectionCloner.Test.cs">
<DependentUpon>ReflectionCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Cloning\ICloneFactory.cs" />
<Compile Include="Source\Cloning\SerializationCloner.cs" />
<Compile Include="Source\Cloning\SerializationCloner.Test.cs">
<DependentUpon>SerializationCloner.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Constants.cs" />
<Compile Include="Source\Collections\Constants.Test.cs">
<DependentUpon>Constants.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.cs" />
<Compile Include="Source\Collections\Deque.Insertion.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Interfaces.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Removal.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Search.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Deque.Test.cs">
<DependentUpon>Deque.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\IMultiDictionary.cs" />
<Compile Include="Source\Collections\IObservableCollection.cs" />
<Compile Include="Source\Collections\IRecyclable.cs" />
<Compile Include="Source\Collections\ItemEventArgs.cs" />
<Compile Include="Source\Collections\ItemEventArgs.Test.cs">
<DependentUpon>ItemEventArgs.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ItemReplaceEventArgs.cs" />
<Compile Include="Source\Collections\ItemReplaceEventArgs.Test.cs">
<DependentUpon>ItemReplaceEventArgs.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ListSegment.cs" />
<Compile Include="Source\Collections\ListSegment.Test.cs" />
<Compile Include="Source\Collections\MultiDictionary.cs" />
<Compile Include="Source\Collections\MultiDictionary.ValueCollection.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\MultiDictionary.Interfaces.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\MultiDictionary.Test.cs">
<DependentUpon>MultiDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableCollection.cs" />
<Compile Include="Source\Collections\ObservableCollection.Test.cs">
<DependentUpon>ObservableCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableDictionary.cs" />
<Compile Include="Source\Collections\ObservableDictionary.Test.cs">
<DependentUpon>ObservableDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableList.cs" />
<Compile Include="Source\Collections\ObservableList.Test.cs">
<DependentUpon>ObservableList.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ObservableSet.cs" />
<Compile Include="Source\Collections\ObservableSet.Test.cs">
<DependentUpon>ObservableSet.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PairPriorityQueue.cs" />
<Compile Include="Source\Collections\PairPriorityQueue.Test.cs">
<DependentUpon>PairPriorityQueue.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Parentable.cs" />
<Compile Include="Source\Collections\Parentable.Test.cs">
<DependentUpon>Parentable.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ParentingCollection.cs" />
<Compile Include="Source\Collections\ParentingCollection.Test.cs">
<DependentUpon>ParentingCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Pool.cs" />
<Compile Include="Source\Collections\Pool.Test.cs">
<DependentUpon>Pool.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PriorityItemPair.cs" />
<Compile Include="Source\Collections\PriorityItemPair.Test.cs">
<DependentUpon>PriorityItemPair.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\PriorityQueue.cs" />
<Compile Include="Source\Collections\PriorityQueue.Test.cs">
<DependentUpon>PriorityQueue.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyCollection.cs" />
<Compile Include="Source\Collections\ReadOnlyCollection.Test.cs">
<DependentUpon>ReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyDictionary.cs" />
<Compile Include="Source\Collections\ReadOnlyDictionary.Test.cs">
<DependentUpon>ReadOnlyDictionary.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlyList.cs" />
<Compile Include="Source\Collections\ReadOnlyList.Test.cs">
<DependentUpon>ReadOnlyList.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReadOnlySet.cs" />
<Compile Include="Source\Collections\ReadOnlySet.Test.cs">
<DependentUpon>ReadOnlySet.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\ReverseComparer.cs" />
<Compile Include="Source\Collections\ReverseComparer.Test.cs">
<DependentUpon>ReverseComparer.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.cs" />
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Interfaces.cs">
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Test.cs">
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\Variegator.cs" />
<Compile Include="Source\Collections\Variegator.Test.cs">
<DependentUpon>Variegator.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\WeakCollection.cs" />
<Compile Include="Source\Collections\WeakCollection.Interfaces.cs">
<DependentUpon>WeakCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\WeakCollection.Test.cs">
<DependentUpon>WeakCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ConfigurationFileStore.cs" />
<Compile Include="Source\Settings\ConfigurationFileStore.Parsing.cs">
<DependentUpon>ConfigurationFileStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ConfigurationFileStore.Test.cs">
<DependentUpon>ConfigurationFileStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\ISettingsStore.cs" />
<Compile Include="Source\Settings\MemoryStore.cs" />
<Compile Include="Source\Settings\MemoryStore.Test.cs">
<DependentUpon>MemoryStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\Settings\OptionInfo.cs" />
<Compile Include="Source\Settings\WindowsRegistryStore.cs" />
<Compile Include="Source\Settings\WindowsRegistryStore.Test.cs">
<DependentUpon>WindowsRegistryStore.cs</DependentUpon>
</Compile>
<Compile Include="Source\GarbagePolicy.cs" />
<Compile Include="Source\IO\PartialStream.cs" />
<Compile Include="Source\IO\PartialStream.Test.cs">
<DependentUpon>PartialStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\IO\RingMemoryStream.cs" />
<Compile Include="Source\IO\RingMemoryStream.Test.cs">
<DependentUpon>RingMemoryStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\IO\ChainStream.cs" />
<Compile Include="Source\IO\ChainStream.Test.cs">
<DependentUpon>ChainStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\Licensing\LicenseKey.cs" />
<Compile Include="Source\Licensing\LicenseKey.Test.cs">
<DependentUpon>LicenseKey.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.cs" />
<Compile Include="Source\Parsing\CommandLine.Argument.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Formatter.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Test.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\CommandLine.Parser.cs">
<DependentUpon>CommandLine.cs</DependentUpon>
</Compile>
<Compile Include="Source\Parsing\ParserHelper.cs" />
<Compile Include="Source\Parsing\ParserHelper.Test.cs">
<DependentUpon>ParserHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\PropertyChangedEventArgsHelper.cs" />
<Compile Include="Source\PropertyChangedEventArgsHelper.Test.cs">
<DependentUpon>PropertyChangedEventArgsHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\EnumHelper.cs" />
<Compile Include="Source\EnumHelper.Test.cs">
<DependentUpon>EnumHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Observable.cs" />
<Compile Include="Source\Observable.Test.cs">
<DependentUpon>Observable.cs</DependentUpon>
</Compile>
<Compile Include="Source\ObservableHelper.cs" />
<Compile Include="Source\ObservableHelper.Test.cs">
<DependentUpon>ObservableHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\AffineThreadPool.cs" />
<Compile Include="Source\Threading\AffineThreadPool.Test.cs">
<DependentUpon>AffineThreadPool.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\CancellableAction.cs" />
<Compile Include="Source\Threading\ParallelBackgroundWorker.cs" />
<Compile Include="Source\Threading\ParallelBackgroundWorker.Test.cs">
<DependentUpon>ParallelBackgroundWorker.cs</DependentUpon>
</Compile>
<Compile Include="Source\Threading\ThreadRunner.cs" />
<Compile Include="Source\Threading\ThreadRunner.Test.cs">
<DependentUpon>ThreadRunner.cs</DependentUpon>
</Compile>
<Compile Include="Source\TypeHelper.cs" />
<Compile Include="Source\TypeHelper.Test.cs">
<DependentUpon>TypeHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\FloatHelper.cs" />
<Compile Include="Source\FloatHelper.Test.cs">
<DependentUpon>FloatHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\IntegerHelper.cs" />
<Compile Include="Source\IntegerHelper.Test.cs">
<DependentUpon>IntegerHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\PathHelper.cs" />
<Compile Include="Source\PathHelper.Test.cs">
<DependentUpon>PathHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Shared.cs" />
<Compile Include="Source\Shared.Test.cs">
<DependentUpon>Shared.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringBuilderHelper.cs" />
<Compile Include="Source\StringBuilderHelper.Test.cs">
<DependentUpon>StringBuilderHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringHelper.cs" />
<Compile Include="Source\StringHelper.Test.cs">
<DependentUpon>StringHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\StringSegment.cs" />
<Compile Include="Source\StringSegment.Test.cs">
<DependentUpon>StringSegment.cs</DependentUpon>
</Compile>
<Compile Include="Source\WeakReference.cs" />
<Compile Include="Source\WeakReference.Test.cs">
<DependentUpon>WeakReference.cs</DependentUpon>
</Compile>
<Compile Include="Source\XmlHelper.cs" />
<Compile Include="Source\XmlHelper.Test.cs">
<DependentUpon>XmlHelper.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\Foundation.snk">
<Link>Foundation.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Documents\DoubleConverter.txt" />
<Content Include="Documents\Nuclex.Support.txt" />
<Content Include="Documents\Request Framework.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>

View File

@ -0,0 +1,257 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2017 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
#if UNITTEST
using NUnit.Framework;
namespace Nuclex.Support.Collections {
/// <summary>Unit Test for the list segment class</summary>
[TestFixture]
internal class ListSegmentTest {
/// <summary>
/// Tests whether the default constructor of the ListSegment class throws the
/// right exception when being passed 'null' instead of a list
/// </summary>
[Test]
public void SimpleConstructorThrowsWhenListIsNull() {
Assert.Throws<ArgumentNullException>(
delegate() { new ListSegment<int>(null); }
);
}
/// <summary>
/// Tests whether the simple constructor of the ListSegment class accepts
/// an empty list
/// </summary>
[Test]
public void SimpleConstructorAcceptsEmptyList() {
new ListSegment<int>(new List<int>());
}
/// <summary>
/// Tests whether the full constructor of the ListSegment class throws the
/// right exception when being passed 'null' instead of a string
/// </summary>
[Test]
public void ConstructorThrowsWhenListIsNull() {
Assert.Throws<ArgumentNullException>(
delegate() { new ListSegment<int>(null, 0, 0); }
);
}
/// <summary>
/// Tests whether the full constructor of the ListSegment class accepts
/// an empty string
/// </summary>
[Test]
public void ConstructorAcceptsEmptyList() {
new ListSegment<int>(new List<int>(), 0, 0);
}
/// <summary>
/// Tests whether the full constructor of the ListSegment class throws the
/// right exception when being passed an invalid start offset
/// </summary>
[Test]
public void ConstructorThrowsOnInvalidOffset() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new ListSegment<int>(new List<int>(), -1, 0); }
);
}
/// <summary>
/// Tests whether the full constructor of the ListSegment class throws the
/// right exception when being passed an invalid element count
/// </summary>
[Test]
public void ConstructorThrowsOnInvalidCount() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new ListSegment<int>(new List<int>(), 0, -1); }
);
}
/// <summary>
/// Tests whether the full constructor of the ListSegment class throws the
/// right exception when being passed a string length that's too large
/// </summary>
[Test]
public void ConstructorThrowsOnListOverrun() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
Assert.Throws<ArgumentException>(
delegate() { new ListSegment<int>(testList, 3, 3); }
);
}
/// <summary>Tests whether the 'Text' property works as expected</summary>
[Test]
public void ListPropertyStoresOriginalList() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 1, 3);
Assert.AreSame(testList, testSegment.List);
}
/// <summary>Tests whether the 'Offset' property works as expected</summary>
[Test]
public void OffsetPropertyIsStored() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 1, 3);
Assert.AreEqual(1, testSegment.Offset);
}
/// <summary>Tests whether the 'Count' property works as expected</summary>
[Test]
public void CountPropertyIsStored() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 1, 3);
Assert.AreEqual(3, testSegment.Count);
}
/// <summary>
/// Tests whether two differing instances produce different hash codes
/// </summary>
[Test]
public void DifferentInstancesHaveDifferentHashCodes_Usually() {
var forwardCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var reverseCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 9, 8, 7, 6, 5, 4, 3, 2, 1 }, 1, 8
);
Assert.AreNotEqual(
forwardCountSegment.GetHashCode(), reverseCountSegment.GetHashCode()
);
}
/// <summary>
/// Tests whether two equivalent instances produce an identical hash code
/// </summary>
[Test]
public void EquivalentInstancesHaveSameHashcode() {
var testSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var identicalSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
Assert.AreEqual(
testSegment.GetHashCode(), identicalSegment.GetHashCode()
);
}
/// <summary>Tests the equals method performing a comparison against null</summary>
[Test]
public void EqualsAgainstNullIsAlwaysFalse() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 1, 3);
Assert.IsFalse(
testSegment.Equals(null)
);
}
/// <summary>Tests the equality operator with differing instances</summary>
[Test]
public void DifferingInstancesAreNotEqual() {
var forwardCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var reverseCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 9, 8, 7, 6, 5, 4, 3, 2, 1 }, 1, 8
);
Assert.IsFalse(forwardCountSegment == reverseCountSegment);
}
/// <summary>Tests the equality operator with equivalent instances</summary>
[Test]
public void EquivalentInstancesAreEqual() {
var testSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var identicalSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
Assert.IsTrue(testSegment == identicalSegment);
}
/// <summary>Tests the inequality operator with differing instances</summary>
[Test]
public void DifferingInstancesAreUnequal() {
var forwardCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var reverseCountSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 9, 8, 7, 6, 5, 4, 3, 2, 1 }, 1, 8
);
Assert.IsTrue(forwardCountSegment != reverseCountSegment);
}
/// <summary>Tests the inequality operator with equivalent instances</summary>
[Test]
public void EquivalentInstancesAreNotUnequal() {
var testSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
var identicalSegment = new ListSegment<int>(
new List<int>(capacity: 9) { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7
);
Assert.IsFalse(testSegment != identicalSegment);
}
/// <summary>Tests the ToString() method of the string segment</summary>
[Test]
public void TestToString() {
var testList = new List<int>(capacity: 6) { 1, 2, 3, 4, 5, 6 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 2, 2);
string stringRepresentation = testSegment.ToString();
StringAssert.Contains("3, 4", stringRepresentation);
StringAssert.DoesNotContain("2", stringRepresentation);
StringAssert.DoesNotContain("5", stringRepresentation);
}
/// <summary>Tests whether the 'Text' property works as expected</summary>
[Test]
public void ToListReturnsSubset() {
var testList = new List<int>(capacity: 5) { 1, 2, 3, 4, 5 };
ListSegment<int> testSegment = new ListSegment<int>(testList, 1, 3);
CollectionAssert.AreEqual(
new List<int>(capacity: 3) { 2, 3, 4 },
testSegment.ToList()
);
}
}
} // namespace Nuclex.Support.Collections
#endif // UNITTEST

View File

@ -0,0 +1,281 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2017 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Nuclex.Support.Collections {
/// <summary>View into a section of an IList&lt;T&gt; without copying said string</summary>
/// <typeparam name="TElement">
/// Type of elements that are stored in the list the segment references
/// </typeparam>
/// <remarks>
/// <para>
/// The design of this class pretty much mirrors that of the
/// <see cref="T:System.ArraySegment" /> class found in the .NET framework, but is
/// specialized to be used for IList&lt;T&gt;, which can not be cast to arrays
/// directly (and <see cref="M:System.ArrayList.Adapter" /> loses type safety).
/// </para>
/// <para>
/// In certain situations, passing a ListSegment instead of storing the selected
/// elements in a new list is useful. For example, the caller might want to know
/// from which index of the original list the section was taken. When the original
/// list needs to be modified, for example in a sorting algorithm, the list segment
/// can be used to specify a region for the algorithm to work on while still accessing
/// the original list.
/// </para>
/// </remarks>
#if !NO_SERIALIZATION
[Serializable, StructLayout(LayoutKind.Sequential)]
#endif
public struct ListSegment<TElement> {
/// <summary>
/// Initializes a new instance of the <see cref="ListSegment&lt;TElement&gt;" /> class
/// that delimits all the elements in the specified string
/// </summary>
/// <param name="list">List that will be wrapped</param>
/// <exception cref="System.ArgumentNullException">String is null</exception>
public ListSegment(IList<TElement> list) {
if(list == null) { // questionable, but matches behavior of ArraySegment class
throw new ArgumentNullException("text", "Text must not be null");
}
this.list = list;
this.offset = 0;
this.count = list.Count;
}
/// <summary>
/// Initializes a new instance of the <see cref="ListSegment&lt;TElement&gt;" /> class
/// that delimits the specified range of the elements in the specified string
/// </summary>
/// <param name="list">The list containing the range of elements to delimit</param>
/// <param name="offset">The zero-based index of the first element in the range</param>
/// <param name="count">The number of elements in the range</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Offset or count is less than 0
/// </exception>
/// <exception cref="System.ArgumentException">
/// Offset and count do not specify a valid range in array
/// </exception>
/// <exception cref="System.ArgumentNullException">String is null</exception>
public ListSegment(IList<TElement> list, int offset, int count) {
if(list == null) { // questionable, but matches behavior of ArraySegment class
throw new ArgumentNullException("list");
}
if(offset < 0) {
throw new ArgumentOutOfRangeException(
"offset", "Argument out of range, non-negative number required"
);
}
if(count < 0) {
throw new ArgumentOutOfRangeException(
"count", "Argument out of range, non-negative number required"
);
}
if(count > (list.Count - offset)) {
throw new ArgumentException(
"Invalid argument, specified offset and count exceed list size"
);
}
this.list = list;
this.offset = offset;
this.count = count;
}
/// <summary>
/// Gets the original list containing the range of elements that the list
/// segment delimits
/// </summary>
/// <returns>
/// The original list that was passed to the constructor, and that contains the range
/// delimited by the <see cref="ListSegment&lt;TElement&gt;" />
/// </returns>
public IList<TElement> List {
get { return this.list; }
}
/// <summary>
/// Gets the position of the first element in the range delimited by the list segment,
/// relative to the start of the original list
/// </summary>
/// <returns>
/// The position of the first element in the range delimited by the
/// <see cref="ListSegment&lt;TElement&gt;" />, relative to the start of the original list
/// </returns>
public int Offset {
get { return this.offset; }
}
/// <summary>
/// Gets the number of elements in the range delimited by the list segment
/// </summary>
/// <returns>
/// The number of elements in the range delimited by
/// the <see cref="ListSegment&lt;TElement&gt;" />
/// </returns>
public int Count {
get { return this.count; }
}
/// <summary>Returns the hash code for the current instance</summary>
/// <returns>A 32-bit signed integer hash code</returns>
public override int GetHashCode() {
int hashCode = this.offset ^ this.count;
for(int index = 0; index < this.count; ++index) {
hashCode ^= this.list[index + this.offset].GetHashCode();
}
return hashCode;
}
/// <summary>
/// Determines whether the specified object is equal to the current instance
/// </summary>
/// <returns>
/// True if the specified object is a <see cref="ListSegment&lt;TElement&gt;" /> structure
/// and is equal to the current instance; otherwise, false
/// </returns>
/// <param name="other">The object to be compared with the current instance</param>
public override bool Equals(object other) {
return
(other is ListSegment<TElement>) &&
this.Equals((ListSegment<TElement>)other);
}
/// <summary>
/// Determines whether the specified <see cref="ListSegment&lt;TElement&gt;" />
/// structure is equal to the current instance
/// </summary>
/// <returns>
/// True if the specified <see cref="ListSegment&lt;TElement&gt;" /> structure is equal
/// to the current instance; otherwise, false
/// </returns>
/// <param name="other">
/// The <see cref="ListSegment&lt;TElement&gt;" /> structure to be compared with
/// the current instance
/// </param>
public bool Equals(ListSegment<TElement> other) {
if(other.count != this.count) {
return false;
}
if(ReferenceEquals(other.list, this.list)) {
return (other.offset == this.offset);
} else {
var comparer = Comparer<TElement>.Default;
for(int index = 0; index < this.count; ++index) {
int difference = comparer.Compare(
other.list[index + other.offset], this.list[index + this.offset]
);
if(difference != 0) {
return false;
}
}
}
return true;
}
/// <summary>
/// Indicates whether two <see cref="ListSegment&lt;TElement&gt;" /> structures are equal
/// </summary>
/// <returns>True if a is equal to b; otherwise, false</returns>
/// <param name="left">
/// The <see cref="ListSegment&lt;TElement&gt;" /> structure on the left side of
/// the equality operator
/// </param>
/// <param name="right">
/// The <see cref="ListSegment&lt;TElement&gt;" /> structure on the right side of
/// the equality operator
/// </param>
public static bool operator ==(ListSegment<TElement> left, ListSegment<TElement> right) {
return left.Equals(right);
}
/// <summary>
/// Indicates whether two <see cref="ListSegment&lt;TElement&gt;" /> structures are unequal
/// </summary>
/// <returns>True if a is not equal to b; otherwise, false</returns>
/// <param name="left">
/// The <see cref="ListSegment&lt;TElement&gt;" /> structure on the left side of
/// the inequality operator
/// </param>
/// <param name="right">
/// The <see cref="ListSegment&lt;TElement&gt;" /> structure on the right side of
/// the inequality operator
/// </param>
public static bool operator !=(ListSegment<TElement> left, ListSegment<TElement> right) {
return !(left == right);
}
/// <summary>Returns a string representation of the list segment</summary>
/// <returns>The string representation of the list segment</returns>
public override string ToString() {
var builder = new System.Text.StringBuilder();
builder.Append("ListSegment {");
for(int index = 0; index < Math.Min(this.count, 10); ++index) {
if(index == 0) {
builder.Append(" ");
} else {
builder.Append(", ");
}
builder.Append(this.list[index + this.offset].ToString());
}
if(this.count >= 11) {
builder.Append(", ... }");
} else {
builder.Append(" }");
}
return builder.ToString();
}
/// <summary>Returns a new list containing only the elements in the list segment</summary>
/// <returns>A new list containing only the elements in the list segment</returns>
public List<TElement> ToList() {
if(this.count == 0) {
return new List<TElement>(capacity: 0);
} else {
var newList = new List<TElement>(capacity: this.count);
{
int endIndex = this.offset + this.count;
for(int index = this.offset; index < endIndex; ++index) {
newList.Add(this.list[index]);
}
}
return newList;
}
}
/// <summary>List wrapped by the list segment</summary>
private IList<TElement> list;
/// <summary>Offset in the original list the segment begins at</summary>
private int offset;
/// <summary>Number of elements in the segment</summary>
private int count;
}
} // namespace Nuclex.Support.Collections

View File

@ -27,7 +27,7 @@ using NUnit.Framework;
namespace Nuclex.Support {
/// <summary>Unit Test for the strign segment class</summary>
/// <summary>Unit Test for the string segment class</summary>
[TestFixture]
internal class StringSegmentTest {
@ -36,7 +36,7 @@ namespace Nuclex.Support {
/// right exception when being passed 'null' instead of a string
/// </summary>
[Test]
public void TestNullStringInSimpleConstructor() {
public void SimpleConstructorThrowsWhenStringIsNull() {
Assert.Throws<ArgumentNullException>(
delegate() { new StringSegment(null); }
);
@ -47,7 +47,7 @@ namespace Nuclex.Support {
/// an empty string
/// </summary>
[Test]
public void TestEmptyStringInSimpleConstructor() {
public void SimpleConstructorAcceptsEmptyString() {
new StringSegment(string.Empty);
}
@ -56,7 +56,7 @@ namespace Nuclex.Support {
/// right exception when being passed 'null' instead of a string
/// </summary>
[Test]
public void TestNullStringInFullConstructor() {
public void ConstructorThrowsWhenStringIsNull() {
Assert.Throws<ArgumentNullException>(
delegate() { new StringSegment(null, 0, 0); }
);
@ -67,7 +67,7 @@ namespace Nuclex.Support {
/// an empty string
/// </summary>
[Test]
public void TestEmptyStringInFullConstructor() {
public void ConstructorAcceptsEmptyString() {
new StringSegment(string.Empty, 0, 0);
}
@ -76,7 +76,7 @@ namespace Nuclex.Support {
/// right exception when being passed an invalid start offset
/// </summary>
[Test]
public void TestInvalidOffsetInConstructor() {
public void ConstructorThrowsOnInvalidOffset() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new StringSegment(string.Empty, -1, 0); }
);
@ -87,7 +87,7 @@ namespace Nuclex.Support {
/// right exception when being passed an invalid string length
/// </summary>
[Test]
public void TestInvalidLengthInConstructor() {
public void ConstructorThrowsOnInvalidLength() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new StringSegment(string.Empty, 0, -1); }
);
@ -98,7 +98,7 @@ namespace Nuclex.Support {
/// right exception when being passed a string length that's too large
/// </summary>
[Test]
public void TestExcessiveLengthInConstructor() {
public void ConstructorThrowsOnLengthOverrun() {
Assert.Throws<ArgumentException>(
delegate() { new StringSegment("hello", 3, 3); }
);
@ -106,21 +106,21 @@ namespace Nuclex.Support {
/// <summary>Tests whether the 'Text' property works as expected</summary>
[Test]
public void TestTextProperty() {
public void TextPropertyStoresOriginalString() {
StringSegment testSegment = new StringSegment("hello", 1, 3);
Assert.AreEqual("hello", testSegment.Text);
}
/// <summary>Tests whether the 'Offset' property works as expected</summary>
[Test]
public void TestOffsetProperty() {
public void OffsetPropertyIsStored() {
StringSegment testSegment = new StringSegment("hello", 1, 3);
Assert.AreEqual(1, testSegment.Offset);
}
/// <summary>Tests whether the 'Count' property works as expected</summary>
[Test]
public void TestCountProperty() {
public void CountPropertyIsStored() {
StringSegment testSegment = new StringSegment("hello", 1, 3);
Assert.AreEqual(3, testSegment.Count);
}
@ -129,7 +129,7 @@ namespace Nuclex.Support {
/// Tests whether two differing instances produce different hash codes
/// </summary>
[Test]
public void TestHashCodeOnDifferingInstances() {
public void DifferentInstancesHaveDifferentHashCodes_Usually() {
StringSegment helloWorldSegment = new StringSegment("hello world", 2, 7);
StringSegment howAreYouSegment = new StringSegment("how are you", 1, 9);
@ -142,7 +142,7 @@ namespace Nuclex.Support {
/// Tests whether two equivalent instances produce an identical hash code
/// </summary>
[Test]
public void TestHashCodeOnEquivalentInstances() {
public void EquivalentInstancesHaveSameHashcode() {
StringSegment helloWorld1Segment = new StringSegment("hello world", 2, 7);
StringSegment helloWorld2Segment = new StringSegment("hello world", 2, 7);
@ -153,7 +153,7 @@ namespace Nuclex.Support {
/// <summary>Tests the equals method performing a comparison against null</summary>
[Test]
public void TestEqualsOnNull() {
public void EqualsAgainstNullIsAlwaysFalse() {
StringSegment helloWorldSegment = new StringSegment("hello world", 2, 7);
Assert.IsFalse(
@ -163,7 +163,7 @@ namespace Nuclex.Support {
/// <summary>Tests the equality operator with differing instances</summary>
[Test]
public void TestEqualityOnDifferingInstances() {
public void DifferingInstancesAreNotEqual() {
StringSegment helloWorldSegment = new StringSegment("hello world", 2, 7);
StringSegment howAreYouSegment = new StringSegment("how are you", 1, 9);
@ -172,7 +172,7 @@ namespace Nuclex.Support {
/// <summary>Tests the equality operator with equivalent instances</summary>
[Test]
public void TestEqualityOnEquivalentInstances() {
public void EquivalentInstancesAreEqual() {
StringSegment helloWorld1Segment = new StringSegment("hello world", 2, 7);
StringSegment helloWorld2Segment = new StringSegment("hello world", 2, 7);
@ -181,7 +181,7 @@ namespace Nuclex.Support {
/// <summary>Tests the inequality operator with differing instances</summary>
[Test]
public void TestInequalityOnDifferingInstances() {
public void DifferingInstancesAreUnequal() {
StringSegment helloWorldSegment = new StringSegment("hello world", 2, 7);
StringSegment howAreYouSegment = new StringSegment("how are you", 1, 9);
@ -190,7 +190,7 @@ namespace Nuclex.Support {
/// <summary>Tests the inequality operator with equivalent instances</summary>
[Test]
public void TestInequalityOnEquivalentInstances() {
public void EquivalentInstancesAreNotUnequal() {
StringSegment helloWorld1Segment = new StringSegment("hello world", 2, 7);
StringSegment helloWorld2Segment = new StringSegment("hello world", 2, 7);
@ -205,36 +205,6 @@ namespace Nuclex.Support {
Assert.AreEqual("o w", helloWorldSegment.ToString());
}
/// <summary>
/// Tests the ToString() method of the string segment with an invalid string
/// </summary>
[Test]
public void TestToStringWithInvalidString() {
Assert.Throws<ArgumentNullException>(
delegate() { new StringSegment(null, 4, 3); }
);
}
/// <summary>
/// Tests the ToString() method of the string segment with an invalid offset
/// </summary>
[Test]
public void TestToStringWithInvalidOffset() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new StringSegment("hello world", -4, 3); }
);
}
/// <summary>
/// Tests the ToString() method of the string segment with an invalid count
/// </summary>
[Test]
public void TestToStringWithInvalidCount() {
Assert.Throws<ArgumentOutOfRangeException>(
delegate() { new StringSegment("hello world", 4, -3); }
);
}
}
} // namespace Nuclex.Support

View File

@ -23,7 +23,7 @@ using System.Runtime.InteropServices;
namespace Nuclex.Support {
/// <summary>Delimits a section of a string</summary>
/// <summary>View into a section of a string without copying said string</summary>
/// <remarks>
/// <para>
/// The design of this class pretty much mirrors that of the
@ -32,10 +32,10 @@ namespace Nuclex.Support {
/// share a lot of the characteristics of an array.
/// </para>
/// <para>
/// In certain situations, passing a StringSegment instead of the the actual
/// section from a string is useful. For example, the caller might want to know
/// from which index of the original string the substring was taken. Used internally
/// in parsers, it can also prevent needless string copying and garbage generation.
/// In certain situations, passing a StringSegment instead of the actual copied
/// substring is useful. For example, the caller might want to know from which
/// index of the original string the substring was taken. Used internally in parsers,
/// it can also prevent needless string copying and garbage generation.
/// </para>
/// </remarks>
#if !NO_SERIALIZATION
@ -103,7 +103,7 @@ namespace Nuclex.Support {
/// segment delimits
/// </summary>
/// <returns>
/// The original array that was passed to the constructor, and that contains the range
/// The original string that was passed to the constructor, and that contains the range
/// delimited by the <see cref="StringSegment" />
/// </returns>
public string Text {
@ -111,19 +111,19 @@ namespace Nuclex.Support {
}
/// <summary>
/// Gets the position of the first element in the range delimited by the array segment,
/// relative to the start of the original array
/// Gets the position of the first element in the range delimited by the string segment,
/// relative to the start of the original string
/// </summary>
/// <returns>
/// The position of the first element in the range delimited by the
/// <see cref="StringSegment" />, relative to the start of the original array
/// <see cref="StringSegment" />, relative to the start of the original string
/// </returns>
public int Offset {
get { return this.offset; }
}
/// <summary>
/// Gets the number of elements in the range delimited by the array segment
/// Gets the number of elements in the range delimited by the string segment
/// </summary>
/// <returns>
/// The number of elements in the range delimited by the <see cref="StringSegment" />