forked from codecadwallader/codemaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeItemProperty.cs
More file actions
116 lines (90 loc) · 3.89 KB
/
CodeItemProperty.cs
File metadata and controls
116 lines (90 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using EnvDTE;
using EnvDTE80;
using SteveCadwallader.CodeMaid.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SteveCadwallader.CodeMaid.Model.CodeItems
{
/// <summary>
/// The representation of a code property.
/// </summary>
public class CodeItemProperty : BaseCodeItemElement, ICodeItemComplexity, ICodeItemParameters, IInterfaceItem
{
#region Fields
private readonly Lazy<int> _complexity;
private readonly Lazy<bool> _isExplicitInterfaceImplementation;
private readonly Lazy<bool> _isIndexer;
private readonly Lazy<IEnumerable<CodeParameter>> _parameters;
#endregion Fields
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CodeItemProperty" /> class.
/// </summary>
public CodeItemProperty()
{
// Make exceptions for explicit interface implementations - which report private access
// but really do not have a meaningful access level.
_Access = LazyTryDefault(
() => CodeProperty != null && !IsExplicitInterfaceImplementation ? CodeProperty.Access : vsCMAccess.vsCMAccessPublic);
_Attributes = LazyTryDefault(
() => CodeProperty?.Attributes);
_complexity = LazyTryDefault(
() => CodeElementHelper.CalculateComplexity(CodeElement));
_DocComment = LazyTryDefault(
() => CodeProperty?.DocComment);
_isExplicitInterfaceImplementation = LazyTryDefault(
() => CodeProperty != null && ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(CodeProperty));
_isIndexer = LazyTryDefault(
() => CodeProperty?.Parameters != null && CodeProperty.Parameters.Count > 0);
_IsStatic = LazyTryDefault(
() => CodeProperty != null &&
((CodeProperty.Getter != null && CodeProperty.Getter.IsShared) ||
(CodeProperty.Setter != null && CodeProperty.Setter.IsShared)));
_parameters = LazyTryDefault(
() => CodeProperty?.Parameters?.Cast<CodeParameter>().ToList() ?? Enumerable.Empty<CodeParameter>());
_TypeString = LazyTryDefault(
() => CodeProperty?.Type?.AsString);
}
#endregion Constructors
#region BaseCodeItem Overrides
/// <summary>
/// Gets the kind.
/// </summary>
public override KindCodeItem Kind => IsIndexer ? KindCodeItem.Indexer : KindCodeItem.Property;
/// <summary>
/// Loads all lazy initialized values immediately.
/// </summary>
public override void LoadLazyInitializedValues()
{
base.LoadLazyInitializedValues();
var c = Complexity;
var ieii = IsExplicitInterfaceImplementation;
var ii = IsIndexer;
var p = Parameters;
}
#endregion BaseCodeItem Overrides
#region Properties
/// <summary>
/// Gets or sets the underlying VSX CodeProperty.
/// </summary>
public CodeProperty2 CodeProperty { get; set; }
/// <summary>
/// Gets the complexity.
/// </summary>
public int Complexity => _complexity.Value;
/// <summary>
/// Gets a flag indicating if this property is an explicit interface implementation.
/// </summary>
public bool IsExplicitInterfaceImplementation => _isExplicitInterfaceImplementation.Value;
/// <summary>
/// Gets a flag indicating if this property is an indexer.
/// </summary>
public bool IsIndexer => _isIndexer.Value;
/// <summary>
/// Gets the parameters.
/// </summary>
public IEnumerable<CodeParameter> Parameters => _parameters.Value;
#endregion Properties
}
}