Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 97c243e

Browse files
committed
squash! proxy: Property get/set via CLR properties
Add caching for generated MethodCaller delegates.
1 parent f7f0e01 commit 97c243e

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

src/ExportObject.cs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ internal static MethodCaller GetMCaller (MethodInfo mi)
7474
return mCaller;
7575
}
7676

77+
internal static MethodCaller GetPropertyCaller(PropertyInfo pi)
78+
{
79+
MethodInfo mi = pi.GetMethod;
80+
MethodCaller mCaller;
81+
if (!mCallers.TryGetValue(mi, out mCaller))
82+
{
83+
mCaller = TypeImplementer.GenGetCall (pi);
84+
mCallers[mi] = mCaller;
85+
}
86+
return mCaller;
87+
}
88+
89+
internal static MethodCaller SetPropertyCaller(PropertyInfo pi)
90+
{
91+
MethodInfo mi = pi.SetMethod;
92+
MethodCaller mCaller;
93+
if (!mCallers.TryGetValue(mi, out mCaller))
94+
{
95+
mCaller = TypeImplementer.GenSetCall (pi);
96+
mCallers[mi] = mCaller;
97+
}
98+
return mCaller;
99+
}
100+
77101
public static ExportObject CreateExportObject (Connection conn, ObjectPath object_path, object obj)
78102
{
79103
return new ExportObject (conn, object_path, obj);
@@ -171,29 +195,32 @@ private void HandlePropertyCall(MessageContainer method_call)
171195

172196
string name = (string)args[1];
173197

174-
PropertyInfo pi = Object.GetType().GetProperty(name);
175-
MethodInfo mi;
176-
MethodCaller pc;
198+
PropertyInfo pi = Object.GetType ().GetProperty (name);
199+
200+
if (null == pi)
201+
{
202+
conn.MaybeSendUnknownMethodError (method_call);
203+
return;
204+
}
205+
206+
MethodCaller pc = null;
207+
MethodInfo mi = null;
177208
Signature outSig, inSig = method_call.Signature;
178209

179210
switch (method_call.Member) {
180211
case "Set":
181-
mi = pi.GetSetMethod ();
182-
pc = TypeImplementer.GenSetCall(pi);
212+
mi = pi.SetMethod;
213+
pc = SetPropertyCaller (pi);
183214
outSig = Signature.Empty;
184215
break;
185216
case "Get":
186-
mi = pi.GetGetMethod ();
187-
pc = TypeImplementer.GenGetCall(pi);
188-
outSig = Signature.GetSig(mi.ReturnType);
217+
mi = pi.GetMethod;
218+
pc = GetPropertyCaller (pi);
219+
outSig = Signature.GetSig (mi.ReturnType);
189220
break;
190221
default:
191-
throw new ArgumentException(string.Format ("No such method {0}.{1}", method_call.Interface, method_call.Member));
192-
}
193-
194-
if (null == pc) {
195-
conn.MaybeSendUnknownMethodError (method_call);
196-
return;
222+
conn.MaybeSendUnknownMethodError (method_call);
223+
return;
197224
}
198225

199226
Exception raisedException = null;

0 commit comments

Comments
 (0)