/ILSpy/TreeNodes/Analyzer/AnalyzedPropertyTreeNode.cs

http://github.com/icsharpcode/ILSpy · C# · 92 lines · 63 code · 11 blank · 18 comment · 12 complexity · 50b45e82213d9b93d8a302f2ac3179fd MD5 · raw file

  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 ICSharpCode.Decompiler;
  20. using Mono.Cecil;
  21. namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
  22. {
  23. internal sealed class AnalyzedPropertyTreeNode : AnalyzerEntityTreeNode
  24. {
  25. private readonly PropertyDefinition analyzedProperty;
  26. private readonly bool isIndexer;
  27. private readonly string prefix;
  28. public AnalyzedPropertyTreeNode(PropertyDefinition analyzedProperty, string prefix = "")
  29. {
  30. if (analyzedProperty == null)
  31. throw new ArgumentNullException("analyzedProperty");
  32. this.isIndexer = analyzedProperty.IsIndexer();
  33. this.analyzedProperty = analyzedProperty;
  34. this.prefix = prefix;
  35. this.LazyLoading = true;
  36. }
  37. public override object Icon
  38. {
  39. get { return PropertyTreeNode.GetIcon(analyzedProperty, isIndexer); }
  40. }
  41. public override object Text
  42. {
  43. get
  44. {
  45. // TODO: This way of formatting is not suitable for properties which explicitly implement interfaces.
  46. return prefix + Language.TypeToString(analyzedProperty.DeclaringType, true) + "." + PropertyTreeNode.GetText(analyzedProperty, Language, isIndexer);
  47. }
  48. }
  49. protected override void LoadChildren()
  50. {
  51. if (analyzedProperty.GetMethod != null)
  52. this.Children.Add(new AnalyzedPropertyAccessorTreeNode(analyzedProperty.GetMethod, "get"));
  53. if (analyzedProperty.SetMethod != null)
  54. this.Children.Add(new AnalyzedPropertyAccessorTreeNode(analyzedProperty.SetMethod, "set"));
  55. foreach (var accessor in analyzedProperty.OtherMethods)
  56. this.Children.Add(new AnalyzedPropertyAccessorTreeNode(accessor, null));
  57. if (AnalyzedPropertyOverridesTreeNode.CanShow(analyzedProperty))
  58. this.Children.Add(new AnalyzedPropertyOverridesTreeNode(analyzedProperty));
  59. if (AnalyzedInterfacePropertyImplementedByTreeNode.CanShow(analyzedProperty))
  60. this.Children.Add(new AnalyzedInterfacePropertyImplementedByTreeNode(analyzedProperty));
  61. }
  62. public static AnalyzerTreeNode TryCreateAnalyzer(MemberReference member)
  63. {
  64. if (CanShow(member))
  65. return new AnalyzedPropertyTreeNode(member as PropertyDefinition);
  66. else
  67. return null;
  68. }
  69. public static bool CanShow(MemberReference member)
  70. {
  71. var property = member as PropertyDefinition;
  72. if (property == null)
  73. return false;
  74. return !MainWindow.Instance.CurrentLanguage.ShowMember(property.GetMethod ?? property.SetMethod)
  75. || AnalyzedPropertyOverridesTreeNode.CanShow(property);
  76. }
  77. public override MemberReference Member {
  78. get { return analyzedProperty; }
  79. }
  80. }
  81. }