[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - 19 commits - bin/distro-install-file-lists bin/distro-install-mono cli_ure/CliLibrary_cli_cppuhelper_mono.mk cli_ure/CliLibrary_cli_uno_bridge.mk cli_ure/CliLibrary_cli_ure.mk cli_ure/CustomTarget_cli_ure_assemblies.mk cli_ure/Executable_climaker_mono.mk cli_ure/Library_climaker.mk cli_ure/Library_cli_uno_glue.mk cli_ure/Library_cli_uno_unix.mk cli_ure/Library_mono_loader.mk cli_ure/Module_cli_ure.mk cli_ure/source config_host.mk.in configure.ac desktop/source external/prj Makefile.top Repository.mk scp2/InstallModule_ooo.mk scp2/InstallModule_ure.mk scp2/source solenv/gbuild unoil/CustomTarget_climaker.mk unoil/Module_unoil.mk

Petr Mladek pmladek at suse.cz
Tue Apr 30 03:14:42 PDT 2013


 Makefile.top                                                  |    1 
 Repository.mk                                                 |    3 
 bin/distro-install-file-lists                                 |    3 
 bin/distro-install-mono                                       |   96 
 cli_ure/CliLibrary_cli_cppuhelper_mono.mk                     |   32 
 cli_ure/CliLibrary_cli_uno_bridge.mk                          |   46 
 cli_ure/CliLibrary_cli_ure.mk                                 |    8 
 cli_ure/CustomTarget_cli_ure_assemblies.mk                    |   12 
 cli_ure/Executable_climaker_mono.mk                           |   20 
 cli_ure/Library_cli_uno_glue.mk                               |   33 
 cli_ure/Library_cli_uno_unix.mk                               |   35 
 cli_ure/Library_climaker.mk                                   |   26 
 cli_ure/Library_mono_loader.mk                                |   33 
 cli_ure/Module_cli_ure.mk                                     |   35 
 cli_ure/source/bootstrap/assembly.cs                          |    4 
 cli_ure/source/bootstrap/managed_bootstrap.cs                 |  106 
 cli_ure/source/bootstrap/native_glue.cxx                      |  114 
 cli_ure/source/climaker/climaker_csharp.cs                    | 3207 ++++++++++
 cli_ure/source/climaker/climaker_mono.cxx                     | 1247 +++
 cli_ure/source/mono_bridge/assemblyinfo.cs                    |    4 
 cli_ure/source/mono_bridge/binaryuno.cs                       |  159 
 cli_ure/source/mono_bridge/bridge.cs                          | 1849 +++++
 cli_ure/source/mono_bridge/cli_environment.cs                 |  171 
 cli_ure/source/mono_bridge/managed_proxy.cs                   |  444 +
 cli_ure/source/mono_bridge/mono_bridge.cxx                    |  419 +
 cli_ure/source/mono_bridge/mono_bridge.h                      |  125 
 cli_ure/source/mono_bridge/mono_proxy.cxx                     |  167 
 cli_ure/source/mono_bridge/rtl_ustring.cs                     |  105 
 cli_ure/source/mono_bridge/typeclass.cs                       |   99 
 cli_ure/source/mono_bridge/typedescription.cs                 |  612 +
 cli_ure/source/mono_bridge/uik.cs                             |   45 
 cli_ure/source/mono_bridge/uno_glue.cxx                       |   84 
 cli_ure/source/mono_bridge/uno_proxy.cs                       |  565 +
 cli_ure/source/mono_loader/mono_loader.cxx                    |  238 
 cli_ure/source/mono_loader/mono_loader.xml                    |   26 
 cli_ure/source/mono_loader/service.cxx                        |   72 
 cli_ure/source/ure/uno/util/Factory.cs                        |  180 
 cli_ure/source/ure/uno/util/ManagedCodeLoader.cs              |  189 
 cli_ure/source/ure/uno/util/RegistrationClassFinder.cs        |   33 
 config_host.mk.in                                             |   10 
 configure.ac                                                  |  105 
 desktop/source/deployment/registry/component/dp_component.cxx |   10 
 external/prj/d.lst                                            |    4 
 scp2/InstallModule_ooo.mk                                     |    1 
 scp2/InstallModule_ure.mk                                     |    1 
 scp2/source/ooo/file_library_ooo.scp                          |    6 
 scp2/source/ooo/ure.scp                                       |   68 
 solenv/gbuild/CliAssembly.mk                                  |    8 
 solenv/gbuild/CliExecutable.mk                                |  188 
 solenv/gbuild/CliLibrary.mk                                   |   14 
 solenv/gbuild/CliUnoApi.mk                                    |    7 
 solenv/gbuild/Helper.mk                                       |    2 
 solenv/gbuild/TargetLocations.mk                              |    8 
 solenv/gbuild/gbuild.mk                                       |    1 
 solenv/gbuild/platform/unxgcc.mk                              |    4 
 unoil/CustomTarget_climaker.mk                                |   31 
 unoil/Module_unoil.mk                                         |    7 
 57 files changed, 11088 insertions(+), 34 deletions(-)

New commits:
commit ab6f96f0212a120a537128296b81d1991e860137
Author: Petr Mladek <pmladek at suse.cz>
Date:   Tue Nov 6 16:03:54 2012 +0100

    [mono] fix build in gbuildised unoil
    
    Change-Id: I9c717b067e067338160a38c88d935187db8cc04d

diff --git a/external/prj/d.lst b/external/prj/d.lst
index 7ee2582..a797a3e 100644
--- a/external/prj/d.lst
+++ b/external/prj/d.lst
@@ -1,4 +1,5 @@
 mkdir: %_DEST%\inc\external
+mkdir: %_DEST%\inc\external\cli
 mkdir: %_DEST%\inc\external\glibc
 mkdir: %_DEST%\inc\external\mingw
 mkdir: %_DEST%\inc\external\mingw\include
@@ -6,6 +7,9 @@ mkdir: %_DEST%\inc\external\mingw\include\atl
 mkdir: %_DEST%\inc\external\mingw\include\sys
 mkdir: %_DEST%\inc\external\wine
 
+..\cli\*.config %_DEST%\inc\external\cli\*.config
+..\cli\*.dll %_DEST%\inc\external\cli\*.dll
+
 ..\glibc\rtufiles\config.h %_DEST%\inc\external\glibc\config.h
 ..\glibc\rtufiles\getopt.h %_DEST%\inc\external\glibc\getopt.h
 
diff --git a/unoil/CustomTarget_climaker.mk b/unoil/CustomTarget_climaker.mk
index a2c81c3..16db37e 100644
--- a/unoil/CustomTarget_climaker.mk
+++ b/unoil/CustomTarget_climaker.mk
@@ -36,6 +36,29 @@ $(call gb_CustomTarget_get_target,unoil/climaker) : \
 	$(unoil_CLIDIR)/cli_oootypes.config \
 	$(unoil_CLIDIR)/$(CLI_OOOTYPES_POLICY_ASSEMBLY).dll
 
+
+ifeq ($(ENABLE_MONO),YES)
+ifneq ($(ENABLE_MONO_CLIMAKER),YES)
+unoil_prebuilt_mono_dlls := YES
+endif
+endif
+
+ifeq ($(unoil_prebuilt_mono_dlls),YES)
+
+$(unoil_CLIDIR)/cli_oootypes.dll : $(OUTDIR)/inc/external/cli/cli_oootypes.dll
+	mkdir -p $(@D)
+	$(GNUCOPY) $? $@
+
+$(unoil_CLIDIR)/cli_oootypes.config : $(OUTDIR)/inc/external/cli/cli_oootypes.config
+	mkdir -p $(@D)
+	$(GNUCOPY) $? $@
+
+$(unoil_CLIDIR)/$(CLI_OOOTYPES_POLICY_ASSEMBLY).dll : $(OUTDIR)/inc/external/cli/$(CLI_OOOTYPES_POLICY_ASSEMBLY).dll
+	mkdir -p $(@D)
+	$(GNUCOPY) $< $@
+
+else
+
 $(unoil_CLIDIR)/cli_oootypes.dll : $(SRCDIR)/unoil/climaker/version.txt \
 		$(OUTDIR)/bin/offapi.rdb $(OUTDIR)/bin/udkapi.rdb \
 		$(OUTDIR)/bin/cliuno.snk $(OUTDIR)/bin/cli_uretypes.dll \
@@ -73,5 +96,6 @@ $(unoil_CLIDIR)/$(CLI_OOOTYPES_POLICY_ASSEMBLY).dll : \
 		-keyfile:$(OUTDIR)/bin/cliuno.snk \
 		-link:cli_oootypes.config)
 	rm cli_oootypes.config
+endif
 
 # vim:set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/unoil/Module_unoil.mk b/unoil/Module_unoil.mk
index 40e7cdd..ae29c85 100644
--- a/unoil/Module_unoil.mk
+++ b/unoil/Module_unoil.mk
@@ -39,6 +39,13 @@ $(eval $(call gb_Module_add_targets,unoil,\
 endif
 
 ifeq ($(COM),MSC)
+unoil_climaker_build := YES
+endif
+ifeq ($(ENABLE_MONO),YES)
+unoil_climaker_build := YES
+endif
+
+ifeq ($(unoil_climaker_build),YES)
 $(eval $(call gb_Module_add_targets,unoil,\
     CustomTarget_climaker \
     Package_climaker \
commit 10fb45c7fc8d521db6adae2b4b25eaec137c77fb
Author: Petr Mladek <pmladek at suse.cz>
Date:   Tue Aug 2 18:37:13 2011 +0200

    [mono] mono-component-support.diff: add mono support
    
    Conflicts:
    	cli_ure/prj/build.lst
    	cli_ure/prj/d.lst
    
    Change-Id: I58285be7b14a4e128d49f00dccc17e0a5fc64248

diff --git a/cli_ure/Library_mono_loader.mk b/cli_ure/Library_mono_loader.mk
new file mode 100644
index 0000000..719425e
--- /dev/null
+++ b/cli_ure/Library_mono_loader.mk
@@ -0,0 +1,33 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,mono_loader))
+
+$(eval $(call gb_Library_add_cxxflags,mono_loader,\
+        $(MONO_CFLAGS) \
+))
+
+$(eval $(call gb_Library_use_udk_api,mono_loader))
+
+$(eval $(call gb_Library_add_ldflags,mono_loader,\
+        $(MONO_LIBS) \
+))
+
+$(eval $(call gb_Library_use_libraries,mono_loader,\
+	sal \
+	cppu \
+	cppuhelper \
+))
+
+$(eval $(call gb_Library_add_exception_objects,mono_loader,\
+    cli_ure/source/mono_loader/service \
+    cli_ure/source/mono_loader/mono_loader \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/cli_ure/source/mono_bridge/bridge.cs b/cli_ure/source/mono_bridge/bridge.cs
index df2a615..6fdd78e 100644
--- a/cli_ure/source/mono_bridge/bridge.cs
+++ b/cli_ure/source/mono_bridge/bridge.cs
@@ -1646,9 +1646,9 @@ public unsafe class Bridge
 
         for (int i = 0; i < nParams; ++i)
         {
-            // FIXME it's a TypeDescriptionReference
-            TypeDescription *type = (TypeDescription *)parameters[i].pTypeRef;
-
+            TypeDescriptionReference *typeref = (TypeDescriptionReference *)parameters[i].pTypeRef;
+            TypeDescription *type = null;
+            TypeDescriptionReference.GetDescription(&type, typeref);
             unoArgPtrs[i] = unoArgs + i;
             if ((type->eTypeClass == TypeClass.STRUCT ||
                  type->eTypeClass == TypeClass.EXCEPTION) &&
@@ -1663,7 +1663,7 @@ public unsafe class Bridge
             if (parameters[i].bIn != 0)
             {
                 // FIXME error handling
-                MapToUno(unoArgPtrs[i], args[i], type, false /* no assign */);
+                MapToUno(unoArgPtrs[i], args[i], (TypeDescription*)typeref, false /* no assign */);
             }
         }
 
@@ -1795,13 +1795,27 @@ public unsafe class Bridge
                 MapToManaged(ref args[i], unoArgs[i], parameters[i].pTypeRef, null, false);
 
         object invocationResult = null;
+        Exception exc = null;
         try
         {
             invocationResult = method.Invoke(managedI, args);
         }
         catch (TargetInvocationException e)
         {
-            Exception exc = e.InnerException;
+            exc = e.InnerException;
+        }
+        catch (Exception e)
+        {
+            exc = e;
+        }
+        if ( exc != null )
+        {
+            if ( !( exc is unoidl.com.sun.star.uno.Exception ) )
+            {
+                // #FIXME put more info in here trace, stack etc. ( when I
+                // figure out how to do that in mono )
+                exc = new unoidl.com.sun.star.uno.RuntimeException( exc.ToString(), null );
+            }
             TypeDescription* td = null;
             // FIXME leak
             TypeDescriptionReference.GetDescription(&td, MapManagedType(exc.GetType()));
@@ -1811,11 +1825,6 @@ public unsafe class Bridge
             (*unoExc)->pData = memExc;
             return;
         }
-        catch (Exception e)
-        {
-            // FIXME
-        }
-
         // convert out, in/out params
         for (int i = 0; i < nParams; ++i)
         {
diff --git a/cli_ure/source/mono_loader/mono_loader.cxx b/cli_ure/source/mono_loader/mono_loader.cxx
new file mode 100644
index 0000000..0651bf3
--- /dev/null
+++ b/cli_ure/source/mono_loader/mono_loader.cxx
@@ -0,0 +1,238 @@
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include <comphelper/processfactory.hxx>
+#include <comphelper/uno3.hxx>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/loader/XImplementationLoader.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/util/XMacroExpander.hpp>
+#include <cppuhelper/implbase2.hxx>
+#include "uno/mapping.hxx"
+#include "osl/file.hxx"
+#include "glib/gtypes.h"
+
+// for debug
+#include <comphelper/anytostring.hxx>
+
+extern "C" {
+#include <mono/jit/jit.h>
+#include <mono/metadata/object.h>
+#include <mono/metadata/environment.h>
+#include <mono/metadata/assembly.h>
+#include <mono/metadata/debug-helpers.h>
+#include <mono/metadata/threads.h>
+}
+
+using namespace ::com::sun::star;
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
+
+//static const char CLIURE_DLL[] = "$URE_LIB_DIR/cli_ure.dll";
+static const char CLIURE_DLL[] = "$URE_INTERNAL_LIB_DIR/cli_ure.dll";
+typedef ::cppu::WeakImplHelper2< loader::XImplementationLoader, lang::XServiceInfo > MonoLoader_BASE;
+
+namespace mono_loader
+{
+    ::rtl::OUString SAL_CALL getImplementationName();
+
+    uno::Reference< uno::XInterface > SAL_CALL create( uno::Reference< uno::XComponentContext > const & xContext ) SAL_THROW( () );
+
+    uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
+}
+
+uno::Reference< loader::XImplementationLoader >
+create_object (MonoDomain *domain, MonoImage *image)
+{
+        MonoClass *klass;
+
+        klass = mono_class_from_name (image, "uno.util", "ManagedCodeLoader");
+        if (!klass) {
+                OSL_TRACE ("Can't find ManagedCodeLoader in assembly %s", mono_image_get_filename (image));
+                return NULL;
+        }
+        MonoObject* obj = mono_object_new (domain, klass);
+        /* mono_object_new () only allocates the storage:
+         * it doesn't run any constructor. Tell the runtime to run
+         * the default argumentless constructor.
+         */
+        mono_runtime_object_init (obj);
+        static uno::Reference< loader::XImplementationLoader > xLoader;
+        // not sure if this is correct ( I'm loosely following 'to_uno'
+        // method in cli_ure/source/native/native_share.h )
+
+        loader::XImplementationLoader* pLoader = NULL;
+        OSL_TRACE("About to call mapInterface for XImplementionLoader returned from Mono");
+        // we are storing the object so... I guess we need to tell the gc not
+        // to bother about this object
+        //mono_gchandle_new( obj, false ); // where do we release that ? do we even need to do this?
+        guint32 nHandle = mono_gchandle_new( obj, true ); // where do we release that ? do we even need to do this?
+        uno::Mapping mapping( OUSTR( UNO_LB_CLI ), OUSTR( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
+        OSL_ASSERT( mapping.is() );
+        if (! mapping.is() )
+            return NULL;
+
+        mapping.mapInterface(
+            reinterpret_cast< void ** >( &pLoader ),
+            reinterpret_cast< void * >( obj ), ::getCppuType( &xLoader ) );
+        mono_gchandle_free ( nHandle ); // copying what cli_ure/source/native/native_share.h does for DotNet
+        xLoader.set( pLoader, SAL_NO_ACQUIRE /* takeover ownership */ );
+        OSL_TRACE("We appear to have got an XImplementationLoader that has a value? %s", xLoader.is() ? "yes" : "no " );
+        return xLoader;
+}
+
+
+class MonoLoader : public MonoLoader_BASE
+{
+    class MonoCleanUp
+    {
+    public:
+        MonoCleanUp() { OSL_TRACE("MonoCleanUp created "); }
+        ~MonoCleanUp()
+        {
+            OSL_TRACE("~MonoCleanUp");
+            // loader only uses the root domain
+            mono_jit_cleanup (mono_get_root_domain());
+        }
+    };
+    uno::Reference< uno::XComponentContext > mxContext;
+    uno::Reference< loader::XImplementationLoader > mxLoader;
+    uno::Reference< util::XMacroExpander > mxExpander;
+    uno::Reference< loader::XImplementationLoader > getLoader( const char* file)
+    {
+        OSL_TRACE("** enter getLoader()");
+        // init only once
+        static MonoDomain* domain = mono_jit_init (file);
+        // when is a good time to trigger clean up ?
+        //static MonoCleanUp cleaner;
+        // hmm appears we need to attach this thread to the domain
+        mono_thread_attach( domain );
+        MonoAssembly *assembly;
+
+        assembly = mono_domain_assembly_open ( domain, file);
+        OSL_TRACE("** open of assembly %s = 0x%x", file, assembly);
+        if ( !assembly )
+            throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to open assembly " ) ) + rtl::OUString::createFromAscii( file ), NULL );
+        return create_object (domain, mono_assembly_get_image (assembly));
+    }
+
+
+public:
+    MonoLoader( const uno::Reference< uno::XComponentContext >& rxContext ) : mxContext( rxContext )
+    {
+        if (!(mxContext->getValueByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))) >>= mxExpander)
+        || !mxExpander.is())
+        {
+            throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "component context fails to supply singleton" " com.sun.star.util.theMacroExpander of type" " com.sun.star.util.XMacroExpander")), mxContext);
+        }
+
+        rtl::OUString dllUrlPath =  mxExpander->expandMacros( rtl::OUString(  RTL_CONSTASCII_USTRINGPARAM( CLIURE_DLL ) ) );
+        rtl::OUString dllPath;
+        if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL(
+                dllUrlPath, dllPath ))
+        {
+            throw uno::RuntimeException(
+                OUSTR("cannot get system path from file url ") +
+                dllPath,
+                uno::Reference< uno::XInterface >() );
+        }
+
+        OSL_TRACE("**** location for dll is %s", rtl::OUStringToOString( dllPath, RTL_TEXTENCODING_UTF8 ).getStr() );
+        OSL_TRACE("** MonoLoader::MonoLoader() ");
+        mxLoader = getLoader( rtl::OUStringToOString( dllPath, RTL_TEXTENCODING_UTF8 ).getStr() );
+        if ( mxLoader.is() )
+        {
+            // set the service factory
+            uno::Sequence< uno::Any > args(1);
+            args[ 0 ] <<= rxContext->getServiceManager();
+            uno::Reference< lang::XInitialization > xInitialize( mxLoader, uno::UNO_QUERY_THROW );
+            OSL_TRACE("MonoLoader::MonoLoader() about to call initialise");
+            xInitialize->initialize( args );
+        }
+        else
+            OSL_TRACE("**  MonoLoader::MonoLoader(): No Mono loader found ");
+
+    }
+    ~MonoLoader()
+    {
+        OSL_TRACE("** MonoLoader::~MonoLoader() ");
+    }
+    // Methods
+    virtual uno::Reference< uno::XInterface > SAL_CALL activate( const ::rtl::OUString& implementationName, const ::rtl::OUString& implementationLoaderUrl, const ::rtl::OUString& locationUrl, const uno::Reference< registry::XRegistryKey >& xKey ) throw (loader::CannotActivateFactoryException, uno::RuntimeException)
+    {
+        // try to instatiate a mono loader and return a reference to it
+        OSL_TRACE("**** in MonoLoader::activate");
+        if ( mxLoader.is() )
+        {
+            OSL_TRACE("*** MonoLoader::activate() about to call activate on 0x%x", mxLoader.get() );
+            return mxLoader->activate( implementationName, implementationLoaderUrl, locationUrl, xKey );
+        }
+        return NULL;
+    }
+
+    virtual ::sal_Bool SAL_CALL writeRegistryInfo( const uno::Reference< registry::XRegistryKey >& xKey, const ::rtl::OUString& implementationLoaderUrl, const ::rtl::OUString& locationUrl ) throw (registry::CannotRegisterImplementationException, uno::RuntimeException)
+    {
+        if ( mxLoader.is() )
+            return mxLoader->writeRegistryInfo( xKey, implementationLoaderUrl, locationUrl );
+        return sal_False;
+    }
+    virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (uno::RuntimeException){ return mono_loader::getImplementationName(); }
+    virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
+    {
+        sal_Bool bRes = sal_False;
+        uno::Sequence< ::rtl::OUString > sServices = mono_loader::getSupportedServiceNames();
+        const ::rtl::OUString* pService = sServices.getConstArray();
+        const ::rtl::OUString* pEnd = sServices.getConstArray() + sServices.getLength();
+        for ( ; pService != pEnd ;  ++pService )
+        {
+            if ( (*pService).equals( ServiceName ) )
+            {
+                bRes = sal_True;
+                break;
+            }
+        }
+        return bRes;
+    }
+    virtual uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (uno::RuntimeException){ return mono_loader::getSupportedServiceNames(); }
+
+};
+
+namespace mono_loader
+{
+    ::rtl::OUString SAL_CALL getImplementationName()
+    {
+        static ::rtl::OUString* pImplName = 0;
+        if ( !pImplName )
+        {
+            ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+            if ( !pImplName )
+            {
+                static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.loader.MonoLoader" ) );
+                pImplName = &aImplName;
+            }
+        }
+        return *pImplName;
+    }
+
+    uno::Reference< uno::XInterface > SAL_CALL create(
+    uno::Reference< uno::XComponentContext > const & xContext )
+    SAL_THROW( () )
+    {
+        OSL_TRACE("** In create for monoloader");
+        // mimic java loader if I read it correctly it just has a single entry
+        // point ( Mono implementation loader should do the same? #TODO maybe )
+        // #FIXME use whatever boiler plate static initialisatioon foo that is
+        // available ( seem to recall there is some helpers for that )
+        // static uno::Reference < lang::XTypeProvider  > xLoader( new MonoLoader( xContext ) );
+        // hmm lets not do it for now because I'm not sure how an exiting/shutting down office/bridge co-operates
+        // with the mono runtime or if it does at all :/
+        uno::Reference < lang::XTypeProvider  > xLoader( new MonoLoader( xContext ) );
+        return xLoader;
+    }
+
+    uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
+    {
+        const ::rtl::OUString strName( ::mono_loader::getImplementationName() );
+        return uno::Sequence< ::rtl::OUString >( &strName, 1 );
+    }
+}
diff --git a/cli_ure/source/mono_loader/mono_loader.xml b/cli_ure/source/mono_loader/mono_loader.xml
new file mode 100644
index 0000000..4c18027
--- /dev/null
+++ b/cli_ure/source/mono_loader/mono_loader.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+
+    <module-name>mono_loader</module-name>
+
+    <component-description>
+        <author>Noel Power </author>
+        <name>Mono Loader</name>
+        <description>Loader for components located in mono assemblies</description>
+        <loader-name>com.sun.star.loader.SharedLibrary</loader-name>
+        <language>c++</language>
+        <status value="drafts"/>
+        <supported-service>org.openoffice.loader.MonoLoader</supported-service>
+        <type>com.sun.star.uno.XComponentContext</type>
+    </component-description>
+
+    <project-build-dependency>cppuhelper</project-build-dependency>
+    <project-build-dependency>cppu</project-build-dependency>
+    <project-build-dependency>sal</project-build-dependency>
+
+    <runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency>
+    <runtime-module-dependency>cppu3</runtime-module-dependency>
+    <runtime-module-dependency>sal3</runtime-module-dependency>
+
+</module-description>
diff --git a/cli_ure/source/mono_loader/service.cxx b/cli_ure/source/mono_loader/service.cxx
new file mode 100644
index 0000000..b2f5f09
--- /dev/null
+++ b/cli_ure/source/mono_loader/service.cxx
@@ -0,0 +1,72 @@
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "cppuhelper/implementationentry.hxx"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/registry/XRegistryKey.hpp"
+
+// =============================================================================
+// component exports
+// =============================================================================
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+namespace mono_loader
+{
+    // =============================================================================
+    // component operations
+    // =============================================================================
+
+    uno::Reference< XInterface > SAL_CALL create(
+        Reference< XComponentContext > const & xContext )
+        SAL_THROW( () );
+
+    // -----------------------------------------------------------------------------
+
+    ::rtl::OUString SAL_CALL getImplementationName();
+
+    Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
+
+    Reference<XInterface> SAL_CALL create(
+        Sequence<Any> const &, Reference<XComponentContext> const & );
+} // end mono_loader
+
+    // =============================================================================
+
+    const ::cppu::ImplementationEntry s_component_entries [] =
+    {
+        {
+            ::mono_loader::create, ::mono_loader::getImplementationName,
+            ::mono_loader::getSupportedServiceNames,
+            ::cppu::createSingleComponentFactory,
+            0, 0
+        },
+        { 0, 0, 0, 0, 0, 0 }
+    };
+
+extern "C"
+{
+    SAL_DLLPUBLIC_EXPORT  void SAL_CALL component_getImplementationEnvironment(
+        const sal_Char ** ppEnvTypeName, uno_Environment ** )
+    {
+        OSL_TRACE("In component_getImplementationEnv");
+        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+    }
+
+    SAL_DLLPUBLIC_EXPORT  sal_Bool SAL_CALL component_writeInfo(
+        lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey )
+    {
+        OSL_TRACE("In component_writeInfo");
+        if ( ::cppu::component_writeInfoHelper(
+            pServiceManager, pRegistryKey, s_component_entries ) )
+            return sal_True;
+        return sal_False;
+    }
+
+    SAL_DLLPUBLIC_EXPORT  void * SAL_CALL component_getFactory(
+        const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
+        registry::XRegistryKey * pRegistryKey )
+    {
+        OSL_TRACE("In component_getFactory");
+        return ::cppu::component_getFactoryHelper(
+            pImplName, pServiceManager, pRegistryKey, s_component_entries );
+    }
+}
diff --git a/scp2/source/ooo/ure.scp b/scp2/source/ooo/ure.scp
index 4447e54..ebf7d41 100755
--- a/scp2/source/ooo/ure.scp
+++ b/scp2/source/ooo/ure.scp
@@ -439,6 +439,16 @@ File gid_File_Dl_LogUnoUno
     Styles = (PACKED, VERSION_INDEPENDENT_COMP_ID);
 End
 
+#if ( defined UNX && defined ENABLE_MONO ) // currently we only will build this on unix
+File gid_File_Dl_MonoLoader
+    TXT_FILE_BODY;
+    Dir = SCP2_URE_DL_DIR;
+    Name = STRING(CONCAT3(mono_loader,.uno,UNXSUFFIX));
+    Styles = (PACKED, UNO_COMPONENT, VERSION_INDEPENDENT_COMP_ID);
+    RegistryID = gid_Starregistry_Services_Rdb_Ure;
+End
+#endif
+
 #if defined _MSC_VER || defined ENABLE_MONO
 File gid_File_Dl_Cli_Uno
     LIB_FILE_BODY;
commit 5f25dc8a564d01829f3cf9f58ed80cc83ea0eb45
Author: Petr Mladek <pmladek at suse.cz>
Date:   Tue Aug 2 18:25:35 2011 +0200

    [mono] mono-climaker.diff: add mono support
    
    merged with buildfix-climaker-disabled.diff: add mono support
    merged with climaker-csharp-win.diff: add mono support
    merged with buildfix-use-climaker-in-unoil.diff: add mono support
    
    Conflicts:
    
    	cli_ure/prj/d.lst
    	cli_ure/source/bootstrap/makefile.mk
    	cli_ure/source/climaker/makefile.mk
    	cli_ure/unotypes/makefile.mk
    	unoil/climaker/makefile.mk
    
    Change-Id: I4c0ec75954df7a34ed6f4173f84190ab10e62c4b

diff --git a/cli_ure/Executable_climaker_mono.mk b/cli_ure/Executable_climaker_mono.mk
new file mode 100644
index 0000000..6af8dc0
--- /dev/null
+++ b/cli_ure/Executable_climaker_mono.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CliExecutable_CliExecutable,climaker))
+
+$(eval $(call gb_CliExecutable_add_csfiles,climaker,\
+    cli_ure/source/climaker/climaker_csharp \
+))
+
+$(eval $(call gb_CliExecutable_use_assemblies,climaker,\
+	cli_basetypes \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/cli_ure/Library_climaker.mk b/cli_ure/Library_climaker.mk
new file mode 100644
index 0000000..22eaffa
--- /dev/null
+++ b/cli_ure/Library_climaker.mk
@@ -0,0 +1,26 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,climaker))
+
+$(eval $(call gb_Library_use_udk_api,climaker))
+
+$(eval $(call gb_Library_set_visibility_default,climaker))
+
+$(eval $(call gb_Library_use_libraries,climaker,\
+        sal \
+        cppu \
+        cppuhelper \
+))
+
+$(eval $(call gb_Library_add_exception_objects,climaker,\
+        cli_ure/source/climaker/climaker_mono \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/cli_ure/source/climaker/climaker_csharp.cs b/cli_ure/source/climaker/climaker_csharp.cs
new file mode 100644
index 0000000..cb6d3de
--- /dev/null
+++ b/cli_ure/source/climaker/climaker_csharp.cs
@@ -0,0 +1,3207 @@
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.InteropServices;
+
+enum UnoTypeClass {
+    Unknown,
+    Void,
+    Char,
+    Boolean,
+    Byte,
+    Short,
+    UnsignedShort,
+    Long,
+    UnsignedLong,
+    Hyper,
+    UnsignedHyper,
+    Float,
+    Double,
+    String,
+    Type,
+    Any,
+    Enum,
+    Typedef,
+    Struct,
+    Exception,
+    Sequence,
+    Interface,
+    InterfaceAttribute,
+    InterfaceMethod,
+    Constant,
+    Constants,
+    Service,
+    Singleton,
+    Module
+}
+
+struct Constants
+{
+    public static readonly string UnoVoid = "void";
+    public static readonly string UnoType = "type";
+    public static readonly string UnoAny =  "any";
+    public static readonly string UnoBool = "boolean";
+    public static readonly string UnoByte = "byte";
+    public static readonly string UnoChar = "char";
+    public static readonly string UnoShort = "short";
+    public static readonly string UnoUShort = "unsigned short";
+    public static readonly string UnoLong = "long";
+    public static readonly string UnoULong = "unsigned long";
+    public static readonly string UnoHyper = "hyper";
+    public static readonly string UnoUHyper = "unsigned hyper";
+    public static readonly string UnoString = "string";
+    public static readonly string UnoFloat = "float";
+    public static readonly string UnoDouble = "double";
+    public static readonly string UnoXInterface = "com.sun.star.uno.XInterface";
+    public static readonly string Brackets = "[]";
+
+    public static readonly string Object = "System.Object";
+    public static readonly string Type = "System.Type";
+    public static readonly string Unoidl = "unoidl.";
+    public static readonly string Void = "System.Void";
+    public static readonly string Any = "uno.Any";
+    public static readonly string Boolean = "System.Boolean";
+    public static readonly string Char = "System.Char";
+    public static readonly string Byte = "System.Byte";
+    public static readonly string Int16 = "System.Int16";
+    public static readonly string UInt16 = "System.UInt16";
+    public static readonly string Int32 = "System.Int32";
+    public static readonly string UInt32 = "System.UInt32";
+    public static readonly string Int64 = "System.Int64";
+    public static readonly string UInt64 = "System.UInt64";
+    public static readonly string String = "System.String";
+    public static readonly string Single = "System.Single";
+    public static readonly string Double = "System.Double";
+    public static readonly string Comma = ",";
+}
+
+class TypeEmitter : IDisposable
+{
+    ResolveEventHandler mTypeResolver;
+    ModuleBuilder mModuleBuilder;
+    ArrayList mExtraAssemblies;
+    Hashtable mIncompleteIFaces;
+    Hashtable mIncompleteServices;
+    Hashtable mIncompleteSingletons;
+    Hashtable mGeneratedStructs;
+    Config mConfig;
+
+    Type mTypeException = null;
+    Type mTypeRuntimeException = null;
+
+    readonly static MethodAttributes cCtorMethodAttr =
+    MethodAttributes.Public |
+    MethodAttributes.HideBySig |
+    MethodAttributes.SpecialName |
+    MethodAttributes.RTSpecialName;
+    /* | xxx todo: ??? compiler does not know Instance ???
+       ::System::Reflection::MethodAttributes::Instance*/
+
+    MethodInfo mMethodInfoTypeGetTypeFromHandle;
+
+    class IFaceEntry
+    {
+        public UnoXInterfaceTypeDescription mType;
+        public TypeBuilder mTypeBuilder;
+    }
+
+    class ServiceEntry
+    {
+        public UnoXServiceTypeDescription mType;
+        public TypeBuilder mTypeBuilder;
+    }
+
+    class SingletonEntry
+    {
+        public UnoXSingletonTypeDescription mType;
+        public TypeBuilder mTypeBuilder;
+    }
+
+    class StructEntry
+    {
+        public string[] mMemberNames;
+        public Type[] mParamTypes;
+        public ConstructorInfo mDefaultConstructor;
+        public ConstructorInfo mConstructor;
+    }
+
+    public TypeEmitter (Config config, ModuleBuilder builder)
+    {
+        mConfig = config;
+
+        // load extra assemblies
+        mExtraAssemblies = new ArrayList ();
+        foreach (string assemblyPath in mConfig.mExtraAssemblies)
+            mExtraAssemblies.Add (Assembly.LoadFrom (assemblyPath));
+
+        mTypeResolver = new ResolveEventHandler (TypeResolveHandler);
+        mModuleBuilder = builder;
+
+        mIncompleteIFaces = new Hashtable ();
+        mIncompleteServices = new Hashtable ();
+        mIncompleteSingletons = new Hashtable ();
+        mGeneratedStructs = new Hashtable ();
+
+        Type[] paramTypes = { typeof (RuntimeTypeHandle) };
+        mMethodInfoTypeGetTypeFromHandle = typeof (Type).GetMethod ("GetTypeFromHandle", paramTypes);
+    }
+
+    public ResolveEventHandler ResolveEventHandler
+    {
+    get
+    {
+        return mTypeResolver;
+    }
+    }
+
+    Assembly TypeResolveHandler (object o, ResolveEventArgs args)
+    {
+        Type ret = mModuleBuilder.GetType (args.Name, false);
+        //Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret);
+
+#if __MonoCS__
+        if (ret is TypeBuilder) {
+            TypeBuilder tb = ret as TypeBuilder;
+            //Console.WriteLine ("{0} is type builder", tb);
+            if (tb.IsCreated ()) {
+                ret = tb.CreateType ();
+                //Console.WriteLine ("resolving to created {0} {1}", ret, tb);
+            }
+        }
+#endif
+        if (ret == null) {
+            IFaceEntry entry = mIncompleteIFaces [args.Name] as IFaceEntry;
+            if (entry != null)
+                ret = entry.mTypeBuilder;
+        }
+
+        if (ret == null && mExtraAssemblies != null) {
+            //Console.WriteLine ("assemblies {0}", mExtraAssemblies);
+            foreach (Assembly assembly in mExtraAssemblies) {
+                ret = assembly.GetType (args.Name, false);
+                if (ret != null) {
+                    if (mConfig.mVerbose) {
+                        Console.WriteLine ("> resolving type {0} from {1}.",
+                                           args.Name, ret.Assembly.FullName);
+				    }
+                    break;
+                }
+            }
+            //Console.WriteLine ("done {0}", ret);
+        }
+
+        if (ret != null)
+            return ret.Assembly;
+
+        return null;
+    }
+
+    Type GetType (string name, bool throwExc)
+    {
+        Type ret = mModuleBuilder.GetType (name, false);
+        //Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret);
+
+#if __MonoCS__
+        if (ret is TypeBuilder) {
+            TypeBuilder tb = ret as TypeBuilder;
+            //Console.WriteLine ("{0} is type builder", tb);
+            if (tb.IsCreated ()) {
+                ret = tb.CreateType ();
+                //Console.WriteLine ("resolving to created {0} {1}", ret, tb);
+            }
+        }
+#endif
+        if (ret == null) {
+            //Console.WriteLine ("looking name {0}", name);
+            IFaceEntry entry = mIncompleteIFaces [name] as IFaceEntry;
+            if (entry != null)
+                ret = entry.mTypeBuilder;
+        }
+
+        //try the cli_basetypes assembly
+        if (ret == null) {
+            ret = Type.GetType (name + ",cli_basetypes");
+        }
+
+        if (ret == null) {
+            try  {
+                // may call on type_resolve()
+                return Type.GetType (name, throwExc);
+            } catch (Exception e) {
+                //If the type is not found one may have forgotten to specify assemblies with
+                //additional types
+                if (throwExc)
+                    throw new Exception ("\nThe type " + name + " \n could not be found. Did you forget to " +
+                                         "specify an additional assembly with the --reference option?\n", e);
+            }
+        }
+
+        return ret;
+    }
+
+    public Type GetType (UnoXEnumTypeDescription xtd)
+    {
+    //Console.WriteLine ("emit enum {0} {1}", xtd.Name, xtd.Length);
+    string name = "unoidl." + xtd.Name;
+
+    Type ret = GetType (name, false /* no exc */);
+    if (ret == null) {
+//         Emit::EnumBuilder * enum_builder =
+//             m_module_builder->DefineEnum(
+//                 cts_name,
+//                 (TypeAttributes) (TypeAttributes::Public |
+// //                                   TypeAttributes::Sealed |
+//                                   TypeAttributes::AnsiClass),
+//                 __typeof (::System::Int32) );
+        // workaround enum builder bug
+        TypeBuilder enumBuilder =
+        mModuleBuilder.DefineType (name,
+                       TypeAttributes.Public |
+                       TypeAttributes.Sealed,
+                       typeof (System.Enum));
+        enumBuilder.DefineField ("value__", typeof (System.Int32),
+                     FieldAttributes.Public |
+                     FieldAttributes.SpecialName |
+                     FieldAttributes.RTSpecialName);
+
+        int length = xtd.Length;
+        for (int pos = 0; pos < length; pos ++) {
+//             enum_builder->DefineLiteral(
+//                 ustring_to_String( enum_names[ enum_pos ] ),
+//                 __box ((::System::Int32) enum_values[ enum_pos ]) );
+        FieldBuilder fieldBuilder =
+            enumBuilder.DefineField (xtd.ValueName (pos),
+                         enumBuilder,
+                         FieldAttributes.Public |
+                         FieldAttributes.Static |
+                         FieldAttributes.Literal);
+        fieldBuilder.SetConstant (xtd.Value (pos));
+        }
+
+        if (mConfig.mVerbose)
+             Console.WriteLine ("> emitting enum type {0}", name );
+
+        ret = enumBuilder.CreateType ();
+    }
+
+    return ret;
+    }
+
+    public Type GetType (UnoXInterfaceTypeDescription xtd)
+    {
+        //Console.WriteLine ("get iface {0}", xtd.Name);
+
+        if (String.Compare (xtd.Name, "com.sun.star.uno.XInterface") == 0) {
+            return typeof (object);
+    }
+
+    string name = "unoidl." + xtd.Name;
+
+    Type ret = GetType (name, false /* no exc */);
+
+    if (ret == null) {
+        //Console.WriteLine ("creating name {0}", name);
+        TypeBuilder typeBuilder;
+
+        TypeAttributes attr = TypeAttributes.Public |
+        TypeAttributes.Interface |
+        TypeAttributes.Abstract |
+        TypeAttributes.AnsiClass;
+
+        int length = xtd.BaseTypes;
+        if (length > 0) {
+        ArrayList ifaces = new ArrayList ();
+        int i;
+
+        for (i = 0; i < length; i ++) {
+            UnoXInterfaceTypeDescription baseType = xtd.BaseType (i);
+            if (String.Compare (baseType.Name, "com.sun.star.uno.XInterface") != 0)
+            ifaces.Add (baseType);
+        }
+        Type[] baseInterfaces = new Type [ifaces.Count];
+
+        i = 0;
+        foreach (UnoXInterfaceTypeDescription iface in ifaces) {
+            baseInterfaces[i] = GetType (iface);
+            i++;
+        }
+
+        typeBuilder = mModuleBuilder.DefineType (name, attr, null, baseInterfaces);
+        } else {
+            System.Console.WriteLine ("warning: IDL interface {0} is not derived from " +
+                                      "com.sun.star.uno.XInterface!", name);
+
+            typeBuilder = mModuleBuilder.DefineType (name, attr);
+        }
+
+        // insert to be completed
+        IFaceEntry entry = new IFaceEntry ();
+        entry.mType = xtd;
+        entry.mTypeBuilder = typeBuilder;
+        mIncompleteIFaces [name] = entry;
+
+        // type is incomplete
+	    ret = typeBuilder;
+    }
+
+    return ret;
+    }
+
+    string PolymorphicStructNameToStructName (string name)
+    {
+    if (!name.EndsWith (">"))
+        return name;
+
+    int index = name.IndexOf ('<');
+
+    if (index == -1)
+        return name;
+
+    return name.Substring (0, index);
+    }
+
+    Type TypeException ()
+    {
+        if (mTypeException == null) {
+            mTypeException = GetType ("unoidl.com.sun.star.uno.Exception", false);
+
+            if (mTypeException == null) {
+                // define hardcoded type unoidl.com.sun.star.uno.Exception
+                TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.Exception",
+                                                                     TypeAttributes.Public |
+                                                                     TypeAttributes.BeforeFieldInit |
+                                                                     TypeAttributes.AnsiClass,
+                                                                     typeof (System.Exception));
+                FieldBuilder fieldContext = typeBuilder.DefineField ("Context", typeof (object),
+                                                                     FieldAttributes.Public);
+                // default .ctor
+                typeBuilder.DefineDefaultConstructor (cCtorMethodAttr);
+                // .ctor
+                Type[] paramTypes = new Type [2];
+                paramTypes [0] = typeof (string);
+                paramTypes [1] = typeof (object);
+                ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr,
+                                                                                CallingConventions.Standard,
+                                                                                paramTypes);
+                ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message");
+                ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context");
+                ILGenerator code = ctorBuilder.GetILGenerator ();
+                code.Emit (OpCodes.Ldarg_0);
+                code.Emit (OpCodes.Ldarg_1);
+                paramTypes = new Type [1];
+                paramTypes [0] = typeof (string);
+                code.Emit (OpCodes.Call, typeof (System.Exception).GetConstructor (paramTypes));
+                code.Emit( OpCodes.Ldarg_0 );
+                code.Emit( OpCodes.Ldarg_2 );
+                code.Emit( OpCodes.Stfld, fieldContext );
+                code.Emit( OpCodes.Ret );
+
+                if (mConfig.mVerbose)
+                    Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.Exception");
+
+                mTypeException = typeBuilder.CreateType ();
+            }
+        }
+
+        return mTypeException;
+    }
+
+    Type TypeRuntimeException ()
+    {
+        if (mTypeRuntimeException == null) {
+            mTypeRuntimeException = GetType ("unoidl.com.sun.star.uno.RuntimeException", false);
+            if (mTypeRuntimeException == null) {
+                // define hardcoded type unoidl.com.sun.star.uno.RuntimeException
+                Type typeException = TypeException ();
+                TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.RuntimeException",
+                                                                     TypeAttributes.Public |
+                                                                     TypeAttributes.BeforeFieldInit |
+                                                                     TypeAttributes.AnsiClass,
+                                                                     typeException);
+                // default .ctor
+                typeBuilder.DefineDefaultConstructor (cCtorMethodAttr);
+                // .ctor
+                Type[] paramTypes = new Type [2];
+                paramTypes [0] = typeof (string);
+                paramTypes [1] = typeof (object);
+                ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr,
+                                                                                CallingConventions.Standard,
+                                                                                paramTypes);
+                ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message");
+                ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context");
+                ILGenerator code = ctorBuilder.GetILGenerator ();
+                code.Emit (OpCodes.Ldarg_0);
+                code.Emit (OpCodes.Ldarg_1);
+                code.Emit (OpCodes.Ldarg_2 );
+                code.Emit (OpCodes.Call,
+                           typeException.GetConstructor (paramTypes));
+                code.Emit (OpCodes.Ret);
+
+                if (mConfig.mVerbose)
+                    Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.RuntimeException");
+
+                mTypeRuntimeException = typeBuilder.CreateType ();
+            }
+        }
+
+        return mTypeRuntimeException;
+    }
+
+    public Type GetType (UnoXServiceTypeDescription xtd)
+    {
+        // Console.WriteLine ("get service {0}", xtd.Name);
+
+        if (!xtd.IsSingleInterfaceBased)
+            return null;
+
+        string name = "unoidl." + xtd.Name;
+
+        Type ret = GetType (name, false /* no exc */);
+
+        if (ret != null)
+            return ret;
+
+        TypeAttributes attr =
+            TypeAttributes.Public |
+            TypeAttributes.Sealed |
+            TypeAttributes.BeforeFieldInit |
+            TypeAttributes.AnsiClass;
+
+        // insert to be completed
+        ServiceEntry entry = new ServiceEntry ();
+        entry.mType = xtd;
+        entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr);
+        mIncompleteServices.Add (name, entry);
+
+        return entry.mTypeBuilder;
+    }
+
+    static void EmitLdarg (ILGenerator code, int index)
+    {
+        switch (index) {
+        case 0:
+            code.Emit( OpCodes.Ldarg_0 );
+            break;
+        case 1:
+            code.Emit( OpCodes.Ldarg_1 );
+            break;
+        case 2:
+            code.Emit( OpCodes.Ldarg_2 );
+            break;
+        case 3:
+            code.Emit( OpCodes.Ldarg_3 );
+            break;
+        default:
+            if (index < 0x100)
+                code.Emit (OpCodes.Ldarg_S, (byte) index);
+            else if (index < 0x8000)
+                code.Emit (OpCodes.Ldarg_S, (System.Int16) index);
+            else
+                code.Emit (OpCodes.Ldarg, index);
+            break;
+        }
+    }
+
+    /** For example, there is a uno type
+        com.sun.star.Foo<char, long>.
+        The values in the type list
+        are uno types and are replaced by cli types, such as System.Char,
+        System.Int32, etc.
+
+        Strings can be as complicated as this
+        test.MyStruct<char,test.MyStruct<long, []string>>
+    */
+    string MapUnoPolymorphicName (string unoName)
+    {
+        int index = unoName.IndexOf('<');
+        if (index == -1)
+            return unoName;
+
+        System.Text.StringBuilder builder = new System.Text.StringBuilder (unoName.Substring (0, index + 1));
+
+        //Find the first occurrence of ','
+        //If the parameter is a polymorphic struct then we neede to ignore everything
+        //between the brackets because it can also contain commas
+        //get the type list within < and >
+        int endIndex = unoName.Length - 1;
+        index ++;
+        int cur = index;
+        int countParams = 0;
+        while (cur <= endIndex) {
+            char c = unoName [cur];
+
+            if (c == ',' || c == '>') {
+                //insert a comma if needed
+                if (countParams != 0)
+                    builder.Append (",");
+                countParams++;
+                string param = unoName.Substring (index, cur - index);
+                //skip the comma
+                cur ++;
+                //the the index to the beginning of the next param
+                index = cur;
+                builder.Append (MapUnoTypeName (param));
+            } else if (c == '<') {
+                cur++;
+                //continue until the matching '>'
+                int numNested = 0;
+                for (;; cur ++) {
+                    char curChar = unoName [cur];
+                    if (curChar == '<')
+                        numNested ++;
+                    else if (curChar == '>') {
+                        if (numNested > 0)
+                            numNested --;
+                        else
+                            break;
+                    }
+                }
+            }
+            cur ++;
+        }
+
+        builder.Append ('>');
+        return builder.ToString();
+    }
+
+    string MapUnoTypeName (string typeName)
+    {
+        System.Text.StringBuilder buf= new System.Text.StringBuilder ();
+        string unoName = String.Copy (typeName);
+
+        //determine if the type is a sequence and its dimensions
+        int dims = 0;
+        if (typeName.StartsWith ("[")) {
+            int index= 1;
+            while (true) {
+                if (typeName [index ++] == ']')
+                    dims++;
+                if (typeName [index ++] != '[')
+                    break;
+            }
+            unoName = unoName.Substring (index - 1);
+        }
+
+        if (unoName.Equals (Constants.UnoBool))
+            buf.Append (Constants.Boolean);
+        else if (unoName.Equals(Constants.UnoChar))
+            buf.Append (Constants.Char);
+        else if (unoName.Equals(Constants.UnoByte))
+            buf.Append (Constants.Byte);
+        else if (unoName.Equals(Constants.UnoShort))
+            buf.Append (Constants.Int16);
+        else if (unoName.Equals(Constants.UnoUShort))
+            buf.Append (Constants.UInt16);
+        else if (unoName.Equals(Constants.UnoLong))
+            buf.Append (Constants.Int32);
+        else if (unoName.Equals(Constants.UnoULong))
+            buf.Append (Constants.UInt32);
+        else if (unoName.Equals(Constants.UnoHyper))
+            buf.Append (Constants.Int64);
+        else if (unoName.Equals(Constants.UnoUHyper))
+            buf.Append (Constants.UInt64);
+        else if (unoName.Equals(Constants.UnoFloat))
+            buf.Append (Constants.Single);
+        else if (unoName.Equals(Constants.UnoDouble))
+            buf.Append (Constants.Double);
+        else if (unoName.Equals(Constants.UnoString))
+            buf.Append (Constants.String);
+        else if (unoName.Equals(Constants.UnoVoid))
+            buf.Append (Constants.Void);
+        else if (unoName.Equals(Constants.UnoType))
+            buf.Append (Constants.Type);
+        else if (unoName.Equals(Constants.UnoXInterface))
+            buf.Append (Constants.Object);
+        else if (unoName.Equals(Constants.UnoAny)) {
+            buf.Append (Constants.Any);
+        } else {
+            //put "unoidl." at the beginning
+            buf.Append (Constants.Unoidl);
+            buf.Append (MapUnoPolymorphicName (unoName));
+        }
+
+        // apend []
+        for (;dims-- > 0;)
+            buf.Append (Constants.Brackets);
+
+        // Console.WriteLine ("MapUnoTypeName {0} => {1}", typeName, buf.ToString ());
+
+        return buf.ToString();
+    }
+
+    public Type GetType (UnoXCompoundTypeDescription xtd)
+    {
+        // Console.WriteLine ("get compound type {0}", xtd.Name);
+
+        if (xtd.TypeClass == UnoTypeClass.Exception) {
+            if (xtd.Name.Equals ("com.sun.star.uno.Exception"))
+                return TypeException ();
+
+            if (xtd.Name.Equals ("com.sun.star.uno.RuntimeException"))
+                return TypeRuntimeException ();
+        }
+
+        string name = "unoidl." + xtd.Name;
+
+        // if the struct is an instantiated polymorpic struct then we create the simple struct name
+        // For example:
+        //   void func ([in] PolyStruct<boolean> arg);
+        //   PolyStruct<boolean> will be converted to PolyStruct
+        name = PolymorphicStructNameToStructName (name);
+
+        Type ret = GetType (name, false /* no exc */);
+        UnoXStructTypeDescription xsd = xtd as UnoXStructTypeDescription;
+
+        if (ret == null) {
+            // Console.WriteLine ("create compound type {0}", name);
+            UnoXTypeDescription baseTD = xtd.BaseType;
+            Type baseType = baseTD != null ? GetType (baseTD) : typeof (object);
+            CustomAttributeBuilder attrBuilder;
+            TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
+                                                                 TypeAttributes.Public |
+                                                                 TypeAttributes.BeforeFieldInit |
+                                                                 TypeAttributes.AnsiClass,
+                                                                 baseType);
+            int i;
+
+            // Polymorphic struct, define uno.TypeParametersAttribute
+            // A polymorphic struct cannot have a basetype.
+            // When we create the template of the struct then we have no exact types
+            // and the name does not contain a parameter list
+            if (xsd != null && xsd.TypeParameters > 0) {
+                object[] args = new object [xsd.TypeParameters];
+
+                for (i = 0; i < xsd.TypeParameters; i ++)
+                    args [i] = xsd.TypeParameter (i);
+                object[] aargs = { args };
+
+                Type[] typesCtor = { typeof (string[]) };
+                attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeParametersAttribute).GetConstructor (typesCtor), aargs);
+                typeBuilder.SetCustomAttribute (attrBuilder);
+            }
+
+            // optional: lookup base type whether generated entry of this session
+            StructEntry baseTypeEntry = null;
+            if (baseType != null)
+                baseTypeEntry = (StructEntry) mGeneratedStructs [baseType.FullName];
+
+            // members
+            for (i = 0; i < xtd.MemberTypes; i ++) {
+                if (xtd.MemberType (i) == null)
+                    throw new Exception ("Missing type description . Check if you need to " +
+                                         "specify additional RDBs with the --extra option. Type missing for: " +
+                                         xtd.Name + "::" + xtd.MemberName (i));
+            }
+
+            // collect base types; wrong order
+            ArrayList baseTypes = new ArrayList (3);
+            int allMembersLength = 0;
+            for (Type baseTypePos = baseType; !baseTypePos.Equals (typeof (object)); baseTypePos = baseTypePos.BaseType) {
+                baseTypes.Add (baseTypePos);
+                if (baseTypePos.Equals (typeof (System.Exception))) {
+                    // special Message member
+                    allMembersLength ++;
+                    break; // don't include System.Exception base classes
+                } else {
+                    allMembersLength += baseTypePos.GetFields (BindingFlags.Instance |
+                                                               BindingFlags.Public |
+                                                               BindingFlags.DeclaredOnly).Length;
+                }
+            }
+
+            // create all_members arrays; right order
+            string[] allMemberNames = new string [allMembersLength + xtd.MemberTypes];
+            Type[] allParamTypes = new Type [allMembersLength + xtd.MemberTypes];
+            int memberPos = 0;
+            for (i = baseTypes.Count - 1; i >= 0; i--) {
+                Type type = baseTypes [i] as Type;
+
+                if (type.Equals (typeof (System.Exception))) {
+                    allMemberNames [memberPos] = "Message";
+                    allParamTypes [memberPos] = typeof (string);
+                    memberPos ++;
+                } else {
+                    StructEntry baseEntry = mGeneratedStructs [type.FullName] as StructEntry;
+                    if (baseEntry == null) {
+                        // complete type
+                        FieldInfo[] fields = type.GetFields (BindingFlags.Instance |
+                                                             BindingFlags.Public |
+                                                             BindingFlags.DeclaredOnly);
+                        foreach (FieldInfo fieldInfo in fields) {
+                            allMemberNames [memberPos] = fieldInfo.Name;
+                            allParamTypes [memberPos] = fieldInfo.FieldType;
+                            memberPos ++;
+                        }
+                    } else {
+                        // generated during this session:
+                        // members may be incomplete ifaces
+                        int j;
+                        for (j = 0; j < baseEntry.mParamTypes.Length; j ++) {
+                            allMemberNames [memberPos] = baseEntry.mMemberNames [j];
+                            allParamTypes [memberPos] = baseEntry.mParamTypes [j];
+                            memberPos ++;
+                        }
+                    }
+                }
+            }
+            if (allMembersLength != memberPos)
+                throw new Exception ("something went wrong, allMembersLength != memberPos");
+
+
+            // build up entry
+            StructEntry entry = new StructEntry ();
+            entry.mMemberNames = new string [xtd.MemberTypes];
+            entry.mParamTypes = new Type [xtd.MemberTypes];
+
+            // add members
+            FieldBuilder[] members = new FieldBuilder [xtd.MemberTypes];
+            int curParamIndex = 0;
+            int typeParamPos = 0;
+
+            for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
+                string fieldName = xtd.MemberName (memberPos);
+                Type fieldType;
+
+                //Special handling of struct parameter types
+                bool parameterizedType = false;
+                if (xtd.MemberType (memberPos).TypeClass == UnoTypeClass.Unknown) {
+                    parameterizedType = true;
+                    if (xsd != null && typeParamPos < xsd.TypeParameters) {
+                        fieldType = typeof (object);
+                        typeParamPos ++;
+                    } else {
+                        throw new Exception ("unexpected member type in " + xtd.Name);
+                    }
+                } else {
+                    fieldType = GetType (xtd.MemberType (memberPos));
+                }
+                members [memberPos] = typeBuilder.DefineField (fieldName, fieldType, FieldAttributes.Public);
+
+                //parameterized type (polymorphic struct) ?
+                if (parameterizedType && xsd != null) {
+                    object[] args = { xsd.TypeParameter (curParamIndex ++) };
+                    Type[] ctorTypes = { typeof (string) };
+                    attrBuilder = new CustomAttributeBuilder (typeof (uno.ParameterizedTypeAttribute).GetConstructor (ctorTypes), args);
+                    members [memberPos].SetCustomAttribute (attrBuilder);
+                }
+
+                // add to all_members
+                allMemberNames [allMembersLength + memberPos] = fieldName;
+                allParamTypes [allMembersLength + memberPos] = fieldType;
+
+                // add to entry
+                entry.mMemberNames [memberPos] = fieldName;
+                entry.mParamTypes [memberPos] = fieldType;
+            }
+
+            allMembersLength += xtd.MemberTypes;
+
+            // default .ctor
+            ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, new Type [0]);
+            ILGenerator code = ctorBuilder.GetILGenerator ();
+
+            code.Emit (OpCodes.Ldarg_0);
+            // Console.WriteLine ("baseType: {0}", baseType);
+            code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (new Type [0]) : baseTypeEntry.mDefaultConstructor);
+
+            // default initialize members
+            for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
+                FieldInfo fieldInfo = members [memberPos];
+
+                // default initialize
+                // string, type, enum, sequence, struct, exception, any
+                if (fieldInfo.FieldType.Equals (typeof (string))) {
+                    code.Emit (OpCodes.Ldarg_0);
+                    code.Emit (OpCodes.Ldstr, "");
+                    code.Emit (OpCodes.Stfld, fieldInfo);
+                } else if (fieldInfo.FieldType.Equals (typeof (Type))) {
+                    code.Emit (OpCodes.Ldarg_0);
+                    code.Emit (OpCodes.Ldtoken, typeof (void));
+                    code.Emit (OpCodes.Call, mMethodInfoTypeGetTypeFromHandle);
+                    code.Emit (OpCodes.Stfld, fieldInfo);
+                } else if (fieldInfo.FieldType.IsArray) {
+                    code.Emit (OpCodes.Ldarg_0);
+                    code.Emit (OpCodes.Ldc_I4_0);
+                    code.Emit (OpCodes.Newarr, fieldInfo.FieldType.GetElementType ());
+                    code.Emit (OpCodes.Stfld, fieldInfo);
+                } else if (fieldInfo.FieldType.IsValueType) {
+                    if (fieldInfo.FieldType.FullName.Equals ("uno.Any")) {
+                        code.Emit (OpCodes.Ldarg_0);
+                        code.Emit (OpCodes.Ldsfld, typeof (uno.Any).GetField ("VOID"));
+                        code.Emit (OpCodes.Stfld, fieldInfo);
+                    }
+                } else if (fieldInfo.FieldType.IsClass) {
+                    // may be XInterface
+                    if (!fieldInfo.FieldType.Equals (typeof (object))) {
+                        code.Emit (OpCodes.Ldarg_0);
+                        code.Emit (OpCodes.Newobj, fieldInfo.FieldType.GetConstructor (new Type [0]));
+                        code.Emit (OpCodes.Stfld, fieldInfo);
+                    }
+                }
+            }
+
+            code.Emit (OpCodes.Ret);
+            entry.mDefaultConstructor = ctorBuilder;
+
+            // parameterized .ctor including all base members
+            ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, allParamTypes);
+            for (memberPos = 0; memberPos < allMembersLength; memberPos ++)
+                ctorBuilder.DefineParameter (memberPos + 1, ParameterAttributes.In, allMemberNames [memberPos]);
+
+            code = ctorBuilder.GetILGenerator ();
+            // call base .ctor
+            code.Emit (OpCodes.Ldarg_0); // push this
+            int baseMembersLength = allMembersLength - xtd.MemberTypes;
+            Type[] paramTypes = new Type [baseMembersLength];
+
+            for (memberPos = 0; memberPos < baseMembersLength; memberPos ++) {
+                EmitLdarg (code, memberPos + 1);
+                paramTypes [memberPos] = allParamTypes [memberPos];
+            }
+
+            code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (paramTypes) : baseTypeEntry.mConstructor);
+
+            // initialize members
+
+            for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
+                code.Emit (OpCodes.Ldarg_0); // push this
+                EmitLdarg (code, memberPos + baseMembersLength + 1);
+                code.Emit (OpCodes.Stfld, members [memberPos]);
+            }
+
+            code.Emit (OpCodes.Ret);
+            entry.mConstructor = ctorBuilder;
+
+            if (mConfig.mVerbose)
+                Console.WriteLine ("> emitting {0} type {1}", xtd is UnoXStructTypeDescription ? "struct" : "exception", name);
+
+            // new entry
+            mGeneratedStructs.Add (name, entry);
+            //Console.WriteLine ("added entry to mGeneratedStructs: {0}", name);
+            //if (baseTD != null)
+            //Console.WriteLine ("baseTD: {0}", baseTD.Name, GetType (baseTD).Name);
+            ret = typeBuilder.CreateType ();
+        }
+
+        // This is neaded
+        // for constructing the service code. We can only do that if the
+        // struct is completed.
+        StructEntry anEntry = mGeneratedStructs [name] as StructEntry;
+        if ( anEntry != null && xsd != null && xsd.TypeArguments > 0) {
+            //Console.WriteLine ("polymorphic struct: call uno.PolymorphicType.GetType ({0}, {1})", ret, xtd.Name);
+            ret = uno.PolymorphicType.GetType (ret, MapUnoTypeName (xtd.Name));
+            //Console.WriteLine ("polymorphic struct: {0} ({1})", ret, xtd.Name);
+        }
+
+        return ret;
+    }
+
+    public Type GetType (UnoXConstantTypeDescription xtd)
+    {
+        //Console.WriteLine ("get constant type {0}", xtd.Name);
+
+        string name = "unoidl." + xtd.Name;
+
+        Type ret = GetType (name, false /* no exc */);
+
+        if (ret == null) {
+            object constant = xtd.ConstantValue;
+
+            TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
+                                                                 TypeAttributes.Public |
+                                                                 TypeAttributes.Sealed |
+                                                                 TypeAttributes.BeforeFieldInit |
+                                                                 TypeAttributes.AnsiClass);
+            FieldBuilder field = typeBuilder.DefineField (name.Substring (name.LastIndexOf ('.') + 1),
+                                                          constant.GetType (),
+                                                          FieldAttributes.Public |
+                                                          FieldAttributes.Static |
+                                                          FieldAttributes.Literal);
+            field.SetConstant (constant);
+
+            if (mConfig.mVerbose)
+                Console.WriteLine ("> emitting constant type {0}", name);
+
+            ret = typeBuilder.CreateType ();
+        }
+
+        return ret;
+    }
+
+    public Type GetType (UnoXConstantsTypeDescription xtd)
+    {
+        //Console.WriteLine ("get constants type {0}", xtd.Name);
+
+        string name = "unoidl." + xtd.Name;
+
+        Type ret = GetType (name, false /* no exc */);
+
+        if (ret == null) {
+            TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
+                                                                 TypeAttributes.Public |
+                                                                 TypeAttributes.Sealed |
+                                                                 TypeAttributes.BeforeFieldInit |
+                                                                 TypeAttributes.AnsiClass);
+            int i;
+            for (i = 0; i < xtd.Constants; i ++) {
+                UnoXConstantTypeDescription constantTD = xtd.Constant (i);
+                object constant = constantTD.ConstantValue;
+                FieldBuilder field = typeBuilder.DefineField (constantTD.Name.Substring (constantTD.Name.LastIndexOf ('.') + 1),
+                                                              constant.GetType (),
+                                                              FieldAttributes.Public |
+                                                              FieldAttributes.Static |
+                                                              FieldAttributes.Literal);
+                field.SetConstant (constant);
+            }
+
+            if (mConfig.mVerbose)
+                Console.WriteLine ( "> emitting constants group type {0}", name);
+
+            ret = typeBuilder.CreateType ();
+        }
+
+        return ret;
+    }
+
+    public Type GetType (UnoXSingletonTypeDescription xtd)
+    {
+        //Console.WriteLine ("get singleton {0}", xtd.Name);
+
+        if (!xtd.IsInterfaceBased)
+            return null;
+
+        //Console.WriteLine ("singleton {0} is interface based", xtd.Name);
+
+        string name = "unoidl." + xtd.Name;
+
+        Type ret = GetType (name, false /* no exc */);
+
+        if (ret != null)
+            return ret;
+
+        TypeAttributes attr =
+            TypeAttributes.Public |
+            TypeAttributes.Sealed |
+            TypeAttributes.BeforeFieldInit |
+            TypeAttributes.AnsiClass;
+
+        // insert to be completed
+        SingletonEntry entry = new SingletonEntry ();
+        entry.mType = xtd;
+        entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr);
+        mIncompleteSingletons.Add (name, entry);
+
+        return entry.mTypeBuilder;
+    }
+
+    public Type GetType (UnoXTypeDescription xtd)
+    {
+        UnoTypeClass tc = xtd.TypeClass;
+
+        switch (tc) {
+        case UnoTypeClass.Void:
+            return typeof (void);
+        case UnoTypeClass.Char:
+            return typeof (char);
+        case UnoTypeClass.Boolean:
+            return typeof (bool);
+        case UnoTypeClass.Byte:
+            return typeof (byte);
+        case UnoTypeClass.Short:
+            return typeof (Int16);
+        case UnoTypeClass.UnsignedShort:
+            return typeof (UInt16);
+        case UnoTypeClass.Long:
+            return typeof (Int32);
+        case UnoTypeClass.UnsignedLong:
+            return typeof (UInt32);
+        case UnoTypeClass.Hyper:
+            return typeof (Int64);
+        case UnoTypeClass.UnsignedHyper:
+            return typeof (UInt64);
+        case UnoTypeClass.Float:
+            return typeof (Single);
+        case UnoTypeClass.Double:
+            return typeof (double);
+        case UnoTypeClass.String:
+            return typeof (string);
+        case UnoTypeClass.Type:
+            return typeof (Type);
+        case UnoTypeClass.Any:
+            return typeof (uno.Any);
+        case UnoTypeClass.Enum:
+            return GetType (xtd as UnoXEnumTypeDescription);
+        case UnoTypeClass.Interface:
+            return GetType (xtd as UnoXInterfaceTypeDescription);
+        case UnoTypeClass.Struct:
+        case UnoTypeClass.Exception:
+            return GetType (xtd as UnoXCompoundTypeDescription);
+        case UnoTypeClass.Module:
+            return null;
+        case UnoTypeClass.Sequence:
+            Type elementType = GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType);
+            Type retType = GetType (elementType.FullName + "[]", true);
+            uno.PolymorphicType polyType = elementType as uno.PolymorphicType;
+            if (polyType != null) {
+                string name = polyType.PolymorphicName + "[]";
+                retType = uno.PolymorphicType.GetType (retType, name);
+            }
+            return retType;
+        case UnoTypeClass.Typedef:
+            return GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType);
+        case UnoTypeClass.Constant:
+            return GetType (xtd as UnoXConstantTypeDescription);
+        case UnoTypeClass.Constants:
+            return GetType (xtd as UnoXConstantsTypeDescription);
+        case UnoTypeClass.Service:
+            return GetType (xtd as UnoXServiceTypeDescription);
+        case UnoTypeClass.Singleton:
+            return GetType (xtd as UnoXSingletonTypeDescription);
+        default:
+            // fixme, use double for unfinished types
+            //Console.WriteLine ("warning: unfinished type reached: {0}", xtd.Name);
+            return typeof (void);
+        }
+
+        //throw new Exception (String.Format ("Unknown type requested {0}", tc));
+    }
+
+    CustomAttributeBuilder IFaceMethodExceptionAttribute (UnoXInterfaceMethodTypeDescription method)
+    {
+        Type[] exceptionTypes = new Type [method.ExceptionTypes];
+        int i;
+
+        for (i = 0; i < method.ExceptionTypes; i ++) {
+            exceptionTypes [i] = GetType (method.ExceptionType (i));
+        }
+
+        return ExceptionAttribute (exceptionTypes);
+    }
+
+    CustomAttributeBuilder ExceptionAttribute (Type[] exceptionTypes)
+    {
+        CustomAttributeBuilder attrBuilder = null;
+
+        if (exceptionTypes.Length > 0) {
+            object[] args = { exceptionTypes };
+            Type[] arTypesCtor = { typeof (Type[]) };
+            ConstructorInfo ctorInfo = typeof (uno.ExceptionAttribute).GetConstructor (arTypesCtor);
+            attrBuilder = new CustomAttributeBuilder (ctorInfo, args);
+        }
+
+        return attrBuilder;
+    }
+
+    Type[] GetTypes (UnoXTypeDescription[] tds)
+    {
+        Type[] types = new Type [tds.Length];
+        int i;
+
+        for (i = 0; i < tds.Length; i ++)
+            types [i] = GetType (tds [i]);
+
+        return types;
+    }
+
+    Type CompleteIFaceType (IFaceEntry entry)
+        {
+            //Console.WriteLine ("going to complete {0}", entry.mTypeBuilder.FullName);
+
+    // complete base interfaces first
+            foreach (Type type in entry.mTypeBuilder.GetInterfaces ()) {
+                IFaceEntry baseEntry = mIncompleteIFaces [type.FullName] as IFaceEntry;
+                if (baseEntry != null)
+                    CompleteIFaceType (baseEntry);
+            }
+
+            // emit members
+            const MethodAttributes methodAttr =
+                MethodAttributes.Public |
+                MethodAttributes.Abstract |
+                MethodAttributes.Virtual |
+                MethodAttributes.NewSlot |
+                MethodAttributes.HideBySig;
+            int i;
+
+            for (i = 0; i < entry.mType.Members; i ++) {
+                UnoXInterfaceMemberTypeDescription member = entry.mType.Member (i);
+                MethodBuilder methodBuilder;
+                CustomAttributeBuilder attrBuilder;
+
+                if (member.TypeClass == UnoTypeClass.InterfaceMethod) {
+                    UnoXInterfaceMethodTypeDescription method = new UnoXInterfaceMethodTypeDescription (member.Handle);
+                    UnoXMethodParameter[] parameters = new UnoXMethodParameter [method.Parameters];
+                    Type[] pTypes = new Type [method.Parameters];
+                    int j;
+
+                    //Console.WriteLine ("method {0}.{1}", entry.mTypeBuilder.FullName, method.MemberName);
+
+                    // first determine all types
+                    for (j = 0; j < method.Parameters; j ++) {
+                        parameters [j] = method.Parameter (j);
+                        pTypes [j] = GetType (parameters [j].Type);
+                        if (parameters [j].IsOut)
+                            pTypes [j] = GetType (pTypes [j].FullName + "&", true);
+                    }
+
+                    // create method
+                    methodBuilder = entry.mTypeBuilder.DefineMethod (method.MemberName,
+                                                                     methodAttr,
+                                                                     GetType (method.ReturnType),
+                                                                     pTypes);
+
+                    // then define parameter infos
+                    for (j = 0; j < method.Parameters; j ++) {
+                        ParameterAttributes attr = 0;
+                        if (parameters [j].IsIn)
+                            attr |= ParameterAttributes.In;
+                        if (parameters [j].IsOut)
+                            attr |= ParameterAttributes.Out;
+
+                        if (attr == 0)
+                            throw new Exception ("wrong parameter attributes");
+
+                        methodBuilder.DefineParameter (parameters [j].Position + 1,
+                                                       attr,
+                                                       parameters [j].Name);
+                    }
+
+                    if (method.ReturnsStruct) {
+                        // Console.WriteLine ("returns struct");
+
+                        UnoXStructTypeDescription std = method.ReturnType as UnoXStructTypeDescription;
+                        if (std.TypeArguments != 0) {
+                            // Console.WriteLine ("std: '{0}' '{1}' {2}", std, method.ReturnType, method.ReturnType.Name);
+                            Type[] ats = new Type [std.TypeArguments];
+
+                            // Console.WriteLine ("type arguments: {0}", std.TypeArguments);
+
+                            for (j = 0; j < std.TypeArguments; j ++) {
+                                ats [j] = GetType (std.TypeArgument (j));
+                                //Console.WriteLine ("ats [{0}] = {1}", j, ats [j]);
+                            }
+
+                            object[] atso = { ats };
+                            Type[] ctor = { typeof (Type[]) };
+                            attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeArgumentsAttribute).GetConstructor (ctor),
+                                                                  atso);
+                            methodBuilder.SetCustomAttribute (attrBuilder);
+                        }
+                    }
+
+                    // define UNO exception attribute (exceptions) --------------------------------------
+                    attrBuilder = IFaceMethodExceptionAttribute (method);
+                    if (attrBuilder != null)
+                        methodBuilder.SetCustomAttribute (attrBuilder);
+
+                    // oneway attribute
+                    if (method.IsOneway) {
+                        Type[] arCtorOneway = new Type [0];
+                        object[] arArgs = new object [0];
+                        attrBuilder = new CustomAttributeBuilder (typeof (uno.OnewayAttribute).GetConstructor (arCtorOneway),
+                                                                  arArgs);
+                        methodBuilder.SetCustomAttribute (attrBuilder);
+                    }
+                } else {
+                    // attribute
+                    if (member.TypeClass != UnoTypeClass.InterfaceAttribute)
+                        throw new Exception (String.Format ("Unknown member type class: {0} ", member.TypeClass));
+
+                    UnoXInterfaceAttributeTypeDescription attribute = new UnoXInterfaceAttributeTypeDescription (member.Handle);
+                    const MethodAttributes propMethodAttr = methodAttr | MethodAttributes.SpecialName;
+
+                    Type attrType = GetType (attribute.Type);
+                    //Console.WriteLine ("attribute {2} type: {0} => {1}", attribute.Type, attrType, attribute.Name);
+                    Type[] parameters = new Type [0];
+
+                    PropertyBuilder propBuilder = entry.mTypeBuilder.DefineProperty (attribute.MemberName, PropertyAttributes.None, attrType, parameters);
+
+                    //set BoundAttribute, if necessary
+                    if (attribute.IsBound) {
+                        ConstructorInfo ctorBoundAttr = typeof (uno.BoundAttribute).GetConstructor (new Type [0]);
+                        attrBuilder = new CustomAttributeBuilder (ctorBoundAttr, new object [0]);
+                        propBuilder.SetCustomAttribute (attrBuilder);
+                    }
+
+                    // getter
+                    methodBuilder = entry.mTypeBuilder.DefineMethod ("get_" + attribute.MemberName,
+                                                                     propMethodAttr, attrType, parameters);
+
+                    attrBuilder = ExceptionAttribute (GetTypes (attribute.GetExceptionTypes));
+                    if (attrBuilder != null)
+                        methodBuilder.SetCustomAttribute (attrBuilder);
+
+                    propBuilder.SetGetMethod (methodBuilder);
+
+                    if (!attribute.IsReadOnly) {
+                        // setter
+                        parameters = new Type [1];
+                        parameters [0] = attrType;
+                        //parameters [0] = null;
+                        //Console.WriteLine ("setter parameters: {0} ({1})", parameters, parameters [0]);
+                        methodBuilder = entry.mTypeBuilder.DefineMethod ("set_" + attribute.MemberName,
+                                                                         propMethodAttr, typeof (void), parameters);
+                        methodBuilder.DefineParameter (1, ParameterAttributes.In, "value");
+
+                        attrBuilder = ExceptionAttribute (GetTypes (attribute.SetExceptionTypes));
+                        if (attrBuilder != null)
+                            methodBuilder.SetCustomAttribute (attrBuilder);
+
+                        propBuilder.SetSetMethod (methodBuilder);
+                    }
+                }
+            }
+            //	cmm_x_interface_type_description_members_release (membersHandle);
+
+            if (mConfig.mVerbose)
+                Console.WriteLine ("> emitting interface type {0}", "unoidl." + entry.mType.Name);
+
+            mIncompleteIFaces.Remove (entry.mTypeBuilder.FullName);
+
+            //Console.WriteLine ("completed {0}", entry.mTypeBuilder.FullName);
+
+            return entry.mTypeBuilder.CreateType ();
+    }
+
+    UnoXInterfaceTypeDescription ResolveInterfaceTypedef (UnoXTypeDescription xtd)
+    {
+        UnoXInterfaceTypeDescription xtdIface = xtd as UnoXInterfaceTypeDescription;
+
+        if (xtdIface != null)
+            return xtdIface;
+
+        UnoXIndirectTypeDescription xtdIndirect = xtd as UnoXIndirectTypeDescription;
+
+        if (xtdIndirect != null)
+            return ResolveInterfaceTypedef (xtdIndirect.ReferencedType);;
+
+        throw new Exception ("resolveInterfaceTypedef was called with an invalid argument");
+    }
+
+    ArrayList GetServiceConstructorMethodExceptionsReduced (UnoXTypeDescription[] exceptionTypes)
+    {
+        if (exceptionTypes.Length == 0)
+            return new ArrayList ();
+
+        ArrayList types = new ArrayList();
+        int i;
+
+        for (i = 0; i < exceptionTypes.Length; i ++)
+            types.Add (GetType ("unoidl." + exceptionTypes [i].Name, true));
+
+        int start = 0;
+        while (true) {
+            bool bRemove = false;
+
+            for (i = start; i < types.Count; i ++) {
+                Type t = types [i] as Type;
+                int j;
+
+                for (j = 0; j < types.Count; j ++) {
+                    if (t.IsSubclassOf (types [j] as Type)) {
+                        types.RemoveAt (i);
+                        bRemove = true;
+                        break;
+                    }
+                }
+                if (bRemove)
+                    break;
+                start ++;
+            }
+
+            if (bRemove == false)
+                break;
+        }
+
+        return types;
+    }
+
+    Type CompleteServiceType (ServiceEntry entry)
+    {
+        // Create the private default constructor
+        ConstructorBuilder ctorBuilder = entry.mTypeBuilder.DefineConstructor (MethodAttributes.Private |
+                                                                               MethodAttributes.HideBySig |
+                                                                               MethodAttributes.SpecialName |
+                                                                               MethodAttributes.RTSpecialName,
+                                                                               CallingConventions.Standard,
+                                                                               null);
+
+        ILGenerator ilGen = ctorBuilder.GetILGenerator ();
+        ilGen.Emit (OpCodes.Ldarg_0);  // push this
+        ilGen.Emit (OpCodes.Call, entry.mTypeBuilder.BaseType.GetConstructor (new Type[0]));
+        ilGen.Emit (OpCodes.Ret);
+
+        // Create the service constructors.
+        // obtain the interface which makes up this service, it is the return
+        // type of the constructor functions
+        UnoXInterfaceTypeDescription iface = entry.mType.Interface as UnoXInterfaceTypeDescription;
+
+        if (iface == null)
+            iface = ResolveInterfaceTypedef (entry.mType.Interface);
+
+        Type ret = GetType (iface);
+
+        // Create the ConstructorInfo for a DeploymentException
+        Type typeDeploymentException = GetType ("unoidl.com.sun.star.uno.DeploymentException", true);
+        Type[] arTypeCtor = { typeof (string), typeof (object) };
+        ConstructorInfo ctorDeploymentException = typeDeploymentException.GetConstructor (arTypeCtor);
+
+        Type typeUnoException = GetType ("unoidl.com.sun.star.uno.Exception", true);
+        int i, j;
+
+        for (i = entry.mType.Constructors - 1; i >= 0; i --) {
+            bool bParameterArray = false;
+            UnoXServiceConstructorDescription ctorDesc = entry.mType.Constructor (i);
+            Type[] typeParameters = new Type [ctorDesc.Parameters + 1];
+            typeParameters [0] = GetType ("unoidl.com.sun.star.uno.XComponentContext", true);
+
+            for (j = 0; j < ctorDesc.Parameters; j ++) {
+                UnoXParameter parameter = ctorDesc.Parameter (j);
+
+                if (parameter.IsRest)
+                    typeParameters [j + 1] = typeof (uno.Any[]);
+                else
+                    typeParameters [j + 1] = GetType (parameter.Type);
+            }
+
+            // The array typeParameters can contain:
+            // System.Type and uno.PolymorphicType.
+            // Passing PolymorphicType to MethodBuilder.DefineMethod will cause a problem.
+            // The exception will read something like no on information for parameter # d
+            // Maybe we need no override another Type method in PolymorphicType ...
+            // Until we have figured this out, we will create another array of System.Type which
+            // we pass on to DefineMethod.
+
+            Type[] paramTypes = new Type [ctorDesc.Parameters + 1];
+
+            for (j = 0; j < ctorDesc.Parameters + 1; j ++) {
+                if (typeParameters [j] is uno.PolymorphicType)
+                    paramTypes [j] = (typeParameters [j] as uno.PolymorphicType).OriginalType;
+                else
+                    paramTypes [j] = typeParameters [j];
+            }
+
+            //define method
+            string ctorName;
+            if (ctorDesc.IsDefault)
+                ctorName = "create";
+            else
+                ctorName = ctorDesc.Name;
+
+            MethodBuilder methodBuilder = entry.mTypeBuilder.DefineMethod (ctorName,
+                                                                           MethodAttributes.Public |
+                                                                           MethodAttributes.HideBySig |
+                                                                           MethodAttributes.Static,
+                                                                           ret,
+                                                                           paramTypes);
+
+            //define UNO exception attribute (exceptions)--------------------------------------
+            CustomAttributeBuilder attrBuilder = ExceptionAttribute (GetTypes (ctorDesc.ExceptionTypes));
+            if (attrBuilder != null)
+                methodBuilder.SetCustomAttribute (attrBuilder);
+
+            // define parameter attributes (paramarray), names etc.
+            // The first parameter is the XComponentContext, which cannot be obtained
+            // from reflection.
+            // The context is not part of the idl description
+
+            methodBuilder.DefineParameter (1, ParameterAttributes.In, "the_context");
+
+            ParameterBuilder[] parameterBuilder = new ParameterBuilder [ctorDesc.Parameters];
+            int iparam;
+
+            for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) {
+                UnoXParameter parameter = ctorDesc.Parameter (iparam);
+
+                parameterBuilder [iparam] = methodBuilder.DefineParameter (iparam + 2, ParameterAttributes.In, parameter.Name);
+
+                if (parameter.IsRest) {
+                    bParameterArray = true;
+                    //set the ParameterArrayAttribute
+                    ConstructorInfo ctorInfo = typeof (System.ParamArrayAttribute).GetConstructor (new Type [0]);
+                    attrBuilder = new CustomAttributeBuilder (ctorInfo, new object [0]);
+
+                    parameterBuilder[iparam].SetCustomAttribute (attrBuilder);
+                    break;
+                }
+            }
+
+            ilGen = methodBuilder.GetILGenerator ();
+
+            // Define locals ---------------------------------
+            // XMultiComponentFactory
+            LocalBuilder localFactory = ilGen.DeclareLocal (GetType ("unoidl.com.sun.star.lang.XMultiComponentFactory", true));
+
+            // The return type
+            LocalBuilder localReturnVal = ilGen.DeclareLocal (ret);
+
+            // Obtain the XMultiComponentFactory and throw an exception if we do not get one
+            ilGen.Emit (OpCodes.Ldarg_0);
+
+            MethodInfo methodGetServiceManager = GetType ("unoidl.com.sun.star.uno.XComponentContext", true).GetMethod ("getServiceManager");
+            ilGen.Emit (OpCodes.Callvirt, methodGetServiceManager);
+            ilGen.Emit (OpCodes.Stloc, localFactory);
+            ilGen.Emit (OpCodes.Ldloc, localFactory);
+            Label label1 = ilGen.DefineLabel ();
+            ilGen.Emit (OpCodes.Brtrue, label1);
+
+            // The string for the exception
+            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder (256);
+
+            strBuilder.Append ("The service ");
+            strBuilder.Append ("unoidl." + entry.mType.Name);
+            strBuilder.Append (" could not be created. The context failed to supply the service manager.");
+
+            ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString ());
+            ilGen.Emit (OpCodes.Ldarg_0);
+            ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
+            ilGen.Emit (OpCodes.Throw);
+            ilGen.MarkLabel (label1);
+
+            // We create a try/ catch around the createInstanceWithContext, etc. functions
+            // There are 3 cases
+            // 1. function do not specify exceptions. Then RuntimeExceptions are retrhown and other
+            //    exceptions produce a DeploymentException.
+            // 2. function specify  Exception. Then all exceptions fly through
+            // 3. function specifies exceptions but no Exception. Then these are rethrown
+            //    and other exceptions, except RuntimeException, produce a deployment exception.
+            // In case there are no parameters we call
+            // XMultiComponentFactory.createInstanceWithContext
+
+            ArrayList exceptionTypes = GetServiceConstructorMethodExceptionsReduced (ctorDesc.ExceptionTypes);
+            if (!exceptionTypes.Contains (typeUnoException)) {
+                ilGen.BeginExceptionBlock ();
+            }
+
+            if (ctorDesc.Parameters == 0) {
+                ilGen.Emit (OpCodes.Ldloc, localFactory);
+                ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
+                ilGen.Emit (OpCodes.Ldarg_0);
+
+                MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithContext");
+                ilGen.Emit (OpCodes.Callvirt, methodCreate);
+            } else if(bParameterArray) {
+                //Service constructor with parameter array
+                ilGen.Emit (OpCodes.Ldloc, localFactory);
+                ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
+                ilGen.Emit (OpCodes.Ldarg_1);
+                ilGen.Emit (OpCodes.Ldarg_0);
+                MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext");
+                ilGen.Emit(OpCodes.Callvirt, methodCreate);
+            } else {
+                // Any param1, Any param2, etc.
+                // For each parameter,except the component context, and parameter array
+                // and Any is created.
+                LocalBuilder[] localAny = new LocalBuilder [ctorDesc.Parameters];
+
+                for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) {
+                    localAny [iparam] = ilGen.DeclareLocal (typeof (uno.Any));
+                }
+
+                // Any[]. This array is filled with the created Anys which contain the parameters
+                // and the values contained in the parameter array
+                LocalBuilder localAnyParams = ilGen.DeclareLocal (typeof (uno.Any []));
+
+                // Create the Any for every argument, except for the parameter array
+                // arLocalAny contains the LocalBuilder for all these parameters.
+                // we call the ctor Any(Type, Object)
+                // If the parameter is an Any then the Any is created with Any(param.Type, param.Value);
+                Type[] typesCtorAny = { typeof (Type),
+                                        typeof (object) };
+                ConstructorInfo ctorAny = typeof (uno.Any).GetConstructor (typesCtorAny);
+                MethodInfo methodAnyGetType = typeof (uno.Any).GetProperty ("Type").GetGetMethod ();
+                MethodInfo methodAnyGetValue = typeof (uno.Any).GetProperty ("Value").GetGetMethod ();
+
+                for (j = 0; j < localAny.Length; j ++) {
+                    //check if the parameter is a polymorphic struct
+                    if (typeParameters [j + 1] is uno.PolymorphicType) {
+                        // It is a polymorphic struct
+                        uno.PolymorphicType polyType = typeParameters [j + 1] as uno.PolymorphicType;
+
+                        // Load the uninitialized local Any on which we will call the ctor
+                        ilGen.Emit (OpCodes.Ldloca, localAny [j]);
+
+                        // Call PolymorphicType PolymorphicType::GetType(Type t, String polyName)
+                        // Prepare the first parameter
+                        ilGen.Emit (OpCodes.Ldtoken, polyType.OriginalType);
+                        Type[] typeParams = { typeof (System.RuntimeTypeHandle) };
+                        ilGen.Emit (OpCodes.Call, typeof(Type).GetMethod ("GetTypeFromHandle", typeParams));
+
+                        // Prepare the second parameter
+                        ilGen.Emit (OpCodes.Ldstr, polyType.PolymorphicName);
+
+                        // Make the actual call
+                        Type[] typeParamGetType = { typeof (Type), typeof (string) };
+                        ilGen.Emit (OpCodes.Call,
+                                    typeof (uno.PolymorphicType).GetMethod("GetType",
+                                                                           typeParamGetType));
+
+                        // Stack is: localAny, PolymorphicType
+                        // Call Any::Any(Type, Object)
+                        // Prepare the second parameter for the any ctor
+                        ilGen.Emit (OpCodes.Ldarg, j + 1);
+
+                        // if the parameter is a value type then we need to box it, because
+                        // the Any ctor takes an Object
+                        if (typeParameters [j + 1].IsValueType)
+                            ilGen.Emit (OpCodes.Box, typeParameters [j + 1]);
+                        ilGen.Emit (OpCodes.Call, ctorAny);
+                    } else if (typeParameters [j + 1] == typeof (uno.Any)) {
+                        // Create the call new Any(param.Type,param,Value)
+                        // Stack must be Any,Type,Value
+                        // First load the Any which is to be constructed
+                        ilGen.Emit (OpCodes.Ldloca, localAny [j]);
+
+                        //Load the Type, which is obtained by calling param.Type
+                        ilGen.Emit (OpCodes.Ldarga, j + 1);
+                        ilGen.Emit (OpCodes.Call, methodAnyGetType);
+
+                        //Load the Value, which is obtained by calling param.Value
+                        ilGen.Emit (OpCodes.Ldarga, j + 1);
+                        ilGen.Emit (OpCodes.Call, methodAnyGetValue);
+
+                        //Call the Any ctor.
+                        ilGen.Emit (OpCodes.Call, ctorAny);
+                    } else {
+                        ilGen.Emit (OpCodes.Ldloca, localAny [j]);
+                        ilGen.Emit (OpCodes.Ldtoken, typeParameters [j + 1]);
+
+                        Type[] typeParams = { typeof (System.RuntimeTypeHandle) };
+                        ilGen.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle", typeParams));
+                        ilGen.Emit(OpCodes.Ldarg, j + 1);
+
+                        // if the parameter is a value type then we need to box it, because
+                        // the Any ctor takes an Object
+                        if (typeParameters [j + 1].IsValueType)
+                            ilGen.Emit (OpCodes.Box, typeParameters [j + 1]);
+                        ilGen.Emit(OpCodes.Call, ctorAny);
+                    }
+                }
+
+
+                // Create the Any[] that is passed to the
+                // createInstanceWithContext[AndArguments] function
+                ilGen.Emit (OpCodes.Ldc_I4, localAny.Length);
+                ilGen.Emit (OpCodes.Newarr, typeof (uno.Any));
+                ilGen.Emit (OpCodes.Stloc, localAnyParams);
+
+                // Assign all anys created from the parameters
+                // array to the Any[]
+                for (j = 0; j < localAny.Length; j ++) {
+                    ilGen.Emit (OpCodes.Ldloc, localAnyParams);
+                    ilGen.Emit (OpCodes.Ldc_I4, j);
+                    ilGen.Emit (OpCodes.Ldelema, typeof (uno.Any));
+                    ilGen.Emit (OpCodes.Ldloc, localAny [j]);
+                    ilGen.Emit (OpCodes.Stobj, typeof (uno.Any));
+                }
+
+                // call createInstanceWithContextAndArguments
+                ilGen.Emit (OpCodes.Ldloc, localFactory);
+                ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
+                ilGen.Emit (OpCodes.Ldloc, localAnyParams);
+                ilGen.Emit (OpCodes.Ldarg_0);
+                MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext");
+                ilGen.Emit (OpCodes.Callvirt, methodCreate);
+            }
+
+            // cast the object returned by the functions createInstanceWithContext or
+            // createInstanceWithArgumentsAndContext to the interface type
+            ilGen.Emit (OpCodes.Castclass, ret);
+            ilGen.Emit (OpCodes.Stloc, localReturnVal);
+
+            //catch exceptions thrown by createInstanceWithArgumentsAndContext and createInstanceWithContext
+            if (!exceptionTypes.Contains (typeUnoException)) {
+                // catch (unoidl.com.sun.star.uno.RuntimeException) {throw;}
+                ilGen.BeginCatchBlock (GetType ("unoidl.com.sun.star.uno.RuntimeException", true));
+                ilGen.Emit (OpCodes.Pop);
+                ilGen.Emit (OpCodes.Rethrow);
+
+                //catch and rethrow all other defined Exceptions
+                for (j = 0; j < exceptionTypes.Count; j ++) {
+                    Type excType = exceptionTypes [j] as Type;
+                    if (excType.IsInstanceOfType (GetType ("unoidl.com.sun.star.uno.RuntimeException", true))) {
+                        // we have a catch for RuntimeException already defined
+                        continue;
+                    }
+
+                    //catch Exception and rethrow
+                    ilGen.BeginCatchBlock (excType);
+                    ilGen.Emit (OpCodes.Pop);
+                    ilGen.Emit (OpCodes.Rethrow);
+                }
+
+                //catch (unoidl.com.sun.star.uno.Exception) {throw DeploymentException...}
+                ilGen.BeginCatchBlock (typeUnoException);
+
+                //Define the local variabe that keeps the exception
+                LocalBuilder localException = ilGen.DeclareLocal (typeUnoException);
+
+                //Store the exception
+                ilGen.Emit (OpCodes.Stloc, localException);
+
+                //prepare the construction of the exception
+                strBuilder = new System.Text.StringBuilder (256);
+                strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
+                strBuilder.Append ("unoidl." + entry.mType.Name);
+                strBuilder.Append (": ");
+
+                ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString());
+
+                // add to the string the Exception.Message
+                ilGen.Emit (OpCodes.Ldloc, localException);
+                //Console.WriteLine ("get message property of type: {0}", typeUnoException);
+                ilGen.Emit (OpCodes.Callvirt, typeUnoException.GetProperty ("Message").GetGetMethod ());
+                Type[] concatParams = { typeof (string), typeof (string)};
+                ilGen.Emit (OpCodes.Call, typeof (string).GetMethod ("Concat", concatParams));
+
+                //load contex argument
+                ilGen.Emit (OpCodes.Ldarg_0);
+                ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
+                ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc);
+
+                ilGen.EndExceptionBlock();
+            }
+
+
+            // Check if the service instance was create and throw a exception if not.
+            Label labelServiceCreated = ilGen.DefineLabel ();
+            ilGen.Emit (OpCodes.Ldloc, localReturnVal);
+            ilGen.Emit (OpCodes.Brtrue_S, labelServiceCreated);
+
+            strBuilder = new System.Text.StringBuilder(256);
+            strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
+            strBuilder.Append ("unoidl." + entry.mType.Name);
+            strBuilder.Append (".");
+            ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString());
+            ilGen.Emit (OpCodes.Ldarg_0);
+            ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
+            ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc);
+
+            ilGen.MarkLabel (labelServiceCreated);
+            ilGen.Emit (OpCodes.Ldloc, localReturnVal);
+            ilGen.Emit (OpCodes.Ret);
+        }
+
+        mIncompleteServices.Remove (entry.mTypeBuilder.FullName);
+
+		if (mConfig.mVerbose)
+			Console.WriteLine("> emitting service type {0}", "unoidl." + entry.mType.Name);
+

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list