Repository: dotnet/runtime
File: src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs (C#)

Code before:
            string paramList = _params.ToTypeListString();
            string returnList = _returns.ToTypeListString();

            if (string.IsNullOrEmpty(returnList))
                return $"(func (param {paramList}))";
            return $"(func (param {paramList}) (result {returnList}))";
        }
    }

    public abstract class WasmImportType : IWasmEncodable
    {
        public abstract int Encode(Span<byte> buffer);
        public abstract int EncodeSize();
    }

    public enum WasmExternalKind : byte
    {
        Function = 0x00,
        Table = 0x01,
        Memory = 0x02,
        Global = 0x03,
        Tag = 0x04,
        Count = 0x05 // Not actually part of the spec; used for counting kinds
    }

    public class WasmGlobalType : WasmImportType
    {
        WasmValueType _valueType;
        WasmMutabilityType _mutability;

        public WasmGlobalType(WasmValueType valueType, WasmMutabilityType mutability)
        {
            _valueType = valueType;
            _mutability = mutability;
        }

        public override int Encode(Span<byte> buffer)
        {
            buffer[0] = (byte)_valueType;
            buffer[1] = (byte)_mutability;
            return 2;
        }

        public override int EncodeSize() => 2;
    }

    public enum WasmLimitType : byte
    {
        HasMin = 0x00,
        HasMinAndMax = 0x01
    }

Review comment (suggestion):
I think these names are a little ambiguous and may be confusing later, I would prefer like WasmImportGlobalType or WasmGlobalImportType in a follow-up. Reading this stuff I'm a little confused what it represents. The code itself is fine though.

Code after:
            string paramList = _params.ToTypeListString();
            string returnList = _returns.ToTypeListString();

            if (string.IsNullOrEmpty(returnList))
                return $"(func (param {paramList}))";
            return $"(func (param {paramList}) (result {returnList}))";
        }
    }

    public abstract class WasmImportType : IWasmEncodable
    {
        public readonly WasmExternalKind Kind;
        public abstract int Encode(Span<byte> buffer);
        public abstract int EncodeSize();
        public WasmImportType(WasmExternalKind kind)
        {
            Kind = kind;
        }
    }

    public enum WasmExternalKind : byte
    {
        Function = 0x00,
        Table = 0x01,
        Memory = 0x02,
        Global = 0x03,
        Tag = 0x04,
        Count = 0x05 // Not actually part of the spec; used for counting kinds
    }

    public class WasmGlobalImportType : WasmImportType
    {
        WasmValueType _valueType;
        WasmMutabilityType _mutability;

        public WasmGlobalImportType(WasmValueType valueType, WasmMutabilityType mutability) : base (WasmExternalKind.Global)
        {
            _valueType = valueType;
            _mutability = mutability;
        }

        public override int Encode(Span<byte> buffer)
        {
            buffer[0] = (byte)_valueType;
            buffer[1] = (byte)_mutability;
            return 2;
        }

        public override int EncodeSize() => 2;
    }