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 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
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.GivesOwnershipAttribute),
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
8 changes: 3 additions & 5 deletions IDisposableAnalyzers/IDisposableAnalyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
</PropertyGroup>

<PropertyGroup>
<Version>2.0.5.0</Version>
<Version>2.0.6.0</Version>
<Authors>Johan Larsson, milleniumbug</Authors>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Description>IDISP004 warn on explicit discard.
IDISP017 when disposing in finally.
IDISP003 when assigning in loop.
</Description>
<Description>BUGFIX: IDISP003 figure out when assigned in switch.
IDISP003 should not warn when assigning out parameter in if return.</Description>
<PackageTags>IDisposable Roslyn Diagnostic Analyzer DotnetAnalyzers</PackageTags>
<PackageReleaseNotes>
BUGFIX: Handle extension methods in binary references better.
Expand Down
6 changes: 2 additions & 4 deletions IDisposableAnalyzers/paket.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
type project
include-referenced-projects true
developmentDependency true
projectUrl https://github.com/DotNetAnalyzers/IDisposableAnalyzers
licenseUrl http://opensource.org/licenses/MIT

releaseNotes
IDISP004 warn on explicit discard.
IDISP017 when disposing in finally.
IDISP003 when assigning in loop.
BUGFIX: IDISP003 figure out when assigned in switch.
IDISP003 should not warn when assigning out parameter in if return.

excludedgroups
Main
Expand Down
12 changes: 12 additions & 0 deletions IDisposableAnnotations/GivesOwnershipAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IDisposableAnnotations
{
using System;

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

/// <summary>
/// The return value must not be disposed by the caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class KeepsOwnershipAttribute : Attribute
{
}
}
12 changes: 12 additions & 0 deletions IDisposableAnnotations/TakesOwnershipAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IDisposableAnnotations
{
using System;

/// <summary>
/// The ownership of instance is transferred and the receiver is responsible for disposing.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class TakesOwnershipAttribute : Attribute
Copy link

Choose a reason for hiding this comment

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

{
}
}
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 2.0.6
* BUGFIX: IDISP003 figure out when assigned in switch.
* IDISP003 should not warn when assigning out parameter in if return.

#### 2.0.5
* IDISP004 warn on explicit discard.
* IDISP017 when disposing in finally.
Expand Down
20 changes: 20 additions & 0 deletions ValidCode/IWithAnnotations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ValidCode
{
using System;
using IDisposableAnnotations;

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

bool TryCreate([GivesOwnership]out IDisposable disposable);

[return: KeepsOwnership]
IDisposable GetOrCreate();

bool TryGet([KeepsOwnership]out IDisposable disposable);

void Add([TakesOwnership] 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>