This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add MemberNotNullWhenAttribute * Fix file header
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
JustArchiNET.Madness/MemberNotNullWhenMadness/MemberNotNullWhenAttribute.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,67 @@ | ||
// _ __ __ | ||
// ___ ___ ___ _ __ __| | __ _ | \/ | | ||
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| | | ||
// \__ \\__ \| __/| | | || (_| || (_| || | | | | ||
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_| | ||
// | | ||
// Copyright 2021-2022 Łukasz "JustArchi" Domeradzki | ||
// Contact: [email protected] | ||
// | | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using JetBrains.Annotations; | ||
using JustArchiNET.Madness.Helpers; | ||
|
||
namespace JustArchiNET.Madness.MemberNotNullWhenMadness; | ||
|
||
[MadnessType(EMadnessType.Implementation)] | ||
[PublicAPI] | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] | ||
public sealed class MemberNotNullWhenAttribute : Attribute { | ||
/// <summary>Gets the return value condition.</summary> | ||
[MadnessType(EMadnessType.Implementation)] | ||
public bool ReturnValue { get; } | ||
|
||
/// <summary>Gets field or property member names.</summary> | ||
[MadnessType(EMadnessType.Implementation)] | ||
public string[] Members { get; } | ||
|
||
/// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary> | ||
/// <param name="returnValue"> | ||
/// The return value condition. If the method returns this value, the associated parameter will not be null. | ||
/// </param> | ||
/// <param name="member"> | ||
/// The field or property member that is promised to be not-null. | ||
/// </param> | ||
[MadnessType(EMadnessType.Implementation)] | ||
public MemberNotNullWhenAttribute(bool returnValue, string member) | ||
{ | ||
ReturnValue = returnValue; | ||
Members = new[] { member }; | ||
} | ||
|
||
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary> | ||
/// <param name="returnValue"> | ||
/// The return value condition. If the method returns this value, the associated parameter will not be null. | ||
/// </param> | ||
/// <param name="members"> | ||
/// The list of field and property members that are promised to be not-null. | ||
/// </param> | ||
[MadnessType(EMadnessType.Implementation)] | ||
public MemberNotNullWhenAttribute(bool returnValue, params string[] members) | ||
{ | ||
ReturnValue = returnValue; | ||
Members = members; | ||
} | ||
} |