Skip to content

Commit

Permalink
Fixed ExecuteCOmmand proxy mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwp committed Apr 7, 2020
1 parent bf5abd9 commit 8bb0ea0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions UIExtenderLibModule/ViewModel/ViewModelComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ private Type GenerateExtendedVMTypeFor(Type t)
}
}

foreach (var method in t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Where(m => m.Name.StartsWith("Execute")))
{
var newMethod = builder.DefineMethod(method.Name, MethodAttributes.Public, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray());
var gen = newMethod.GetILGenerator();

// body
var proxyExecuteCall = typeof(ViewModelPatchUtil).GetMethod(nameof(ViewModelPatchUtil.ProxyExecuteCall));
gen.Emit(OpCodes.Ldstr, method.Name);
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Call, proxyExecuteCall);
gen.Emit(OpCodes.Ret);
}

foreach (var mixin in _mixins[t])
{
// properties
Expand Down
6 changes: 6 additions & 0 deletions UIExtenderLibModule/ViewModel/ViewModelPatchUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ public static void InitializeMixinsForModel(Type t, object instance)
{
UIExtenderLibModule.SharedInstance.ViewModelComponent.InitializeMixinsForViewModelInstance(t, instance);
}

public static void ProxyExecuteCall(string name, object instance)
{
var method = instance.GetType().BaseType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
method.Invoke(instance, null);
}
}
}

0 comments on commit 8bb0ea0

Please sign in to comment.