Skip to content

Commit ab17635

Browse files
authored
Merge pull request #3408 from MDoerner/SomeInspectionSettingsTweaks
Minor changes to handling of inspections settings.
2 parents 39a448b + da0664b commit ab17635

File tree

3 files changed

+15
-42
lines changed

3 files changed

+15
-42
lines changed

RetailCoder.VBE/Settings/CodeInspectionSettings.cs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ public CodeInspectionSetting GetSetting<TInspection>() where TInspection : IInsp
4343
?? GetSetting(typeof(TInspection));
4444
}
4545

46-
public CodeInspectionSetting GetSetting(Type inspection)
46+
public CodeInspectionSetting GetSetting(Type inspectionType)
4747
{
4848
try
4949
{
50-
var proto = Convert.ChangeType(Activator.CreateInstance(inspection), inspection);
51-
var existing = CodeInspections.FirstOrDefault(s => proto.GetType().ToString().Equals(s.Name));
52-
if (existing != null) return existing;
50+
var existing = CodeInspections.FirstOrDefault(s => inspectionType.ToString().Equals(s.Name));
51+
if (existing != null)
52+
{
53+
return existing;
54+
}
55+
var proto = Convert.ChangeType(Activator.CreateInstance(inspectionType), inspectionType);
5356
var setting = new CodeInspectionSetting(proto as IInspectionModel);
5457
CodeInspections.Add(setting);
5558
return setting;
@@ -80,37 +83,15 @@ public class CodeInspectionSetting : IInspectionModel
8083
[XmlIgnore]
8184
public string Description
8285
{
83-
get
84-
{
85-
if (_description == null)
86-
{
87-
_description = InspectionsUI.ResourceManager.GetString(Name + "Name");
88-
}
89-
return _description;
90-
}
91-
set
92-
{
93-
_description = value;
94-
}
86+
get => _description ?? (_description = InspectionsUI.ResourceManager.GetString(Name + "Name"));
87+
set => _description = value;
9588
}// not serialized because culture-dependent
9689

9790
[XmlIgnore]
98-
public string LocalizedName
99-
{
100-
get
101-
{
102-
return InspectionsUI.ResourceManager.GetString(Name + "Name", CultureInfo.CurrentUICulture);
103-
}
104-
} // not serialized because culture-dependent
91+
public string LocalizedName => InspectionsUI.ResourceManager.GetString(Name + "Name", CultureInfo.CurrentUICulture); // not serialized because culture-dependent
10592

10693
[XmlIgnore]
107-
public string AnnotationName
108-
{
109-
get
110-
{
111-
return Name.Replace("Inspection", string.Empty);
112-
}
113-
}
94+
public string AnnotationName => Name.Replace("Inspection", string.Empty);
11495

11596
[XmlIgnore]
11697
public CodeInspectionSeverity DefaultSeverity { get; private set; }
@@ -119,13 +100,7 @@ public string AnnotationName
119100
public CodeInspectionSeverity Severity { get; set; }
120101

121102
[XmlIgnore]
122-
public string Meta
123-
{
124-
get
125-
{
126-
return InspectionsUI.ResourceManager.GetString(Name + "Meta", CultureInfo.CurrentUICulture);
127-
}
128-
}
103+
public string Meta => InspectionsUI.ResourceManager.GetString(Name + "Meta", CultureInfo.CurrentUICulture);
129104

130105
[XmlIgnore]
131106
// ReSharper disable once UnusedMember.Global; used in string literal to define collection groupings
@@ -134,7 +109,7 @@ public string Meta
134109
[XmlIgnore]
135110
public string SeverityLabel
136111
{
137-
get { return InspectionsUI.ResourceManager.GetString("CodeInspectionSeverity_" + Severity, CultureInfo.CurrentUICulture); }
112+
get => InspectionsUI.ResourceManager.GetString("CodeInspectionSeverity_" + Severity, CultureInfo.CurrentUICulture);
138113
set
139114
{
140115
foreach (var severity in Enum.GetValues(typeof(CodeInspectionSeverity)))

Rubberduck.Inspections/Concrete/AssignedByValParameterInspection.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public sealed class AssignedByValParameterInspection : InspectionBase
1414
{
1515
public AssignedByValParameterInspection(RubberduckParserState state)
1616
: base(state)
17-
{
18-
Severity = DefaultSeverity;
19-
}
17+
{ }
2018

2119
public override Type Type => typeof(AssignedByValParameterInspection);
2220

Rubberduck.Inspections/Inspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private void WalkTrees(CodeInspectionSettings settings, RubberduckParserState st
171171

172172
private bool IsDisabled(CodeInspectionSettings config, IInspection inspection)
173173
{
174-
var setting = config.GetSetting(inspection.GetType());
174+
var setting = config.GetSetting(inspection.Type);
175175
return setting != null && setting.Severity == CodeInspectionSeverity.DoNotShow;
176176
}
177177

0 commit comments

Comments
 (0)