Allow fallback decoder overwrite

To fix the runtime crashes in difficulty calculation components, remove
the check for pre-existing fallback registration along with
the exception. The xmldoc for the registration function has been
extended to make users aware of possible consequences of calling it.
This commit is contained in:
Bartłomiej Dach 2019-10-04 17:23:33 +02:00
parent 76c74719a4
commit 7c2c537bc9
1 changed files with 1 additions and 3 deletions

View File

@ -93,14 +93,12 @@ protected static void AddDecoder<T>(string magic, Func<string, Decoder> construc
/// <summary>
/// Registers a fallback decoder instantiation function.
/// The fallback will be returned if the first non-empty line of the decoded stream does not match any known magic.
/// Calling this method will overwrite any existing global fallback registration for type <see cref="T"/> - use with caution.
/// </summary>
/// <typeparam name="T">Type of object being decoded.</typeparam>
/// <param name="constructor">A function that constructs the fallback<see cref="Decoder"/>.</param>
protected static void SetFallbackDecoder<T>(Func<Decoder> constructor)
{
if (fallback_decoders.ContainsKey(typeof(T)))
throw new InvalidOperationException($"A fallback decoder was already added for type {typeof(T)}.");
fallback_decoders[typeof(T)] = constructor;
}
}