DebuggerDisplayAttribute.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. namespace System.Diagnostics
  5. {
  6. // This attribute is used to control what is displayed for the given class or field
  7. // in the data windows in the debugger. The single argument to this attribute is
  8. // the string that will be displayed in the value column for instances of the type.
  9. // This string can include text between { and } which can be either a field,
  10. // property or method (as will be documented in mscorlib). In the C# case,
  11. // a general expression will be allowed which only has implicit access to the this pointer
  12. // for the current instance of the target type. The expression will be limited,
  13. // however: there is no access to aliases, locals, or pointers.
  14. // In addition, attributes on properties referenced in the expression are not processed.
  15. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Assembly, AllowMultiple = true)]
  16. public sealed class DebuggerDisplayAttribute : Attribute
  17. {
  18. private Type _target;
  19. public DebuggerDisplayAttribute(string value)
  20. {
  21. Value = value ?? "";
  22. Name = "";
  23. Type = "";
  24. }
  25. public string Value { get; }
  26. public string Name { get; set; }
  27. public string Type { get; set; }
  28. public Type Target
  29. {
  30. get => _target;
  31. set
  32. {
  33. if (value == null)
  34. {
  35. throw new ArgumentNullException(nameof(value));
  36. }
  37. TargetTypeName = value.AssemblyQualifiedName;
  38. _target = value;
  39. }
  40. }
  41. public string TargetTypeName { get; set; }
  42. }
  43. }