Ejemplo n.º 1
0
        // Enums are tricky. We can probably use expression trees to build these delegates automatically,
        // but it's easy to generate the code for it.

        /// <summary>
        /// Retrieves a codec suitable for an enum field with the given tag.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="toInt32">A conversion function from <see cref="Int32"/> to the enum type.</param>
        /// <param name="fromInt32">A conversion function from the enum type to <see cref="Int32"/>.</param>
        /// <returns>A codec for the given tag.</returns>
        public static FieldCodec <T> ForEnum <T>(uint tag, Func <T, int> toInt32, Func <int, T> fromInt32)
        {
            return(FieldCodec.ForEnum(tag, toInt32, fromInt32, default(T)));
        }