private static void GetMemberValue(IntPtr intPtr, IntPtr memberPtr, MemberType type, ref UnmanagedValue value) { object objectInstance; object valueInstance; switch (type) { case MemberType.field: GetObjectAndInfo(intPtr, memberPtr, out objectInstance, out FieldInfo fieldInfo); valueInstance = fieldInfo.GetValue(objectInstance); value.FromManaged(valueInstance); break; case MemberType.property: GetObjectAndInfo(intPtr, memberPtr, out objectInstance, out PropertyInfo propertyInfo); valueInstance = propertyInfo.GetValue(objectInstance); value.FromManaged(valueInstance); return; case MemberType.method: throw new MissingMethodException(); case MemberType.constructor: throw new MissingMemberException(); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
private static void CallMethod(IntPtr instancePtr, IntPtr methodPtr, UnmanagedValue[] parameters, int paramCount, ref UnmanagedValue output) { GetObjectAndInfo(instancePtr, methodPtr, out object objectInstance, out MethodInfo info); object[] objects = new object[paramCount]; for (int index = 0; index < paramCount; index++) { objects[index] = parameters[index].ToManaged(); } object ret = info.Invoke(objectInstance, objects); if (ret != null) { output.FromManaged(ret); } }
private static bool CallMethodOut(IntPtr instancePtr, IntPtr methodPtr, UnmanagedValue[] parameters, int paramCount, ref UnmanagedValue output) { GetObjectAndInfo(instancePtr, methodPtr, out object objectInstance, out MethodInfo info); object[] objects = new object[paramCount]; for (int index = 0; index < paramCount - 1; index++) { objects[index] = parameters[index].ToManaged(); } bool ret = (bool)info.Invoke(objectInstance, objects); if (!ret) { return(false); } object outParam = objects[paramCount - 1]; output.FromManaged(outParam); return(true); }