from System import String, Char, Int32
def TestCharArray():
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
##for char in arrType:
## print char,
## Also works on instances of the type! ##
strCharArr = String.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
TestCharArray()
On 5/17/2011 12:38 AM, Barton wrote:
def TestCharArray():
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
##for char in arrType:
## print char,
## Also works on instances of the type! ##
strCharArr = s.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
On 5/16/2011 6:29 PM, Adrian Perez wrote:
Hello everyone,
This is probably a total n00b question, but I've been using pythonnet
in our toolchain to communicate with a private c# assembly for months
now without ever running into a problem I couldn't eventually figure
out. This one has me totally stumped, and I'm hoping something
obvious will jump out at experienced eyes.
(I did a find/replace for secrecy, besides silly names these are the
raw results I get back)
A C# class exposes a method 'WriteByte' that has 5 overloads (note
that only one of them takes 2 arguments):
accessor= MyCompany.SomeNamespace.SomeTypeArrayAccessor
accessor.WriteByte.__overloads__
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[])
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, Byte[],
Int32 ByRef)
I attempt to disambiguate by selecting the 2-arg method I want by type:
desired_method=
accessor.WriteByte.__overloads__[MyCompany.SomeNamespace.SomeType,
System.Array[System.Byte]]
The problem may be right here - if I print out desired_method.__doc__
I get the same 5 methods listed above. Anyway, then I compute my
arguments, and can verify they have the types I expect (If it
matters, arg_b is created by a call to
System.IO.BinaryReader.ReadBytes()):
arg_a= ...
arg_b= ...
type(arg_a)
<class 'MyCompany.SomeNamespace.SomeType'>
type(arg_b)
<class 'System.Byte[]'>
However, when I try to call the disambiguated method with the correct
args, I get no love:
result= desired_method(arg_a, arg_b)
Traceback (most recent call last):
File "<string>", line 1, in<fragment>
TypeError: No method matches given arguments
Does anyone see the obvious thing I'm doing wrong? Disambiguating
can be a pain but I've done it before for other methods and have
never had such an impossible time getting the correct method called.
Thanks,
Adrian Perez
_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet