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
2 changes: 1 addition & 1 deletion IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt),
typeof(Gu.Roslyn.CodeFixExtensions.Parse),
typeof(Stubs.Extensions),
typeof(IDisposableAnnotations.DisposeAttribute),
typeof(IDisposableAnnotations.MustDisposeAttribute),
typeof(NUnit.Framework.Assert))]
12 changes: 0 additions & 12 deletions IDisposableAnnotations/DisposeAttribute.cs

This file was deleted.

12 changes: 12 additions & 0 deletions IDisposableAnnotations/DonNotDisposeAttribute.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 | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class DonNotDisposeAttribute : Attribute

Choose a reason for hiding this comment

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

One too many n there. ;-)

{
}
}
12 changes: 0 additions & 12 deletions IDisposableAnnotations/DontDisposeAttribute.cs

This file was deleted.

12 changes: 12 additions & 0 deletions IDisposableAnnotations/MustDisposeAttribute.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.

Choose a reason for hiding this comment

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

Probably better if we change should to must to be consistent with the attribute's name.

/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class MustDisposeAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace IDisposableAnnotations
/// The containing method owns the instance and is responsible for disposing it.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class DisposesAttribute : Attribute
public class TransferOwnershipAttribute : Attribute
{
}
}
10 changes: 7 additions & 3 deletions ValidCode/IWithAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ namespace ValidCode

public interface IWithAnnotations
{
[return:Dispose]
[return:MustDispose]
IDisposable Create();

[return: DontDispose]
bool TryCreate([MustDispose]out IDisposable disposable);

[return: DonNotDispose]
IDisposable GetOrCreate();

void Add([Disposes] IDisposable disposable);
bool TryGet([DonNotDispose]out IDisposable disposable);

void Add([TransferOwnership] IDisposable disposable);
}
}