Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDisposableAnnotations #130

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 DisposableAnnotations/DisposableAnnotations.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
</PropertyGroup>
</Project>
12 changes: 12 additions & 0 deletions DisposableAnnotations/DisposeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DisposableAnnotations
{
using System;

/// <summary>
/// The return value should be disposed by caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
public class DisposeAttribute : Attribute
Copy link

@jnm2 jnm2 Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just spaghetti: [OwnedByCaller]? [CallerOwns]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having Disposable somewhere in the name is good.

{
}
}
12 changes: 12 additions & 0 deletions DisposableAnnotations/DisposesAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DisposableAnnotations
{
using System;

/// <summary>
/// The containing method owns the instance and is responsible for disposing it.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class DisposesAttribute : Attribute
Copy link

@jnm2 jnm2 Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To come up with an alternative for the sake of discussion: [BecomesOwner]? [TransferOwnership]?

[Disposes] sounds like the method itself does the disposing. Is that always the case or might it be saved for the class to dispose later?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to make it a verb to be more explicit for the callers. MustBeDisposed and NotDisposable?

{
}
}
12 changes: 12 additions & 0 deletions DisposableAnnotations/DontDisposeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DisposableAnnotations
{
using System;

/// <summary>
/// The return value should not be disposed by caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
public class DontDisposeAttribute : Attribute
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the contraction. [NotOwnedByCaller]?

{
}
}
6 changes: 6 additions & 0 deletions IDisposableAnalyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stubs", "Stubs\Stubs.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidCode", "ValidCode\ValidCode.csproj", "{C6A235B1-A780-43D5-BA1F-E31861C019F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisposableAnnotations", "DisposableAnnotations\DisposableAnnotations.csproj", "{D147BB16-EB5A-4412-B501-E0DD0AFDA353}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -92,6 +94,10 @@ Global
{C6A235B1-A780-43D5-BA1F-E31861C019F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.Build.0 = Release|Any CPU
{D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions ValidCode/IWithAnnotations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ValidCode
{
using System;
using DisposableAnnotations;

public interface IWithAnnotations
{
[return:Dispose]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisposedByCaller is longer but perhaps clearer?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Would MustDispose be clearer (while still short)?

IDisposable Create();

[return: DontDispose]
IDisposable GetOrCreate();

void Add([Disposes] IDisposable disposable);
}
}
4 changes: 4 additions & 0 deletions ValidCode/ValidCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
</PropertyGroup>

<Import Project="..\.paket\Paket.Restore.targets" />

<ItemGroup>
<ProjectReference Include="..\DisposableAnnotations\DisposableAnnotations.csproj" />
</ItemGroup>
</Project>