Add support for Events in Scripting API reflection in Editor

This commit is contained in:
Wojtek Figat
2021-01-21 14:40:53 +01:00
parent c2f745397a
commit 4042d466d3
2 changed files with 28 additions and 2 deletions

View File

@@ -50,6 +50,9 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public bool IsMethod => false;
/// <inheritdoc />
public bool IsEvent => false;
/// <inheritdoc />
public bool HasGet => true;
@@ -174,6 +177,9 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public bool IsMethod => true;
/// <inheritdoc />
public bool IsEvent => false;
/// <inheritdoc />
public bool HasGet => false;

View File

@@ -138,6 +138,11 @@ namespace FlaxEditor.Scripting
/// </summary>
public bool IsMethod => _managed is MethodInfo || (_custom?.IsMethod ?? false);
/// <summary>
/// Gets a value indicating whether this member is an event.
/// </summary>
public bool IsEvent => _managed is EventInfo || (_custom?.IsEvent ?? false);
/// <summary>
/// Gets a value indicating whether this member value can be gathered (via getter method or directly from the field).
/// </summary>
@@ -383,7 +388,7 @@ namespace FlaxEditor.Scripting
}
/// <summary>
/// Gets the method parameters metadata.
/// Gets the method parameters metadata (or event delegate signature parameters).
/// </summary>
public Parameter[] GetParameters()
{
@@ -416,6 +421,11 @@ namespace FlaxEditor.Scripting
}
return result;
}
if (_managed is EventInfo eventInfo)
{
var invokeMethod = eventInfo.EventHandlerType.GetMethod("Invoke");
return new ScriptMemberInfo(invokeMethod).GetParameters();
}
return _custom.GetParameters();
}
@@ -634,6 +644,11 @@ namespace FlaxEditor.Scripting
/// </summary>
public static readonly ScriptType Null;
/// <summary>
/// A <see cref="ScriptType" /> that is System.Void.
/// </summary>
public static readonly ScriptType Void = new ScriptType(typeof(void));
/// <summary>
/// Gets the type of the script as <see cref="System.Type"/>.
/// </summary>
@@ -1463,6 +1478,11 @@ namespace FlaxEditor.Scripting
/// </summary>
bool IsMethod { get; }
/// <summary>
/// Gets a value indicating whether this member is an event.
/// </summary>
bool IsEvent { get; }
/// <summary>
/// Gets a value indicating whether this member value can be gathered (via getter method or directly from the field).
/// </summary>
@@ -1504,7 +1524,7 @@ namespace FlaxEditor.Scripting
object[] GetAttributes(bool inherit);
/// <summary>
/// Gets the method parameters metadata.
/// Gets the method parameters metadata (or event delegate signature parameters).
/// </summary>
ScriptMemberInfo.Parameter[] GetParameters();