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 2 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
1 change: 1 addition & 0 deletions IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\IDisposableAnalyzers\IDisposableAnalyzers.csproj" />
<ProjectReference Include="..\IDisposableAnnotations\IDisposableAnnotations.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt),
typeof(Gu.Roslyn.CodeFixExtensions.Parse),
typeof(Stubs.Extensions),
typeof(IDisposableAnnotations.DisposeAttribute),
typeof(NUnit.Framework.Assert))]
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDisposableAnnotations", "IDisposableAnnotations\IDisposableAnnotations.csproj", "{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}"
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
{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions IDisposableAnnotations/DisposeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IDisposableAnnotations
{
using System;

/// <summary>
/// The return value should be disposed by caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
public class DisposeAttribute : Attribute
{
}
}
12 changes: 12 additions & 0 deletions IDisposableAnnotations/DisposesAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IDisposableAnnotations
{
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
{
}
}
12 changes: 12 additions & 0 deletions IDisposableAnnotations/DontDisposeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IDisposableAnnotations
{
using System;

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

Choose a reason for hiding this comment

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

I'd spell it out. DoNotDispose 😉

{
}
}
5 changes: 5 additions & 0 deletions IDisposableAnnotations/IDisposableAnnotations.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>
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 IDisposableAnnotations;

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="..\IDisposableAnnotations\IDisposableAnnotations.csproj" />
</ItemGroup>
</Project>