{"id":24629476,"url":"https://github.com/sharpjs/sharp.disposable","last_synced_at":"2025-03-20T04:35:43.670Z","repository":{"id":56705148,"uuid":"142175030","full_name":"sharpjs/Sharp.Disposable","owner":"sharpjs","description":"Thread-safe implementation of the .NET Dispose Pattern, plus extras.","archived":false,"fork":false,"pushed_at":"2022-08-11T16:20:39.000Z","size":248,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T20:39:05.833Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sharpjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-24T15:04:12.000Z","updated_at":"2022-06-13T18:22:33.000Z","dependencies_parsed_at":"2022-08-15T23:40:32.317Z","dependency_job_id":null,"html_url":"https://github.com/sharpjs/Sharp.Disposable","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharpjs%2FSharp.Disposable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharpjs%2FSharp.Disposable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharpjs%2FSharp.Disposable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sharpjs%2FSharp.Disposable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sharpjs","download_url":"https://codeload.github.com/sharpjs/Sharp.Disposable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554042,"owners_count":20471172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-25T06:13:01.976Z","updated_at":"2025-03-20T04:35:43.655Z","avatar_url":"https://github.com/sharpjs.png","language":"C#","readme":"# Sharp.Disposable\n\nThread-safe implementation of the [.NET Dispose Pattern](https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose), plus extras.\n\n## Status\n\n[![Build](https://github.com/sharpjs/Sharp.Disposable/workflows/Build/badge.svg)](https://github.com/sharpjs/Sharp.Disposable/actions)\n[![NuGet](https://img.shields.io/nuget/v/Sharp.Disposable.svg)](https://www.nuget.org/packages/Sharp.Disposable)\n[![NuGet](https://img.shields.io/nuget/dt/Sharp.Disposable.svg)](https://www.nuget.org/packages/Sharp.Disposable)\n\n- **Stable:**     in production for years with no reported defects.\n- **Tested:**     100% coverage by automated tests.\n- **Documented:** IntelliSense on everything.\n\n## Overview\n\nThis package provides the following types in the `Sharp.Disposable` namespace:\n\nName             | Description\n-----------------|------------\n`Disposable`     | Base class for any disposable object.\u003cbr\u003e– Thread-safe; dispose from any thread.\u003cbr\u003e– Guarantees that disposal happens only once.\u003cbr\u003e– Provides an `IsDisposed` property.\u003cbr\u003e– Provides a `RequireNotDisposed()` helper method.\n`DisposableBox`  | Generic, mutable box that can hold a single disposable object.\u003cbr\u003e– The object can be *owned* or *borrowed*.\u003cbr\u003e– Disposes an owned object when another is placed in the box.\u003cbr\u003e– Disposes an owned object when the box itself is disposed.\n`DisposablePool` | Collects multiple disposable objects, disposing them when the pool itself is disposed.\n`Finalizer`      | Methods to force object finalization.\n\n## Usage\n\n```csharp\nusing Sharp.Disposable;\n\npublic class Foo : Disposable\n{\n    private SomeDisposable _bar; // a managed resource\n\n    // ...\n    \n    protected override bool Dispose(bool managed)\n    {\n        // Check if already disposed\n        if (!base.Dispose(managed))\n            // False means nothing happened because already disposed\n            return false;\n\n        // Clean up unmanaged resources (like temp files) here\n        DeleteTemporaryFiles();\n\n        // Check if doing managed disposal too\n        if (managed)\n            // Disposed managed resources (other IDisposables) here\n            _bar.Dispose();\n\n        // True means disposal happened\n        return true;\n    }\n}\n```\n\n\u003c!--\n  Copyright 2022 Jeffrey Sharp\n\n  Permission to use, copy, modify, and distribute this software for any\n  purpose with or without fee is hereby granted, provided that the above\n  copyright notice and this permission notice appear in all copies.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n--\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharpjs%2Fsharp.disposable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharpjs%2Fsharp.disposable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharpjs%2Fsharp.disposable/lists"}