c# - How can I get delegates to property accessors from a generic type? -


I am currently creating a node editor () and I have a problem getting the properties of property accessories in general Has been there. So far this question has brought me the closest, but I'm having trouble that I think that is related to the type of object in particular.

For reference, "node" is synonymous to an object, and a "port" is synonymous with a property.

This is a derogatory code, which is part of the node class. The nodeport code class is a feature that can be set to properties to provide details for the property (such as human-readable names and data flow directions).

  Public Zero SetTarget & lt; T & gt; (T goal) {// TODO: End the old IOs end (if any) Inputs.Clear (); Outputs.Clear (); // Keep track of the current goal of this node. ThisTarget = Target; PropertyInfo [] Pinfa = Target Gettype () GetProperties (); Foreach (PropertyInfo property in Pinfo) {attribute [] attrs = attribute.GetCustomAttributes (property); Foreach (attribute attribute in attribute) {// if there is a nodeport attribute in the property, then it is specifically requesting to be available as a port on the node. If (attribute is nodeport) {nodeport port details = (nodeport) attribute; If (PortDetails.Direction == NodePort.NodePortDirection.PORT_INPUT) {// This row throws an ArgumentException, and only the message "is a forced error to target the method." NodeInput & lt; T & gt; .SetValue Setter = (NodeInput & lt; T & gt; .SetValue) Rep. Cuts (typef (node ​​input & amp; tt; tt> gt; gt; gt; gt; STV), (t) target, property. GetSetMethod ()); AddInput (Setter, PortDetails.CommonName); } And if (PortDetails.Direction == NodePort.NodePortDirection.PORT_OUTPUT) {// The only exception here is Node optical & lt; T & gt; Gate Value Getter = (nodoptput & lt; T & gt; GETValue) representative. Cutlate (typef (node-optup & lt; T & gt; GETValue), (t) target, property. GetGetMethod ()); AddOutput (Greater, PortDetails.CommonName); }}}}  

node-optup and node inputs & lt; T & gt; .SetValue is defined as:

  Public Representative T Gatevelu (); Public representative Zero Setvela (T-value);   

... in node-optup and NodeInput respectively.

Do anyone have an experience to make representatives available to the property? Any idea how this can be different when the question is normal?

I think you have a type of mismatch here in the first of your exception lines, Setter to NodeInput & lt; T & gt; , which means that it is a method that takes T. and gives zero. But the method you specify to setter is the property. GetSetMethod (), which will be a method that takes the property. Property type and zero returns This will be the reason for an exception unless there is good fortune of the property. Property type is similar to T. Similarly exceptions getter on the other side of the rows.

I suspect that you can not handle it using generic, because you do not know the property. Type the property on timeliness, so you can not give that type as a normal parameter (as long as you do not use type.MakeGenericType, normal parameters should be specified.) / P>


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -