---
source: boltffi_bindgen/src/render/csharp/templates.rs
expression: template.render().unwrap()
---
// <auto-generated>
// This file was generated by BoltFFI. Do not edit.
// </auto-generated>
#nullable enable

using System;

namespace Demo
{
    public enum MathError : int
    {
        DivisionByZero = 0,
        NegativeInput = 1,
        Overflow = 2
    }

    internal static class MathErrorWire
    {
        internal const int WireEncodedSize = 4;

        internal static MathError Decode(WireReader reader) =>
            reader.ReadI32() switch
            {
                0 => MathError.DivisionByZero,
                1 => MathError.NegativeInput,
                2 => MathError.Overflow,
                int tag => throw new InvalidOperationException($"Unknown MathError wire tag: {tag}"),
            };

        internal static void WireEncodeTo(this MathError value, WireWriter wire) =>
            wire.WriteI32(value switch
            {
                MathError.DivisionByZero => 0,
                MathError.NegativeInput => 1,
                MathError.Overflow => 2,
                _ => throw new InvalidOperationException($"Unknown MathError variant: {value}"),
            });
    }
    /// <summary>
    /// Thrown by generated wrapper methods when the Rust side returns
    /// a <c>MathError</c> as the error. The original value is
    /// exposed through <c>Error</c>; the inherited <c>Message</c>
    /// derives from it (forwarded from a <c>Message</c> field when the
    /// wrapped type has one, otherwise the value's <c>ToString()</c>).
    /// </summary>
    public sealed class MathErrorException : Exception
    {
        public MathError Error { get; }

        public MathErrorException(MathError error) : base(error.ToString())
        {
            Error = error;
        }
    }
}
