Skip to content

Commit 359615a

Browse files
authored
Merge pull request #68 from CommunityToolkit/dev/stack-trace-hidden-attribute
Add [StackTraceHidden] attribute to Diagnostics package
2 parents e9be820 + d2568f2 commit 359615a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if !NET6_0_OR_GREATER
6+
7+
namespace System.Diagnostics;
8+
9+
/// <summary>
10+
/// Removes annotated methods from the stacktrace in case an exception occurrs while they're on the stack.
11+
/// </summary>
12+
/// <remarks>
13+
/// This is a port of the attribute from the BCL in .NET 6, and it's marked as conditional so that it will
14+
/// be removed for package builds that are released on NuGet. This attribute is only used internally to
15+
/// avoid having to clutter the codebase with many compiler directive switches to check for this API.
16+
/// </remarks>
17+
[Conditional("DEBUG")]
18+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)]
19+
internal sealed class StackTraceHiddenAttribute : Attribute
20+
{
21+
}
22+
23+
#endif

CommunityToolkit.Diagnostics/Internals/Guard.ThrowHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics;
67
using System.Diagnostics.CodeAnalysis;
78

89
namespace CommunityToolkit.Diagnostics;
@@ -15,6 +16,7 @@ public static partial class Guard
1516
/// <summary>
1617
/// Helper methods to efficiently throw exceptions.
1718
/// </summary>
19+
[StackTraceHidden]
1820
private static partial class ThrowHelper
1921
{
2022
/// <summary>

0 commit comments

Comments
 (0)