Skip to content

Commit

Permalink
Declare internal source attributes in consuming projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm2 committed Apr 10, 2020
1 parent 8466e25 commit bce35d8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion IDisposableAnalyzers/IDisposableAnalyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
</ItemGroup>

<ItemGroup>
<None Update="tools\*" Pack="true" PackagePath="" />
<None Update="tools\*;build\*" Pack="true" PackagePath="" />
<Compile Remove="build\*.cs" />
<None Include="build\*.cs" Pack="true" PackagePath="build" />

<None Include="$(OutputPath)\$(AssemblyName).dll;$(OutputPath)\Gu.Roslyn.Extensions.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions IDisposableAnalyzers/build/IDisposableAnalyzers.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>

<PropertyGroup>
<OwnershipAttributesPath Condition="'$(OwnershipAttributesPath)' == ''">$(MSBuildThisFileDirectory)OwnershipAttributes$(DefaultLanguageSourceExtension)</OwnershipAttributesPath>

<IncludeOwnershipAttributes Condition="'$(IncludeOwnershipAttributes)' == '' and Exists($(OwnershipAttributesPath))">true</IncludeOwnershipAttributes>
</PropertyGroup>

<ItemGroup Condition="'$(IncludeOwnershipAttributes)' == 'true'">
<Compile Include="$(OwnershipAttributesPath)" Visible="false" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions IDisposableAnalyzers/build/OwnershipAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace IDisposableAnnotations
{
using System;

/// <summary>
/// The return value must be disposed by the caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
internal sealed class GivesOwnershipAttribute : Attribute
{
}

/// <summary>
/// The return value must not be disposed by the caller.
/// </summary>
[AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
internal sealed class KeepsOwnershipAttribute : Attribute
{
}

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

0 comments on commit bce35d8

Please sign in to comment.