You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.7 KiB

14 years ago
  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Reflection.Metadata;
  20. using System.Windows.Media;
  21. using ICSharpCode.Decompiler;
  22. namespace ICSharpCode.ILSpy.TreeNodes
  23. {
  24. using ICSharpCode.Decompiler.TypeSystem;
  25. /// <summary>
  26. /// Represents an event in the TreeView.
  27. /// </summary>
  28. public sealed class EventTreeNode : ILSpyTreeNode, IMemberTreeNode
  29. {
  30. public EventTreeNode(IEvent @event)
  31. {
  32. this.EventDefinition = @event ?? throw new ArgumentNullException(nameof(@event));
  33. if (@event.CanAdd)
  34. this.Children.Add(new MethodTreeNode(@event.AddAccessor));
  35. if (@event.CanRemove)
  36. this.Children.Add(new MethodTreeNode(@event.RemoveAccessor));
  37. if (@event.CanInvoke)
  38. this.Children.Add(new MethodTreeNode(@event.InvokeAccessor));
  39. //foreach (var m in ev.OtherMethods)
  40. // this.Children.Add(new MethodTreeNode(m));
  41. }
  42. public IEvent EventDefinition { get; }
  43. public override object Text => GetText(GetEventDefinition(), this.Language) + EventDefinition.MetadataToken.ToSuffixString();
  44. private IEvent GetEventDefinition()
  45. {
  46. return ((MetadataModule)EventDefinition.ParentModule.PEFile
  47. ?.GetTypeSystemWithCurrentOptionsOrNull()
  48. ?.MainModule)?.GetDefinition((EventDefinitionHandle)EventDefinition.MetadataToken) ?? EventDefinition;
  49. }
  50. public static object GetText(IEvent ev, Language language)
  51. {
  52. return language.EventToString(ev, false, false, false);
  53. }
  54. public override object Icon => GetIcon(GetEventDefinition());
  55. public static ImageSource GetIcon(IEvent @event)
  56. {
  57. return Images.GetIcon(MemberIcon.Event, MethodTreeNode.GetOverlayIcon(@event.Accessibility), @event.IsStatic);
  58. }
  59. public override FilterResult Filter(FilterSettings settings)
  60. {
  61. if (settings.ShowApiLevel == ApiVisibility.PublicOnly && !IsPublicAPI)
  62. return FilterResult.Hidden;
  63. if (settings.SearchTermMatches(EventDefinition.Name) && (settings.ShowApiLevel == ApiVisibility.All || settings.Language.ShowMember(EventDefinition)))
  64. return FilterResult.Match;
  65. else
  66. return FilterResult.Hidden;
  67. }
  68. public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
  69. {
  70. language.DecompileEvent(EventDefinition, output, options);
  71. }
  72. public override bool IsPublicAPI {
  73. get {
  74. switch (GetEventDefinition().Accessibility)
  75. {
  76. case Accessibility.Public:
  77. case Accessibility.ProtectedOrInternal:
  78. case Accessibility.Protected:
  79. return true;
  80. default:
  81. return false;
  82. }
  83. }
  84. }
  85. IEntity IMemberTreeNode.Member => EventDefinition;
  86. public override string ToString()
  87. {
  88. return EventDefinition.Name;
  89. }
  90. }
  91. }