PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs

http://github.com/icsharpcode/ILSpy
C# | 74 lines | 47 code | 10 blank | 17 comment | 6 complexity | ce619da1d85d03393f78467322b4998d 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 System.Collections.Generic;
21using System.Linq;
22using System.Threading;
23using ICSharpCode.Decompiler.Ast;
24using Mono.Cecil;
25
26namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
27{
28	internal sealed class AnalyzedPropertyOverridesTreeNode : AnalyzerSearchTreeNode
29	{
30		private readonly PropertyDefinition analyzedProperty;
31
32		public AnalyzedPropertyOverridesTreeNode(PropertyDefinition analyzedProperty)
33		{
34			if (analyzedProperty == null)
35				throw new ArgumentNullException("analyzedProperty");
36
37			this.analyzedProperty = analyzedProperty;
38		}
39
40		public override object Text
41		{
42			get { return "Overridden By"; }
43		}
44
45		protected override IEnumerable<AnalyzerTreeNode> FetchChildren(CancellationToken ct)
46		{
47			var analyzer = new ScopedWhereUsedAnalyzer<AnalyzerTreeNode>(analyzedProperty, FindReferencesInType);
48			return analyzer.PerformAnalysis(ct).OrderBy(n => n.Text);
49		}
50
51		private IEnumerable<AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
52		{
53			if (!TypesHierarchyHelpers.IsBaseType(analyzedProperty.DeclaringType, type, resolveTypeArguments: false))
54				yield break;
55
56			foreach (PropertyDefinition property in type.Properties) {
57
58				if (TypesHierarchyHelpers.IsBaseProperty(analyzedProperty, property)) {
59					MethodDefinition anyAccessor = property.GetMethod ?? property.SetMethod;
60					bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot;
61					var node = new AnalyzedPropertyTreeNode(property, hidesParent ? "(hides) " : "");
62					node.Language = this.Language;
63					yield return node;
64				}
65			}
66		}
67
68		public static bool CanShow(PropertyDefinition property)
69		{
70			var accessor = property.GetMethod ?? property.SetMethod;
71			return accessor.IsVirtual && !accessor.IsFinal && !accessor.DeclaringType.IsInterface;
72		}
73	}
74}