You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No way of Invoking a generic method with multiple overload and out/byref parameters #641
Invoke a generic method with multiple overload and out parameters
What commands did you run to trigger this issue?
//C# SIDE//...publicvoidGetProperty<T>(stringpropertyName,outTvalue){...}//<= The one i'm trying to getpublicvoidGetProperty<T>(stringpropertyName,outTvalue,boolasRef){...}publicvoidGetProperty<T>(stringpropertyName,outTvalue,intindex){...}publicvoidGetProperty<T>(stringpropertyName,outTvalue,intindex,boolasRef){...}publicvoidGetProperty<T>(PropertyIDpropertyID,outTvalue,intindex){...}publicvoidGetProperty<T>(PropertyIDpropertyID,outTvalue,boolasRef){...}//...
@llezo you may want to have a look at this issue. I don't see any way to handle byref overloads reliably without re-writing the method resolution logic:
That's what i thought.
I will try some hack on my side, because that sort of problem is everywhere on the DLLs i work with
Here is what i think i'll try:
#Access by its position in the list of overloadsobject.GetProperty.Overloads.ByIndex[0] #GetProperty<T>(string propertyName, out T value)#By passing a string that is equal to GetParameters().ParameterType.Nameobject.GetProperty.Overloads.BySignature["System.String","T&", "System.Boolean&"] #GetProperty<T>(string propertyName, out T value, bool asRef)#Eventually make this work:SingleByRef=System.Type.GetType(System.Single).MakeByRefType()
object.GetProperty[System.Single]('PropertyName', SingleByRef)
@llezo i put something together here long ago, but be careful because in some edge cases this would pick the wrong overloaded method, e.g. when both byref and non-byref versions are present:
There is a more general issue here, that you can't choose a specific overload of a generic method. It always matches the first in MethodBinder.MatchParameters
public void GetProperty(string propertyName, T value){...} //<= The one i'm trying to get
public void GetProperty(double propertyName, T value){...}
Is there any progress on resolving this issue? I have encountered a similar problem when trying out pythonnet with Infer.Net. So in my case I have on the C# side generic overloads that have signatures:
I'm trying to call the second overload in pythonnet as:
a = Variable.Constant(System.Array[System.Double]([1.0, 2.0, 3.0]))
But when I check the type of a, it gives Variable[System.Double[]] and not VariableArray[System.Double]. This makes sense since it's ambiguous without specifying the type of the output variable or specifying the type for the function. Since in python I can't pin the output variable to a specific type, I tried to resolve the ambiguity with:
a = Variable.Constant[System.Double](System.Array[System.Double]([1.0, 2.0, 3.0])
but then I get the exception:
TypeError: No method matches given arguments for Constant
It seems that there is pull-request (#227) ongoing, but it looks to have been work in progress for quite a while now. Is there someone working on resolving this issue? If not, is there a work-around that I could try?
Activity
den-run-ai commentedon Mar 5, 2018
@llezo you may want to have a look at this issue. I don't see any way to handle byref overloads reliably without re-writing the method resolution logic:
#265
RockHornetz commentedon Mar 5, 2018
That's what i thought.
I will try some hack on my side, because that sort of problem is everywhere on the DLLs i work with
Here is what i think i'll try:
What do you think?
den-run-ai commentedon Mar 5, 2018
@llezo i put something together here long ago, but be careful because in some edge cases this would pick the wrong overloaded method, e.g. when both byref and non-byref versions are present:
https://github.com/pythonnet/pythonnet/pull/227/files
RockHornetz commentedon Mar 5, 2018
Hmm it should do the trick but i'll keep an eye on what i'm calling.
Thanks !
williamsardar commentedon Apr 23, 2018
There is a more general issue here, that you can't choose a specific overload of a generic method. It always matches the first in MethodBinder.MatchParameters
public void GetProperty(string propertyName, T value){...} //<= The one i'm trying to get
public void GetProperty(double propertyName, T value){...}
Tobimaru commentedon Feb 24, 2019
Hi,
Is there any progress on resolving this issue? I have encountered a similar problem when trying out pythonnet with Infer.Net. So in my case I have on the C# side generic overloads that have signatures:
I'm trying to call the second overload in pythonnet as:
But when I check the type of
a, it givesVariable[System.Double[]]and notVariableArray[System.Double]. This makes sense since it's ambiguous without specifying the type of the output variable or specifying the type for the function. Since in python I can't pin the output variable to a specific type, I tried to resolve the ambiguity with:but then I get the exception:
It seems that there is pull-request (#227) ongoing, but it looks to have been work in progress for quite a while now. Is there someone working on resolving this issue? If not, is there a work-around that I could try?