static void write_consume_extensions()

in src/tool/cppxlang/code_writers.h [1032:1167]


    static void write_consume_extensions(writer& w, TypeDef const& type)
    {
        type_name type_name(type);

        if (type_name == "Foundation.Collections.IIterator`1")
        {
            w.write(R"(
        auto& operator++()
        {
            if (!MoveNext())
            {
                static_cast<D&>(*this) = nullptr;
            }

            return *this;
        }

        T operator*() const
        {
            return Current();
        }
)");
        }
        else if (type_name == "Foundation.Collections.IKeyValuePair`2")
        {
            w.write(R"(
        bool operator==(Foundation::Collections::IKeyValuePair<K, V> const& other) const
        {
            return Key() == other.Key() && Value() == other.Value();
        }

        bool operator!=(Foundation::Collections::IKeyValuePair<K, V> const& other) const
        {
            return !(*this == other);
        }
)");
        }
        else if (type_name == "Foundation.Collections.IMapView`2")
        {
            w.write(R"(
        auto TryLookup(param_type<K> const& key) const noexcept
        {
            if constexpr (std::is_base_of_v<Foundation::IUnknown, V>)
            {
                V result{ nullptr };
                com_ptr<xlang_error_info> error_info{
                    XLANG_SHIM(Foundation::Collections::IMapView<K, V>)->Lookup(get_abi(key), put_abi(result)),
                    take_ownership_from_abi
                };
                return result;
            }
            else
            {
                std::optional<V> result;
                V value{ empty_value<V>() };

                com_ptr<xlang_error_info> error_info{
                    XLANG_SHIM(Foundation::Collections::IMapView<K, V>)->Lookup(get_abi(key), put_abi(value)),
                    take_ownership_from_abi
                };
                if (nullptr == error_info)
                {
                    result = std::move(value);
                }

                return result;
            }
        }
)");
        }
        else if (type_name == "Foundation.Collections.IMap`2")
        {
            w.write(R"(
        auto TryLookup(param_type<K> const& key) const noexcept
        {
            if constexpr (std::is_base_of_v<Foundation::IUnknown, V>)
            {
                V result{ nullptr };
                com_ptr<xlang_error_info> error_info{
                    XLANG_SHIM(Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(result)),
                    take_ownership_from_abi
                };
                return result;
            }
            else
            {
                std::optional<V> result;
                V value{ empty_value<V>() };

                com_ptr<xlang_error_info> error_info{
                    XLANG_SHIM(Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(value)),
                    take_ownership_from_abi
                };
                if (nullptr == error_info)
                {
                    result = std::move(value);
                }

                return result;
            }
        }
)");
        }
        else if (type_name == "Foundation.IAsyncAction")
        {
            w.write(R"(        void get() const
        {
            blocking_suspend(static_cast<Foundation::IAsyncAction const&>(static_cast<D const&>(*this)));
            GetResults();
        })");
        }
        else if (type_name == "Foundation.IAsyncOperation`1")
        {
            w.write(R"(        TResult get() const
        {
            blocking_suspend(static_cast<Foundation::IAsyncOperation<TResult> const&>(static_cast<D const&>(*this)));
            return GetResults();
        })");
        }
        else if (type_name == "Foundation.IAsyncActionWithProgress`1")
        {
            w.write(R"(        void get() const
        {
            blocking_suspend(static_cast<Foundation::IAsyncActionWithProgress<TProgress> const&>(static_cast<D const&>(*this)));
            GetResults();
        })");
        }
        else if (type_name == "Foundation.IAsyncOperationWithProgress`2")
        {
            w.write(R"(        TResult get() const
        {
            blocking_suspend(static_cast<Foundation::IAsyncOperationWithProgress<TResult, TProgress> const&>(static_cast<D const&>(*this)));
            return GetResults();
        })");
        }
    }