현재 노드 편집기 (as in Blender)를 만들고 있는데 대리인을 제네릭 형식에서 속성 접근 자로 가져 오는 데 문제가 있습니다. 지금까지 질문이 here에 가깝다는 것을 알게되었지만, 나는 일반적으로 객체 유형과 관련이 있다고 생각합니다.제네릭 형식의 속성 접근 자의 대리인을 얻으려면 어떻게해야합니까?
"노드"는 객체와 동의어이며 "포트"는 속성과 동의어입니다.
이것은 위반 코드이며 Node
클래스의 일부입니다. NodePort
클래스는 속성에 대해 설정되어 속성에 대한 세부 정보 (예 : 사람이 읽을 수있는 이름 및 데이터 흐름 방향)를 제공 할 수있는 속성입니다.
public void SetTarget<T>(T Target)
{
//TODO: Finish clearing old IOs (if any)
Inputs.Clear();
Outputs.Clear();
//Keep track of the current target of this node.
ThisTarget = Target;
PropertyInfo[] pinfo = Target.GetType().GetProperties();
foreach (PropertyInfo property in pinfo)
{
Attribute[] attrs = Attribute.GetCustomAttributes(property);
foreach (Attribute attribute in attrs)
{
// If the property has a NodePort attribute, it's specifically requesting to be available as a port on the node.
if (attribute is NodePort)
{
NodePort PortDetails = (NodePort)attribute;
if (PortDetails.Direction == NodePort.NodePortDirection.PORT_INPUT)
{
// This line throws an ArgumentException, and the only message is "Error binding to target method."
NodeInput<T>.SetValue Setter = (NodeInput<T>.SetValue)Delegate.CreateDelegate(typeof(NodeInput<T>.SetValue), (T)Target, property.GetSetMethod());
AddInput(Setter, PortDetails.CommonName);
}
else if (PortDetails.Direction == NodePort.NodePortDirection.PORT_OUTPUT)
{
// Same exception here.
NodeOutput<T>.GetValue Getter = (NodeOutput<T>.GetValue)Delegate.CreateDelegate(typeof(NodeOutput<T>.GetValue), (T)Target, property.GetGetMethod());
AddOutput(Getter, PortDetails.CommonName);
}
}
}
}
}
NodeOutput<T>.GetValue
및 NodeInput<T>.SetValue
는 같은 정의된다
public delegate T GetValue();
public delegate void SetValue(T value);
... 각각
NodeOutput
및
NodeInput
있다.
누구나 속성 접근 자의 대리인을 만드는 경험이 있습니까? 문제의 유형이 제네릭 일 때 어떻게 다른지 알기 원하십니까?
모든 유형의 속성을 * NodePort *로 장식 할 수 있습니까? – Elisha
예. 'NodePort'는 어떤 속성에도 적용될 수 있습니다. –