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

Commit

Permalink
squash! proxy: Property get/set via CLR properties
Browse files Browse the repository at this point in the history
Add caching for generated MethodCaller delegates.
  • Loading branch information
arfbtwn committed Oct 11, 2017
1 parent f7f0e01 commit 97c243e
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions src/ExportObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ internal static MethodCaller GetMCaller (MethodInfo mi)
return mCaller;
}

internal static MethodCaller GetPropertyCaller(PropertyInfo pi)
{
MethodInfo mi = pi.GetMethod;
MethodCaller mCaller;
if (!mCallers.TryGetValue(mi, out mCaller))
{
mCaller = TypeImplementer.GenGetCall (pi);
mCallers[mi] = mCaller;
}
return mCaller;
}

internal static MethodCaller SetPropertyCaller(PropertyInfo pi)
{
MethodInfo mi = pi.SetMethod;
MethodCaller mCaller;
if (!mCallers.TryGetValue(mi, out mCaller))
{
mCaller = TypeImplementer.GenSetCall (pi);
mCallers[mi] = mCaller;
}
return mCaller;
}

public static ExportObject CreateExportObject (Connection conn, ObjectPath object_path, object obj)
{
return new ExportObject (conn, object_path, obj);
Expand Down Expand Up @@ -171,29 +195,32 @@ private void HandlePropertyCall(MessageContainer method_call)

string name = (string)args[1];

PropertyInfo pi = Object.GetType().GetProperty(name);
MethodInfo mi;
MethodCaller pc;
PropertyInfo pi = Object.GetType ().GetProperty (name);

if (null == pi)
{
conn.MaybeSendUnknownMethodError (method_call);
return;
}

MethodCaller pc = null;
MethodInfo mi = null;
Signature outSig, inSig = method_call.Signature;

switch (method_call.Member) {
case "Set":
mi = pi.GetSetMethod ();
pc = TypeImplementer.GenSetCall(pi);
mi = pi.SetMethod;
pc = SetPropertyCaller (pi);
outSig = Signature.Empty;
break;
case "Get":
mi = pi.GetGetMethod ();
pc = TypeImplementer.GenGetCall(pi);
outSig = Signature.GetSig(mi.ReturnType);
mi = pi.GetMethod;
pc = GetPropertyCaller (pi);
outSig = Signature.GetSig (mi.ReturnType);
break;
default:
throw new ArgumentException(string.Format ("No such method {0}.{1}", method_call.Interface, method_call.Member));
}

if (null == pc) {
conn.MaybeSendUnknownMethodError (method_call);
return;
conn.MaybeSendUnknownMethodError (method_call);
return;
}

Exception raisedException = null;
Expand Down

0 comments on commit 97c243e

Please sign in to comment.