summaryrefslogtreecommitdiffstats
path: root/mono
diff options
context:
space:
mode:
authorOwen Fraser-Green <owen@discobabe.net>2004-03-24 14:42:41 +0000
committerOwen Fraser-Green <owen@discobabe.net>2004-03-24 14:42:41 +0000
commita745a709d00e2fd6145ca91f839fb1da947150a1 (patch)
treea7163ab164557f36be6464521ae02fff84fc2f43 /mono
parentf33453896716e69cacd0d065b7cc633258678946 (diff)
Fixed bug preventing creating multiple proxy objects of the same type.
Diffstat (limited to 'mono')
-rw-r--r--mono/ProxyBuilder.cs70
1 files changed, 37 insertions, 33 deletions
diff --git a/mono/ProxyBuilder.cs b/mono/ProxyBuilder.cs
index 5bbf3e41..4ef2fe91 100644
--- a/mono/ProxyBuilder.cs
+++ b/mono/ProxyBuilder.cs
@@ -14,7 +14,7 @@ namespace DBus
private string pathName = null;
private Type type = null;
private Introspector introspector = null;
- private AssemblyBuilder proxyAssembly;
+ private static AssemblyBuilder proxyAssembly;
private static MethodInfo Service_NameMI = typeof(Service).GetMethod("get_Name",
new Type[0]);
@@ -213,40 +213,44 @@ namespace DBus
public object GetProxy()
{
- // Build the type
- TypeBuilder typeB = ServiceModuleBuilder.DefineType(ProxyName, TypeAttributes.Public, this.type);
+ Type proxyType = ProxyAssembly.GetType(ProxyName);
- FieldBuilder serviceF = typeB.DefineField("service",
- typeof(Service),
- FieldAttributes.Private |
- FieldAttributes.Static);
- FieldBuilder pathF = typeB.DefineField("pathName",
- typeof(string),
- FieldAttributes.Private);
-
- BuildConstructor(ref typeB, serviceF, pathF);
-
- // Build the methods
- foreach (DictionaryEntry interfaceEntry in this.introspector.InterfaceProxies) {
- InterfaceProxy interfaceProxy = (InterfaceProxy) interfaceEntry.Value;
- foreach (DictionaryEntry methodEntry in interfaceProxy.Methods) {
- MethodInfo method = (MethodInfo) methodEntry.Value;
- BuildMethod(method, interfaceProxy, ref typeB, serviceF, pathF);
+ if (proxyType == null) {
+ // Build the type
+ TypeBuilder typeB = ServiceModuleBuilder.DefineType(ProxyName, TypeAttributes.Public, this.type);
+
+ FieldBuilder serviceF = typeB.DefineField("service",
+ typeof(Service),
+ FieldAttributes.Private |
+ FieldAttributes.Static);
+ FieldBuilder pathF = typeB.DefineField("pathName",
+ typeof(string),
+ FieldAttributes.Private);
+
+ BuildConstructor(ref typeB, serviceF, pathF);
+
+ // Build the methods
+ foreach (DictionaryEntry interfaceEntry in this.introspector.InterfaceProxies) {
+ InterfaceProxy interfaceProxy = (InterfaceProxy) interfaceEntry.Value;
+ foreach (DictionaryEntry methodEntry in interfaceProxy.Methods) {
+ MethodInfo method = (MethodInfo) methodEntry.Value;
+ BuildMethod(method, interfaceProxy, ref typeB, serviceF, pathF);
+ }
}
- }
+
+ proxyType = typeB.CreateType();
+ // Uncomment the following line to produce a DLL of the
+ // constructed assembly which can then be examined using
+ // monodis. Note that in order for this to work you should copy
+ // the client assembly as a dll file so that monodis can pick it
+ // up.
+ //ProxyAssembly.Save("proxy.dll");
+ }
+
Type [] parTypes = new Type[] {typeof(Service), typeof(string)};
object [] pars = new object[] {Service, pathName};
- Type proxyType = typeB.CreateType();
-
- // Uncomment the following line to produce a DLL of the
- // constructed assembly which can then be examined using
- // monodis. Note that in order for this to work you should copy
- // the client assembly as a dll file so that monodis can pick it
- // up.
- ProxyAssembly.Save("proxy.dll");
-
ConstructorInfo constructor = proxyType.GetConstructor(parTypes);
object instance = constructor.Invoke(pars);
return instance;
@@ -280,14 +284,14 @@ namespace DBus
private AssemblyBuilder ProxyAssembly
{
get {
- if (this.proxyAssembly == null){
+ if (proxyAssembly == null){
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "DBusProxy";
- this.proxyAssembly = Thread.GetDomain().DefineDynamicAssembly(assemblyName,
- AssemblyBuilderAccess.RunAndSave);
+ proxyAssembly = Thread.GetDomain().DefineDynamicAssembly(assemblyName,
+ AssemblyBuilderAccess.RunAndSave);
}
- return this.proxyAssembly;
+ return proxyAssembly;
}
}
}