Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ TestResults/*
*.suo
*.user
_ReSharper.*
.vs/
*.nupkg
**/packages/*
*.nuget.props
*.nuget.targets
53 changes: 26 additions & 27 deletions PerishableCollection.sln
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionExample", "PerishableCollectionExample\PerishableCollectionExample.csproj", "{669BABBC-C9D1-4726-8F0C-1F979C15F5CD}"
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerishableCollection", "PerishableCollection\PerishableCollection.csproj", "{EDFC9D5F-A07B-4EE9-976A-16A3AA15EC4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionExampleTest", "PerishableCollectionExampleTest\PerishableCollectionExampleTest.csproj", "{B3E0CBA9-00D1-4372-BDFE-A6D81531BEB0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionTest", "PerishableCollectionTest\PerishableCollectionTest.csproj", "{E12E9F4C-A683-4477-8BE0-6B0A7BC95E8E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollection", "PerishableCollection\PerishableCollection.csproj", "{7541343D-44B8-49E3-8C2A-0F2618A3B11E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionExample", "PerishableCollectionExample\PerishableCollectionExample.csproj", "{C4CB8315-C38C-48A0-A4B8-9FF8FEC983B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionTest", "PerishableCollectionTest\PerishableCollectionTest.csproj", "{CE78991E-337D-4F75-BA89-B4CC1C05C378}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollection_NonPortableLibrary", "PerishableCollection_NonPortableLibrary\PerishableCollection_NonPortableLibrary.csproj", "{85535624-5831-4C45-AD09-178F85F0E592}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerishableCollectionExampleTest", "PerishableCollectionExampleTest\PerishableCollectionExampleTest.csproj", "{28D8E750-1741-4213-9394-15EEABB7CC34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{669BABBC-C9D1-4726-8F0C-1F979C15F5CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{669BABBC-C9D1-4726-8F0C-1F979C15F5CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{669BABBC-C9D1-4726-8F0C-1F979C15F5CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{669BABBC-C9D1-4726-8F0C-1F979C15F5CD}.Release|Any CPU.Build.0 = Release|Any CPU
{B3E0CBA9-00D1-4372-BDFE-A6D81531BEB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3E0CBA9-00D1-4372-BDFE-A6D81531BEB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3E0CBA9-00D1-4372-BDFE-A6D81531BEB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3E0CBA9-00D1-4372-BDFE-A6D81531BEB0}.Release|Any CPU.Build.0 = Release|Any CPU
{7541343D-44B8-49E3-8C2A-0F2618A3B11E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7541343D-44B8-49E3-8C2A-0F2618A3B11E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7541343D-44B8-49E3-8C2A-0F2618A3B11E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7541343D-44B8-49E3-8C2A-0F2618A3B11E}.Release|Any CPU.Build.0 = Release|Any CPU
{CE78991E-337D-4F75-BA89-B4CC1C05C378}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE78991E-337D-4F75-BA89-B4CC1C05C378}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE78991E-337D-4F75-BA89-B4CC1C05C378}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE78991E-337D-4F75-BA89-B4CC1C05C378}.Release|Any CPU.Build.0 = Release|Any CPU
{85535624-5831-4C45-AD09-178F85F0E592}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85535624-5831-4C45-AD09-178F85F0E592}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85535624-5831-4C45-AD09-178F85F0E592}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85535624-5831-4C45-AD09-178F85F0E592}.Release|Any CPU.Build.0 = Release|Any CPU
{EDFC9D5F-A07B-4EE9-976A-16A3AA15EC4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDFC9D5F-A07B-4EE9-976A-16A3AA15EC4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDFC9D5F-A07B-4EE9-976A-16A3AA15EC4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDFC9D5F-A07B-4EE9-976A-16A3AA15EC4F}.Release|Any CPU.Build.0 = Release|Any CPU
{E12E9F4C-A683-4477-8BE0-6B0A7BC95E8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E12E9F4C-A683-4477-8BE0-6B0A7BC95E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E12E9F4C-A683-4477-8BE0-6B0A7BC95E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E12E9F4C-A683-4477-8BE0-6B0A7BC95E8E}.Release|Any CPU.Build.0 = Release|Any CPU
{C4CB8315-C38C-48A0-A4B8-9FF8FEC983B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4CB8315-C38C-48A0-A4B8-9FF8FEC983B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4CB8315-C38C-48A0-A4B8-9FF8FEC983B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4CB8315-C38C-48A0-A4B8-9FF8FEC983B0}.Release|Any CPU.Build.0 = Release|Any CPU
{28D8E750-1741-4213-9394-15EEABB7CC34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28D8E750-1741-4213-9394-15EEABB7CC34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28D8E750-1741-4213-9394-15EEABB7CC34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28D8E750-1741-4213-9394-15EEABB7CC34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C589D4C0-FAE7-44C6-9DDD-4F704C3E6BF7}
EndGlobalSection
EndGlobal
8 changes: 3 additions & 5 deletions PerishableCollection/Perishable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ public struct Perishable<T> {
public readonly Lifetime Lifetime;
///<summary>Creates a new perishable with the given value and lifetime.</summary>
public Perishable(T value, Lifetime lifetime) {
this.Value = value;
this.Lifetime = lifetime;
Value = value;
Lifetime = lifetime;
}
///<summary>A string representation of the perishable value.</summary>
public override string ToString() {
return string.Format("({0}) {1}", Lifetime, Value);
}
public override string ToString() => $"({Lifetime}) {Value}";
}
}
9 changes: 3 additions & 6 deletions PerishableCollection/PerishableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ private sealed class Link {

///<summary>Creates a new empty perishable collection.</summary>
public PerishableCollection() {
this._root = new Link();
_root = new Link();
_root.Next = _root.Prev = _root;
}

///<summary>Adds an item to the collection, removing it when the given lifetime ends.</summary>
public void Add(T item, Lifetime lifetime) {
Add(new Perishable<T>(item, lifetime));
}
public void Add(T item, Lifetime lifetime) => Add(new Perishable<T>(item, lifetime));

///<summary>Adds an item to the collection, removing it when the item perishes.</summary>
public void Add(Perishable<T> item) {
Expand All @@ -56,8 +54,7 @@ public void Add(Perishable<T> item) {
});

// inform any listeners of the new item
if (onItemDuringInsert != null)
onItemDuringInsert(item);
onItemDuringInsert?.Invoke(item);
}

/// <summary>
Expand Down
88 changes: 25 additions & 63 deletions PerishableCollection/PerishableCollection.csproj
Original file line number Diff line number Diff line change
@@ -1,68 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7541343D-44B8-49E3-8C2A-0F2618A3B11E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TwistedOak.Collections</RootNamespace>
<AssemblyName>PerishableCollection</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.4</Version>
<PackageId>TwistedOak.Collections.PerishableCollection</PackageId>
<Authors>Craig Gidney</Authors>
<Company>Twisted Oak Studios</Company>
<PackageLicenseUrl>https://github.com/TwistedOakStudios/PerishableCollection/blob/master/License.txt</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/TwistedOakStudios/PerishableCollection</PackageProjectUrl>
<PackageIconUrl>http://i.imgur.com/WP3EF.png</PackageIconUrl>
<Description>An observable collection where items are removed when a lifetime paired with them ends.

Affords projecting, filtering, and other functional-style usage by removing the need to equate removed items with previously added items.</Description>
<PackageReleaseNotes>Support for .Net Standard 2.0</PackageReleaseNotes>
<PackageTags>lifetime cancellation token collection perishable</PackageTags>
<Copyright>Twisted Oak Studios, 2012</Copyright>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\PerishableCollection.XML</DocumentationFile>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\PerishableCollection.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\PerishableCollection.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Perishable.cs" />
<Compile Include="PerishableCollection.cs" />
<Compile Include="PerishableUtilities.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Lifetime">
<HintPath>..\packages\TwistedOak.Util.Lifetime.1.0.2\lib\portable-net4+win8\Lifetime.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces">
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq">
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Linq.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
<PackageReference Include="TwistedOak.Util.Lifetime" Version="1.0.2" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.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>

</Project>
22 changes: 11 additions & 11 deletions PerishableCollection/PerishableUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ namespace TwistedOak.Collections {
public static class PerishableUtilities {
///<summary>Feeds observed items into a new perishable collection, stopping if a given lifetime ends.</summary>
public static PerishableCollection<T> ToPerishableCollection<T>(this IObservable<Perishable<T>> observable, Lifetime lifetime = default(Lifetime)) {
if (observable == null) throw new ArgumentNullException("observable");
if (observable == null) throw new ArgumentNullException(nameof(observable));
var result = new PerishableCollection<T>();
observable.Subscribe(result.Add);
observable.Subscribe(result.Add, lifetime);
return result;
}

/// <summary>Projects the value of each perishable element of an observable sequence into a new form.</summary>
public static IObservable<Perishable<TOut>> LiftSelect<TIn, TOut>(this IObservable<Perishable<TIn>> observable, Func<TIn, TOut> projection) {
if (observable == null) throw new ArgumentNullException("observable");
if (projection == null) throw new ArgumentNullException("projection");
if (observable == null) throw new ArgumentNullException(nameof(observable));
if (projection == null) throw new ArgumentNullException(nameof(projection));
return observable.Select(e => new Perishable<TOut>(projection(e.Value), e.Lifetime));
}
/// <summary>Filters the perishable elements of an observable sequence by value based on a predicate.</summary>
public static IObservable<Perishable<T>> LiftWhere<T>(this IObservable<Perishable<T>> observable, Func<T, bool> predicate) {
if (observable == null) throw new ArgumentNullException("observable");
if (predicate == null) throw new ArgumentNullException("predicate");
if (observable == null) throw new ArgumentNullException(nameof(observable));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
return observable.Where(e => predicate(e.Value));
}
/// <summary>Projects the value of each perishable element of a sequence into a new form.</summary>
public static IEnumerable<Perishable<TOut>> LiftSelect<TIn, TOut>(this IEnumerable<Perishable<TIn>> sequence, Func<TIn, TOut> projection) {
if (sequence == null) throw new ArgumentNullException("sequence");
if (projection == null) throw new ArgumentNullException("projection");
if (sequence == null) throw new ArgumentNullException(nameof(sequence));
if (projection == null) throw new ArgumentNullException(nameof(projection));
return sequence.Select(e => new Perishable<TOut>(projection(e.Value), e.Lifetime));
}
/// <summary>Filters the perishable elements of a sequence by value based on a predicate.</summary>
public static IEnumerable<Perishable<T>> LiftWhere<T>(this IEnumerable<Perishable<T>> sequence, Func<T, bool> predicate) {
if (sequence == null) throw new ArgumentNullException("sequence");
if (predicate == null) throw new ArgumentNullException("predicate");
if (sequence == null) throw new ArgumentNullException(nameof(sequence));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
return sequence.Where(e => predicate(e.Value));
}

Expand All @@ -49,7 +49,7 @@ public static IEnumerable<Perishable<T>> LiftWhere<T>(this IEnumerable<Perishabl
/// If false, the resulting observable completes when the observed count is 0 and the source observable has completed.
/// </param>
public static IObservable<int> ObserveNonPerishedCount<T>(this IObservable<Perishable<T>> observable, bool completeWhenSourceCompletes) {
if (observable == null) throw new ArgumentNullException("observable");
if (observable == null) throw new ArgumentNullException(nameof(observable));
return new AnonymousObservable<int>(observer => {
var exposedDisposable = new DisposableLifetime();
var count = 0;
Expand Down
30 changes: 0 additions & 30 deletions PerishableCollection/Properties/AssemblyInfo.cs

This file was deleted.

7 changes: 0 additions & 7 deletions PerishableCollection/packages.config

This file was deleted.

2 changes: 1 addition & 1 deletion PerishableCollectionExample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Loading