public class Actions
{
private delegate void ChangeState(License license, NewLicenseState newState, string reason);
private IDictionary
public Actions()
{
actions = new Dictionary
actions.Add(
ChangeToExpiredBlockedStateException,
delegate(License license, strin reason)
{
license.ChangeState(5, reason);
});
actions.Add(
ChangeToExpiredInUseStateException,
delegate(License license, strin reason)
{
license.ChangeState(4, reason);
});
}
public ChangeState this[LicenseException exception]
{
get
{
if (this.actions.ContainsKey(exception.GetType())
{
return this.actions[exception.GetType()];
}
Assert.ThrowInvalidOperationException(message, params args);
}
}
}
And then use it as follows:
new Actions()[ex.GetType()](license, ex.Message);
Yeah, I wrote this code as a sample. To bad it seems too complicated. Although I like it, they do not.
No comments:
Post a Comment