[Libreoffice-commits] .: Branch 'distro/suse/suse-3.6' - 16 commits - bin/distro-install-file-lists bin/distro-install-mono cli_ure/prj cli_ure/source cli_ure/unotypes cli_ure/util config_host.mk.in configure.in desktop/source Makefile.top oox/source scp2/InstallModule_ooo.mk scp2/source unoil/CustomTarget_climaker.mk

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Oct 13 03:25:23 PDT 2012


 Makefile.top                                                  |    1 
 bin/distro-install-file-lists                                 |    3 
 bin/distro-install-mono                                       |   96 
 cli_ure/prj/build.lst                                         |   19 
 cli_ure/prj/d.lst                                             |    4 
 cli_ure/source/basetypes/makefile.mk                          |   10 
 cli_ure/source/bootstrap/assembly.cs                          |    4 
 cli_ure/source/bootstrap/makefile.mk                          |  123 
 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/climaker/makefile.mk                           |   32 
 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/makefile.mk                        |  102 
 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/makefile.mk                        |   51 
 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/native/makefile.mk                             |    2 
 cli_ure/source/ure/makefile.mk                                |   22 
 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 
 cli_ure/unotypes/makefile.mk                                  |   18 
 cli_ure/util/makefile.pmk                                     |   16 
 cli_ure/util/target.pmk                                       |    2 
 config_host.mk.in                                             |   11 
 configure.in                                                  |  102 
 desktop/source/deployment/registry/component/dp_component.cxx |   10 
 oox/source/drawingml/textparagraphproperties.cxx              |    2 
 scp2/InstallModule_ooo.mk                                     |    1 
 scp2/source/ooo/file_library_ooo.scp                          |    6 
 scp2/source/ooo/ure.scp                                       |   64 
 unoil/CustomTarget_climaker.mk                                |    7 
 48 files changed, 10916 insertions(+), 52 deletions(-)

New commits:
commit 2d55646fe058929bca468757f587fc235de6dbdf
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Oct 11 12:13:52 2012 +0100

    we love you 32bit sal_Int32 as long
    
    Change-Id: I006bceae3d05d2c014beae2127ad8a57c9bee353

diff --git a/oox/source/drawingml/textparagraphproperties.cxx b/oox/source/drawingml/textparagraphproperties.cxx
index e3977af..87091c1 100644
--- a/oox/source/drawingml/textparagraphproperties.cxx
+++ b/oox/source/drawingml/textparagraphproperties.cxx
@@ -434,7 +434,7 @@ void TextParagraphProperties::pushToPropSet( const ::oox::core::XmlFilterBase* p
         {
             // Force Paragraph property as zero - impress seems to use the value from previous
             // (non) bullet line if not set to zero explicitly :(
-            aPropSet.setProperty( PROP_ParaFirstLineIndent, 0 );
+            aPropSet.setProperty( PROP_ParaFirstLineIndent, static_cast< sal_Int32>(0) );
             rioBulletMap[ PROP_FirstLineOffset ] <<= static_cast< sal_Int32 >( *noFirstLineIndentation );
             noFirstLineIndentation = boost::none;
         }
commit b3fef69f7047238f96b91ccc8c4ad0a1f34b9bb3
Author: Fridrich Strba <fridrich.strba at bluewin.ch>
Date:   Wed Aug 10 06:37:59 2011 -0600

    [mono] Make cli_ure build on windows again
    
    Change-Id: I4b79502121f9cb1577214a2c22ffa20bb599e419

diff --git a/cli_ure/prj/build.lst b/cli_ure/prj/build.lst
index f956044..7448a70 100644
--- a/cli_ure/prj/build.lst
+++ b/cli_ure/prj/build.lst
@@ -11,5 +11,5 @@ ure	cli_ure\source\ure                      nmake   -       all     ure_source_u
 ure cli_ure\source\uno_bridge	nmake	-	w,vc7	ure_source_uno_bridge ure_source_basetypes ure_unotypes ure_source_ure ure_inc NULL
 ure	cli_ure\source\mono_bridge	nmake	-	u		ure_source_mono_bridge ure_unotypes ure_source_ure ure_inc NULL
 ure	cli_ure\source\mono_loader      nmake   -       u       ure_source_mono_loader ure_unotypes ure_source_ure ure_inc NULL
-ure cli_ure\source\native		nmake	-	w,vc7	ure_source_native ure_source_version ure_source_source ure_source_ure ure_unotypes ure_source_uno_bridge ure_inc NULL
+ure cli_ure\source\native		nmake	-	w,vc7	ure_source_native ure_source_version ure_source_source ure_source_ure ure_unotypes ure_source_uno_bridge.w ure_inc NULL
 #ure cli_ure\util				nmake	-	w,vc7	ure_util ure_source_ure ure_source_native NULL
diff --git a/cli_ure/source/basetypes/makefile.mk b/cli_ure/source/basetypes/makefile.mk
index e24b6fb..1fe21ad 100644
--- a/cli_ure/source/basetypes/makefile.mk
+++ b/cli_ure/source/basetypes/makefile.mk
@@ -91,7 +91,7 @@ $(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_basetypes.config
     $(WRAPCMD) $(AL) -out:$@ \
             -version:$(CLI_BASETYPES_POLICY_VERSION) \
             -keyfile:$(BIN)$/cliuno.snk \
-            -link:cli_basetypes.config,$(BIN)$/cli_basetypes.config
+            -link:$(CLI_BASETYPES_CONFIG)
 
 
 #Create the config file that is used with the policy assembly
diff --git a/cli_ure/source/native/makefile.mk b/cli_ure/source/native/makefile.mk
index 8d41283..367e270 100644
--- a/cli_ure/source/native/makefile.mk
+++ b/cli_ure/source/native/makefile.mk
@@ -150,7 +150,7 @@ $(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_cppuhelper.config
     $(WRAPCMD) $(AL) -out:$@ \
             -version:$(CLI_CPPUHELPER_POLICY_VERSION) \
             -keyfile:$(BIN)$/cliuno.snk \
-            -link:cli_cppuhelper.config,$(BIN)$/cli_cppuhelper.config \
+            -link:$(BIN)$/cli_cppuhelper.config \
             -platform:x86
 
 #Create the config file that is used with the policy assembly
diff --git a/cli_ure/source/ure/makefile.mk b/cli_ure/source/ure/makefile.mk
index 175256b..b394e8b 100644
--- a/cli_ure/source/ure/makefile.mk
+++ b/cli_ure/source/ure/makefile.mk
@@ -99,7 +99,7 @@ $(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_ure.config
     $(WRAPCMD) $(AL) -out:$@ \
             -version:$(CLI_URE_POLICY_VERSION) \
             -keyfile:$(BIN)$/cliuno.snk \
-            -link:cli_ure.config,$(BIN)$/cli_ure.config
+            -link:$(CLI_URE_CONFIG)
 
 #Create the config file that is used with the policy assembly
 $(BIN)$/cli_ure.config: cli_ure_config $(BIN)$/cliureversion.mk 
diff --git a/cli_ure/unotypes/makefile.mk b/cli_ure/unotypes/makefile.mk
index 546583c..e278de4 100644
--- a/cli_ure/unotypes/makefile.mk
+++ b/cli_ure/unotypes/makefile.mk
@@ -43,7 +43,8 @@ TARGET = unotypes
 WRAPCMD=MONO_PATH=$(OUT)/bin:$(MONO_PATH) LD_LIBRARY_PATH=$(SOLARLIBDIR):$(OUT)/lib
 CLIMAKER=$(BIN)$/climaker
 .ELSE
-CLIMAKER=climaker.exe
+WRAPCMD=$(AUGMENT_LIBRARY_PATH)
+CLIMAKER=$(BIN)$/climaker.exe
 .ENDIF
 
 .INCLUDE : $(BIN)$/cliureversion.mk
@@ -75,7 +76,7 @@ $(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_uretypes.config $(OUT)$/bin$/cli_uretypes.
     $(WRAPCMD) $(AL) -out:$@ \
             -version:$(CLI_URETYPES_POLICY_VERSION) \
             -keyfile:$(BIN)$/cliuno.snk \
-            -link:cli_uretypes.config,$(BIN)$/cli_uretypes.config
+            -link:$(CLI_URETYPES_CONFIG)
 
 #Create the config file that is used with the policy assembly
 $(BIN)$/cli_uretypes.config: cli_uretypes_config $(BIN)$/cliureversion.mk 
diff --git a/cli_ure/util/makefile.pmk b/cli_ure/util/makefile.pmk
index 7dbe191..2422dc2 100644
--- a/cli_ure/util/makefile.pmk
+++ b/cli_ure/util/makefile.pmk
@@ -27,9 +27,23 @@
 
 # no translation here anyway
 .IF "$(L10N_framework)"==""
-.IF "$(COM)$(COMEX)" == "MSC11" || "$(COM)$(COMEX)"== "MSC10" || "$(ENABLE_MONO)" == "YES"
+.IF "$(COM)" == "MSC" || "$(ENABLE_MONO)" == "YES"
 BUILD_FOR_CLI = "true"
 CFLAGSENABLESYMBOLS:=-Z7
 .ENDIF
+CLI_BASETYPES_CONFIG=
+CLI_URETYPES_CONFIG=
+CLI_URE_CONFIG=
+.IF "$(ENABLE_MONO)" == "YES"
+CLI_BASETYPES_CONFIG=cli_basetypes.config,$(BIN)$/cli_basetypes.config
+CLI_URETYPES_CONFIG=cli_uretypes.config,$(BIN)$/cli_uretypes.config
+CLI_URE_CONFIG=cli_ure.config,$(BIN)$/cli_ure.config
+.ENDIF
+.IF "$(COM)" == "MSC"
+CLI_BASETYPES_CONFIG=$(BIN)$/cli_basetypes.config
+CLI_URETYPES_CONFIG=$(BIN)$/cli_uretypes.config
+CLI_URE_CONFIG=$(BIN)$/cli_ure.config
+.ENDIF
+
 .ENDIF			# "L10N_framework"==""
 
diff --git a/config_host.mk.in b/config_host.mk.in
index 38ae226..9f38be9 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -65,7 +65,7 @@ export CPUNAME=@CPUNAME@
 export CPUNAME_FOR_BUILD=@CPUNAME_FOR_BUILD@
 export CPU_FOR_BUILD=@CPU_FOR_BUILD@
 export CROSS_COMPILING=@CROSS_COMPILING@
-export CSC=@CSC@
+ at x_Mono@ export CSC=@CSC@
 export CSC_PATH=@CSC_PATH@
 export CT2N_EXTENSION_PACK=@CT2N_EXTENSION_PACK@
 export CURL_CFLAGS=@CURL_CFLAGS@
diff --git a/configure.in b/configure.in
index cb45b77..7f14413 100644
--- a/configure.in
+++ b/configure.in
@@ -4211,7 +4211,8 @@ if test "$build_os" = "cygwin" ; then
 
     PathFormat "$CSC_PATH"
     CSC_PATH="$formatted_path"
-
+	
+	x_Mono=[\#]
 fi
 
 if test "$_os" = "Linux"; then
@@ -4244,6 +4245,7 @@ if test "$_os" = "Linux"; then
                         "`echo $MCS_VERSION | cut -d"." -f3`" -ge "8"; then
                 ENABLE_MONO=YES
                 CSC=$MCS
+				x_Mono=
                 AC_PATH_PROG(GMCS, gmcs, no)
                 AC_PATH_PROG(MKBUNDLE2, mkbundle2, no)
                 AC_PATH_PROG(MKBUNDLE, mkbundle, no)
@@ -4283,6 +4285,7 @@ if test "$_os" = "Linux"; then
         MONO_GAC_ROOT=$with_mono_gac_root
     fi
 fi
+AC_SUBST(x_Mono)
 AC_SUBST(CSC_PATH)
 AC_SUBST(CSC)
 AC_SUBST(AL)
commit 263e82d49d374fd550dfbdeb30f2596569367a9a
Author: Petr Mladek <pmladek at suse.cz>
Date:   Tue Aug 2 18:37:13 2011 +0200

    [mono] mono-component-support.diff: add mono support

diff --git a/cli_ure/prj/build.lst b/cli_ure/prj/build.lst
index 580c1eb..f956044 100644
--- a/cli_ure/prj/build.lst
+++ b/cli_ure/prj/build.lst
@@ -10,5 +10,6 @@ ure cli_ure\unotypes			nmake	-	all		ure_unotypes ure_source_version ure_source_s
 ure	cli_ure\source\ure                      nmake   -       all     ure_source_ure ure_source_bootstrap.u ure_source_version ure_source_source ure_source_basetypes ure_unotypes ure_inc NULL
 ure cli_ure\source\uno_bridge	nmake	-	w,vc7	ure_source_uno_bridge ure_source_basetypes ure_unotypes ure_source_ure ure_inc NULL
 ure	cli_ure\source\mono_bridge	nmake	-	u		ure_source_mono_bridge ure_unotypes ure_source_ure ure_inc NULL
+ure	cli_ure\source\mono_loader      nmake   -       u       ure_source_mono_loader ure_unotypes ure_source_ure ure_inc NULL
 ure cli_ure\source\native		nmake	-	w,vc7	ure_source_native ure_source_version ure_source_source ure_source_ure ure_unotypes ure_source_uno_bridge ure_inc NULL
 #ure cli_ure\util				nmake	-	w,vc7	ure_util ure_source_ure ure_source_native NULL
diff --git a/cli_ure/prj/d.lst b/cli_ure/prj/d.lst
index 284de4c..54b93ae 100644
--- a/cli_ure/prj/d.lst
+++ b/cli_ure/prj/d.lst
@@ -9,6 +9,7 @@
 ..\%__SRC%\bin\cli_*.config %_DEST%\bin\cli_*.config
 ..\%__SRC%\bin\policy*.dll %_DEST%\bin\policy*.dll
 ..\%__SRC%\bin\cli_uno.* %_DEST%\bin\cli_uno.*
+..\%__SRC%\lib\mono_loader*.so %_DEST%\lib\mono_loader*.so
 
 ..\%__SRC%\bin\cliuno.snk %_DEST%\bin\cliuno.snk
 
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/makefile.mk b/cli_ure/source/mono_loader/makefile.mk
new file mode 100644
index 0000000..ece4aed
--- /dev/null
+++ b/cli_ure/source/mono_loader/makefile.mk
@@ -0,0 +1,51 @@
+PRJ=..$/..
+
+PRJNAME=cli_ure
+TARGET=mono_loader
+
+VISIBILITY_HIDDEN=TRUE
+NO_BSYMBOLIC=	TRUE
+ENABLE_EXCEPTIONS=TRUE
+COMP1TYPELIST=$(TARGET)
+COMPRDB=$(SOLARBINDIR)$/types.rdb
+
+.IF "$(ENABLE_MONO)" != "YES"
+dummy:
+     @echo "Mono binding disabled - skipping ..."
+.ELSE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE :  settings.mk
+CFLAGS+=$(MONO_CFLAGS)
+DLLPRE =
+
+# ------------------------------------------------------------------
+
+#.INCLUDE :  ..$/cppumaker.mk
+
+SLOFILES= \
+		$(SLO)$/service.obj \
+		$(SLO)$/mono_loader.obj
+
+SHL1TARGET= $(TARGET)$(DLLPOSTFIX).uno
+SHL1IMPLIB=     i$(TARGET)
+
+SHL1VERSIONMAP=$(SOLARENV)/src/component.map
+SHL1DEF=$(MISC)$/$(SHL1TARGET).def
+DEF1NAME=$(SHL1TARGET)
+                                                                              
+SHL1STDLIBS= \
+                $(CPPUHELPERLIB) \
+                $(CPPULIB) \
+                $(SALLIB)
+
+SHL1STDLIBS+=$(MONO_LIBS)
+                                                                              
+SHL1DEPN=
+SHL1LIBS=$(SLB)$/$(TARGET).lib
+
+.ENDIF
+# --- Targets ------------------------------------------------------
+
+.INCLUDE :	target.mk
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 63e09ec..b74d657 100644
--- 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(CONCAT4(mono_loader,DLLPOSTFIX,.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 f33aa7084834abdee8a02d9034b1ef68fd2bdfcc
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:
    
    	unoil/climaker/makefile.mk
    
    Change-Id: I4c0ec75954df7a34ed6f4173f84190ab10e62c4b

diff --git a/cli_ure/prj/d.lst b/cli_ure/prj/d.lst
index b42bbc6..284de4c 100644
--- a/cli_ure/prj/d.lst
+++ b/cli_ure/prj/d.lst
@@ -1,4 +1,5 @@
 ..\%__SRC%\bin\climaker.exe %_DEST%\bin\climaker.exe
+..\%__SRC%\bin\climaker %_DEST%\bin\climaker
 ..\%__SRC%\bin\climaker.pdb %_DEST%\bin\climaker.pdb
 ..\%__SRC%\bin\climaker.exe.config %_DEST%\bin\climaker.exe.config
 
diff --git a/cli_ure/source/bootstrap/makefile.mk b/cli_ure/source/bootstrap/makefile.mk
index 54d3366..95bdb3d 100644
--- a/cli_ure/source/bootstrap/makefile.mk
+++ b/cli_ure/source/bootstrap/makefile.mk
@@ -73,8 +73,12 @@ $(ASSEMBLY_ATTRIBUTES) .PHONY: assembly.cs $(BIN)$/cliuno.snk $(BIN)$/cliurevers
 
 EXTERNAL_DIR=$(PRJ)$/..$/external/cli
 
-$(OUT)$/bin$/cli_uretypes.dll : $(EXTERNAL_DIR)$/cli_uretypes.dll
-    +$(COPY) $< $@
+.IF "$(ENABLE_MONO_CLIMAKER)" != "YES"
+
+$(OUT)$/bin$/cli_uretypes.dll : $(EXTERNAL_DIR)$/cli_uretypes.dll $(EXTERNAL_DIR)$/cli_uretypes.config $(EXTERNAL_DIR)$/policy.1.0.cli_uretypes.dll
+    +$(COPY) $? $(OUT)$/bin$/
+
+.ENDIF
 
 $(BIN)$/cli_cppuhelper.dll : $(CSFILES) $(OUT)$/bin$/cli_uretypes.dll
     +$(CSC) $(CSCFLAGS) \
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);

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list