Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomPortBehavior from base class not respected. #216

Open
rhys-vdw opened this issue May 17, 2022 · 0 comments · May be fixed by #218
Open

CustomPortBehavior from base class not respected. #216

rhys-vdw opened this issue May 17, 2022 · 0 comments · May be fixed by #218

Comments

@rhys-vdw
Copy link

rhys-vdw commented May 17, 2022

e.g.

using System.Collections.Generic;
using System.Reflection;
using GraphProcessor;

public abstract class EventNode<T> : BaseNode {
  [Output("Event values", allowMultiple = true)]
  public IEnumerable<object> outputs = null;

  static PortData[] _outputPortDatas;

  public override void InitializePorts() {
    if (_outputPortDatas == null) {
      var fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance);
      _outputPortDatas = new PortData[fields.Length];
      for (var i = 0; i < fields.Length; i++) {
        var field = fields[i];
        _outputPortDatas[i] = new PortData {
          displayName = field.Name,
          displayType = field.FieldType,
          identifier = field.Name
        };
      }
    }
    base.InitializePorts();
  }

  [CustomPortBehavior(nameof(outputs))]
  protected IEnumerable<PortData> GetOutputPorts(List<SerializableEdge> _) {
    foreach (var p in _outputPortDatas) {
      yield return p;
    }
  }

  // ...
}
using GraphProcessor;

[System.Serializable, NodeMenuItem("EffortStar/Events/Reload")]
class ReloadEventNode : EventNode<Reload> {
}

This just shows a single output called "Event values".

Problem is here:

var methods = GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

Requires a BindingFlags.FlattenHierarchy to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant