/ILSpy/TreeNodes/Analyzer/AnalyzedMethodTreeNode.cs

http://github.com/icsharpcode/ILSpy · C# · 72 lines · 45 code · 10 blank · 17 comment · 8 complexity · bf763942354be11c69fc23d4e2f1f1fe 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 Mono.Cecil;
  20. namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
  21. {
  22. internal class AnalyzedMethodTreeNode : AnalyzerEntityTreeNode
  23. {
  24. private readonly MethodDefinition analyzedMethod;
  25. private readonly string prefix;
  26. public AnalyzedMethodTreeNode(MethodDefinition analyzedMethod, string prefix = "")
  27. {
  28. if (analyzedMethod == null)
  29. throw new ArgumentNullException("analyzedMethod");
  30. this.analyzedMethod = analyzedMethod;
  31. this.prefix = prefix;
  32. this.LazyLoading = true;
  33. }
  34. public override object Icon
  35. {
  36. get { return MethodTreeNode.GetIcon(analyzedMethod); }
  37. }
  38. public override object Text
  39. {
  40. get
  41. {
  42. return prefix + Language.TypeToString(analyzedMethod.DeclaringType, true) + "." + MethodTreeNode.GetText(analyzedMethod, Language);
  43. }
  44. }
  45. protected override void LoadChildren()
  46. {
  47. if (analyzedMethod.HasBody)
  48. this.Children.Add(new AnalyzedMethodUsesTreeNode(analyzedMethod));
  49. if (analyzedMethod.IsVirtual && !(analyzedMethod.IsNewSlot && analyzedMethod.IsFinal))
  50. this.Children.Add(new AnalyzedVirtualMethodUsedByTreeNode(analyzedMethod));
  51. else
  52. this.Children.Add(new AnalyzedMethodUsedByTreeNode(analyzedMethod));
  53. if (AnalyzedMethodOverridesTreeNode.CanShow(analyzedMethod))
  54. this.Children.Add(new AnalyzedMethodOverridesTreeNode(analyzedMethod));
  55. if (AnalyzedInterfaceMethodImplementedByTreeNode.CanShow(analyzedMethod))
  56. this.Children.Add(new AnalyzedInterfaceMethodImplementedByTreeNode(analyzedMethod));
  57. }
  58. public override MemberReference Member {
  59. get { return analyzedMethod; }
  60. }
  61. }
  62. }