Permalink
Browse files

AdventureSample - move VerbRoutines to top level, remove D accessor

  • Loading branch information...
bobbymcr committed May 12, 2018
1 parent fa645e8 commit e5b1cec6b2418436d7142db443efb6caa6ee6a20
@@ -0,0 +1,37 @@
// <copyright file="VerbRoutines.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace Adventure
{
using System;
using System.Collections.Generic;
internal sealed class VerbRoutines
{
private readonly Dictionary<string, Func<VerbResult>> verbRoutines;
private readonly Func<VerbResult> unknown;
public VerbRoutines(Func<VerbResult> unknown)
{
this.verbRoutines = new Dictionary<string, Func<VerbResult>>();
this.unknown = unknown;
}
public void Add(string verb, Func<VerbResult> handler)
{
this.verbRoutines.Add(verb, handler);
}
public VerbResult Handle(string verb)
{
Func<VerbResult> verbRoutine;
if (!this.verbRoutines.TryGetValue(verb, out verbRoutine))
{
verbRoutine = this.unknown;
}
return verbRoutine();
}
}
}
@@ -6,7 +6,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Adventure;
@@ -1335,34 +1334,4 @@ private VerbResult Wear()
return VerbResult.Idle;
}
private sealed class VerbRoutines
{
private readonly Dictionary<string, Func<VerbResult>> verbRoutines;
private readonly Func<VerbResult> unknown;
public VerbRoutines(Func<VerbResult> unknown)
{
this.verbRoutines = new Dictionary<string, Func<VerbResult>>();
this.unknown = unknown;
}
public Dictionary<string, Func<VerbResult>> D => verbRoutines;
public void Add(string verb, Func<VerbResult> handler)
{
this.verbRoutines.Add(verb, handler);
}
public VerbResult Handle(string verb)
{
Func<VerbResult> verbRoutine;
if (!this.verbRoutines.TryGetValue(verb, out verbRoutine))
{
verbRoutine = this.unknown;
}
return verbRoutine();
}
}
}

0 comments on commit e5b1cec

Please sign in to comment.