Skip to content

Commit 489038d

Browse files
committed
C# 7 goodness and early-exiting startup when debugging
1 parent 76f3914 commit 489038d

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

RetailCoder.VBE/Extension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ private void Startup()
221221
catch (Exception e)
222222
{
223223
_logger.Log(LogLevel.Fatal, e, "Startup sequence threw an unexpected exception.");
224-
//throw; // <<~ uncomment to crash the process
224+
#if DEBUG
225+
throw; // <<~ uncomment to crash the process
226+
#endif
225227
}
226228
}
227229

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,8 @@ public sealed class RubberduckParserState : IDisposable, IDeclarationFinderProvi
7171

7272
public RubberduckParserState(IVBE vbe, IDeclarationFinderFactory declarationFinderFactory)
7373
{
74-
if(vbe == null)
75-
{
76-
throw new ArgumentNullException(nameof(vbe));
77-
}
78-
if (declarationFinderFactory == null)
79-
{
80-
throw new ArgumentNullException(nameof(declarationFinderFactory));
81-
}
82-
83-
_vbe = vbe;
84-
_declarationFinderFactory = declarationFinderFactory;
74+
_vbe = vbe ?? throw new ArgumentNullException(nameof(vbe));
75+
_declarationFinderFactory = declarationFinderFactory ?? throw new ArgumentNullException(nameof(declarationFinderFactory));
8576

8677
var values = Enum.GetValues(typeof(ParserState));
8778
foreach (var value in values)
@@ -436,12 +427,12 @@ private ParserState OverallParserStateFromModuleStates()
436427
{
437428
if (moduleState != moduleStates[0])
438429
{
439-
state = default(ParserState);
430+
state = default;
440431
break;
441432
}
442433
}
443434

444-
if (state != default(ParserState))
435+
if (state != default)
445436
{
446437
// if all modules are in the same state, we have our result.
447438
return state;
@@ -600,8 +591,7 @@ public List<IAnnotation> AllAnnotations
600591

601592
public IEnumerable<IAnnotation> GetModuleAnnotations(QualifiedModuleName module)
602593
{
603-
ModuleState result;
604-
if (_moduleStates.TryGetValue(module, out result))
594+
if (_moduleStates.TryGetValue(module, out var result))
605595
{
606596
return result.Annotations;
607597
}
@@ -732,8 +722,7 @@ public void ClearStateCache(string projectId, bool notifyStateChanged = false)
732722
{
733723
// store project module name
734724
var qualifiedModuleName = moduleState.Key;
735-
ModuleState state;
736-
if (_moduleStates.TryRemove(qualifiedModuleName, out state))
725+
if (_moduleStates.TryRemove(qualifiedModuleName, out var state))
737726
{
738727
state.Dispose();
739728
}
@@ -943,8 +932,7 @@ public bool IsNewOrModified(IVBComponent component)
943932

944933
public bool IsNewOrModified(QualifiedModuleName key)
945934
{
946-
ModuleState moduleState;
947-
if (_moduleStates.TryGetValue(key, out moduleState))
935+
if (_moduleStates.TryGetValue(key, out var moduleState))
948936
{
949937
// existing/modified
950938
return moduleState.IsNew || key.ContentHashCode != moduleState.ModuleContentHashCode;
@@ -964,8 +952,7 @@ public void RemoveBuiltInDeclarations(IReference reference)
964952
var projectName = reference.Name;
965953
var key = new QualifiedModuleName(projectName, reference.FullPath, projectName);
966954
ClearAsTypeDeclarationPointingToReference(key);
967-
ModuleState moduleState;
968-
if (_moduleStates.TryRemove(key, out moduleState))
955+
if (_moduleStates.TryRemove(key, out var moduleState))
969956
{
970957
moduleState?.Dispose();
971958
Logger.Warn("Could not remove declarations for removed reference '{0}' ({1}).", reference.Name, QualifiedModuleName.GetProjectId(reference));

0 commit comments

Comments
 (0)