Programmatic method to extract file extension association with filters?

Hi, I’m using C# to automate LibreOffice to convert documents into PDFs via the export filters. Is there a nice programmatic way to assign the export filter to a particular file type extensions? Currently my code looks like this:

        switch (extension)
        {
            case ".doc":
            case ".docx":
            case ".txt":
            case ".rtf":
            case ".html":
            case ".htm":
            case ".xml":
            case ".odt":
            case ".wps":
            case ".wpd":
            case ".lwp":
                return "writer_pdf_Export";
            case ".xls":
            case ".xlsb":
            case ".xlsx":
            case ".ods":
                return "calc_pdf_Export";
            case ".ppt":
            case ".pptx":
            case ".odp":
                return "impress_pdf_Export";

            default:
                return null;
        }

Obviously LibreOffice supports much more file extension than that, but was wondering if there a way to extract it via code, rather than “hard coding” with a switch statement like this.

The method you use will vary according to platform (GNU/Linux, MacOS, Windows, etc.) and sometimes even the desktop environment (Gnome, KDE, etc.) What platform / desktop environment are you using?

@S. lock – still looking for an answer here?

This answer is not a solution, but it should hopefully point you in the right direction. The files containing the output filters can be found here or in /filter/source/config/fragments/filters/ if you download a copy of the source code. In simplistic terms you can extract a list of supported file extensions by running a regular expression over the files in this directory e.g.,

$ grep -hre "Extensions" /filter/source/config/fragments/types/ | grep -o "<value>.*</value>"

That will give you raw (non-type associated) output for all supported file types (including graphics formats) as shown in this file for v4.0.3.3. Obviously a more programmatic interrogation method would be required to pull out only document file types and in the groupings (writer, calc, etc. file types) you require. This is the general approach I would take.