-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add [MemberNotNull] and [MemberNotNullWhen] support
- Loading branch information
1 parent
05b952d
commit 3a5c6b7
Showing
5 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...isionLabs.ReferenceAssemblyAnnotator/WellKnownTypes+MemberNotNullAttributeProvidedType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
namespace TunnelVisionLabs.ReferenceAssemblyAnnotator | ||
{ | ||
using System; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Rocks; | ||
|
||
internal partial class WellKnownTypes | ||
{ | ||
private sealed class MemberNotNullAttributeProvidedType : ProvidedAttributeType | ||
{ | ||
public MemberNotNullAttributeProvidedType() | ||
: base("System.Diagnostics.CodeAnalysis", "MemberNotNullAttribute") | ||
{ | ||
} | ||
|
||
protected override void ImplementAttribute(ModuleDefinition module, TypeDefinition attribute, WellKnownTypes wellKnownTypes, CustomAttributeFactory attributeFactory) | ||
{ | ||
var constructor1 = MethodFactory.Constructor(wellKnownTypes.TypeSystem); | ||
constructor1.Parameters.Add(new ParameterDefinition("member", ParameterAttributes.None, wellKnownTypes.TypeSystem.String)); | ||
attribute.Methods.Add(constructor1); | ||
|
||
var constructor2 = MethodFactory.Constructor(wellKnownTypes.TypeSystem); | ||
constructor2.Parameters.Add(new ParameterDefinition("members", ParameterAttributes.None, wellKnownTypes.TypeSystem.String.MakeArrayType())); | ||
attribute.Methods.Add(constructor2); | ||
|
||
attribute.CustomAttributes.Add(attributeFactory.AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, inherited: false, allowMultiple: true)); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...nLabs.ReferenceAssemblyAnnotator/WellKnownTypes+MemberNotNullWhenAttributeProvidedType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
namespace TunnelVisionLabs.ReferenceAssemblyAnnotator | ||
{ | ||
using System; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Rocks; | ||
|
||
internal partial class WellKnownTypes | ||
{ | ||
private sealed class MemberNotNullWhenAttributeProvidedType : ProvidedAttributeType | ||
{ | ||
public MemberNotNullWhenAttributeProvidedType() | ||
: base("System.Diagnostics.CodeAnalysis", "MemberNotNullWhenAttribute") | ||
{ | ||
} | ||
|
||
protected override void ImplementAttribute(ModuleDefinition module, TypeDefinition attribute, WellKnownTypes wellKnownTypes, CustomAttributeFactory attributeFactory) | ||
{ | ||
var constructor1 = MethodFactory.Constructor(wellKnownTypes.TypeSystem); | ||
constructor1.Parameters.Add(new ParameterDefinition("parameterValue", ParameterAttributes.None, wellKnownTypes.TypeSystem.Boolean)); | ||
constructor1.Parameters.Add(new ParameterDefinition("member", ParameterAttributes.None, wellKnownTypes.TypeSystem.String)); | ||
attribute.Methods.Add(constructor1); | ||
|
||
var constructor2 = MethodFactory.Constructor(wellKnownTypes.TypeSystem); | ||
constructor1.Parameters.Add(new ParameterDefinition("parameterValue", ParameterAttributes.None, wellKnownTypes.TypeSystem.Boolean)); | ||
constructor2.Parameters.Add(new ParameterDefinition("members", ParameterAttributes.None, wellKnownTypes.TypeSystem.String.MakeArrayType())); | ||
attribute.Methods.Add(constructor2); | ||
|
||
attribute.CustomAttributes.Add(attributeFactory.AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, inherited: false, allowMultiple: true)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters