/// <inheritdoc/> public void WriteYaml(IEmitter emitter, object value, Type type) { emitter.Emit(new Scalar(null, NeonHelper.EnumToString(type, value))); }
/// <summary> /// Attempts to parse an environment variable as an eumeration, writting messages /// to the associated logger if one was passed to the constructor. /// </summary> /// <typeparam name="TEnum">The desired enumeration type.</typeparam> /// <param name="variable">The variable name.</param> /// <param name="defaultInput">The default value.</param> /// <param name="required">Optionally specifies that the variable is required to exist.</param> /// <param name="validator"> /// Optional validation function to be called to verify that the parsed variable /// value is valid. This should return <c>null</c> for valid values and an error /// message for invalid ones. /// </param> /// <returns>The parsed value.</returns> /// <exception cref="KeyNotFoundException">Thrown if the variable does not exists and <paramref name="required"/>=<c>true</c>.</exception> /// <exception cref="FormatException">Thrown if the variable could not be parsed or the <paramref name="validator"/> returned an error.</exception> public TEnum Get <TEnum>(string variable, TEnum defaultInput, bool required = false, Validator <TEnum> validator = null) where TEnum : Enum { return(Parse <TEnum>(variable, NeonHelper.EnumToString(defaultInput), EnumParser, required, validator)); }