PageRenderTime 35ms CodeModel.GetById 17ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

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