/// <summary> /// Creates a scripting method definition from the reflection info /// </summary> private static SciterNativeMethodDef DefineScriptingMethod(MethodInfo methodInfo, ScriptingMethodAttribute methodAttr) { return(new SciterNativeMethodDef() { name = methodAttr.Name ?? methodInfo.Name, // Method callback implementation method = (IntPtr hvm, ref JsonValue p_data_slot, IntPtr argv, int argc, ref JsonValue retval) => { try { var instance = default(object); if (!methodInfo.IsStatic) { instance = InstanceProtector.GetInstance(p_data_slot.GetNativeObject()); } var result = methodInfo.Invoke(instance, JsonPtrToArray(argv, argc)); retval = result == null ? new JsonValue() : new JsonValue(result); } catch (Exception ex) { SciterHostApi.SciterNativeThrow(hvm, ex.Message); } } }); }
/// <summary> /// Creates a scripting property definitions /// </summary> private static SciterNativePropertyDef DefineScriptingProperty(PropertyInfo propertyInfo, ScriptingPropertyAttribute propertyAttr) { return(new SciterNativePropertyDef() { name = propertyAttr.Name ?? propertyInfo.Name, // Property callback implementation property = (IntPtr hvm, ref JsonValue p_data_slot, bool set, ref JsonValue retval) => { try { var instance = default(object); if (!propertyInfo.GetGetMethod().IsStatic) { instance = InstanceProtector.GetInstance(p_data_slot.GetNativeObject()); } retval = new JsonValue(); if (set) { propertyInfo.SetValue(instance, retval.GetValue(), null); } else { retval = new JsonValue(propertyInfo.GetValue(instance, null)); } } catch (Exception ex) { SciterHostApi.SciterNativeThrow(hvm, ex.Message); } } }); }
/// <summary> /// Creates a scripting ctor definition from the reflection info /// </summary> private static SciterNativeMethodDef DefineCtorMethod(Type type) { return(new SciterNativeMethodDef() { name = "this", // Construction callback implementation method = (IntPtr hvm, ref JsonValue p_data_slot, IntPtr argv, int argc, ref JsonValue retval) => { try { var result = Activator.CreateInstance(type, JsonPtrToArray(argv, argc)); var data_slot_value = InstanceProtector.Protect(result); p_data_slot.SetNativeObject(data_slot_value); _registrations[hvm].Instances.Add(data_slot_value, result); } catch (Exception ex) { SciterHostApi.SciterNativeThrow(hvm, ex.Message); } } }); }