-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Preserve DebuggerTypeProxyAttribute classes #39126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace System.Diagnostics | ||
| { | ||
| [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] | ||
| public sealed class DebuggerTypeProxyAttribute : Attribute | ||
| { | ||
| private Type? _target; | ||
|
|
||
| public DebuggerTypeProxyAttribute(Type type) | ||
| public DebuggerTypeProxyAttribute( | ||
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) | ||
| { | ||
| if (type == null) | ||
| { | ||
|
|
@@ -18,11 +21,15 @@ public DebuggerTypeProxyAttribute(Type type) | |
| ProxyTypeName = type.AssemblyQualifiedName!; | ||
| } | ||
|
|
||
| public DebuggerTypeProxyAttribute(string typeName) | ||
| public DebuggerTypeProxyAttribute( | ||
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] string typeName) | ||
| { | ||
| ProxyTypeName = typeName; | ||
| } | ||
|
|
||
| // The Proxy is only invoked by the debugger, so it needs to have its | ||
| // members preserved | ||
| [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] | ||
|
||
| public string ProxyTypeName { get; } | ||
|
|
||
| public Type? Target | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
|
|
||
| /// <summary> | ||
| /// Tests that types used by DebuggerTypeProxyAttribute are not trimmed out | ||
| /// when Debugger.IsSupported is true (the default). | ||
| /// </summary> | ||
| class Program | ||
| { | ||
| static int Main(string[] args) | ||
| { | ||
| MyClass myClass = new MyClass() { Name = "trimmed" }; | ||
| MyClassWithProxyString myClassWithString = new MyClassWithProxyString() { Name = "trimmed" }; | ||
|
|
||
| Type[] allTypes = typeof(MyClass).Assembly.GetTypes(); | ||
| bool foundDebuggerProxy = false; | ||
| bool foundStringDebuggerProxy = false; | ||
| for (int i = 0; i < allTypes.Length; i++) | ||
| { | ||
| Type currentType = allTypes[i]; | ||
| if (currentType.FullName == "Program+MyClass+DebuggerProxy" && | ||
| currentType.GetProperties().Length == 1 && | ||
| currentType.GetConstructors().Length == 1) | ||
| { | ||
| foundDebuggerProxy = true; | ||
| } | ||
| else if (currentType.FullName == "Program+MyClassWithProxyStringProxy" && | ||
| currentType.GetProperties().Length == 1 && | ||
| currentType.GetConstructors().Length == 1) | ||
| { | ||
| foundStringDebuggerProxy = true; | ||
| } | ||
| } | ||
|
|
||
| return foundDebuggerProxy && foundStringDebuggerProxy ? 100 : -1; | ||
| } | ||
|
|
||
| [DebuggerTypeProxy(typeof(DebuggerProxy))] | ||
eerhardt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class MyClass | ||
| { | ||
| public string Name { get; set; } | ||
|
|
||
| private class DebuggerProxy | ||
| { | ||
| private MyClass _instance; | ||
|
|
||
| public DebuggerProxy(MyClass instance) | ||
| { | ||
| _instance = instance; | ||
| } | ||
|
|
||
| public string DebuggerName => _instance.Name + " Proxy"; | ||
| } | ||
| } | ||
|
|
||
| [DebuggerTypeProxy("Program+MyClassWithProxyStringProxy")] | ||
| public class MyClassWithProxyString | ||
| { | ||
| public string Name { get; set; } | ||
| } | ||
|
|
||
| internal class MyClassWithProxyStringProxy | ||
| { | ||
| private MyClassWithProxyString _instance; | ||
|
|
||
| public MyClassWithProxyStringProxy(MyClassWithProxyString instance) | ||
| { | ||
| _instance = instance; | ||
| } | ||
|
|
||
| public string DebuggerName => _instance.Name + " StringProxy"; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.