本文整理汇总了Python中System.Array方法的典型用法代码示例。如果您正苦于以下问题:Python System.Array方法的具体用法?Python System.Array怎么用?Python System.Array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InitializePath
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def InitializePath(self):
searchPath = []
currentDir = Directory.GetCurrentDirectory()
searchPath.append(currentDir)
filePathDir = Path.GetDirectoryName(Path.Combine(currentDir, self.fileName))
searchPath.append(filePathDir)
entryDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
searchPath.append(entryDir)
siteDir = Path.Combine(entryDir, "Lib")
searchPath.append(siteDir)
devStdLibDir = Path.Combine(entryDir, '../../External.LCA_RESTRICTED/Languages/IronPython/27/Lib')
searchPath.append(devStdLibDir)
dllsDir = Path.Combine(entryDir, "DLLs")
if Directory.Exists(dllsDir):
searchPath.append(dllsDir)
self.engine.SetSearchPaths(Array[str](searchPath))
示例2: test_pass_in_clrarray
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_pass_in_clrarray(self):
import System
a1 = System.Array[int]([1,2])
arrbuff1 = buffer(a1, 0, 5)
self.assertEqual(1, arrbuff1[0])
self.assertEqual(2, arrbuff1[1])
a2 = System.Array[System.String](["a","b"])
arrbuff2 = buffer(a2, 0, 2)
self.assertEqual("a", arrbuff2[0])
self.assertEqual("b", arrbuff2[1])
self.assertEqual(len(arrbuff1), len(arrbuff2))
arrbuff1 = buffer(a1, 1, 1)
self.assertEqual(2, arrbuff1[0])
self.assertEqual(len(arrbuff1), 1)
arrbuff1 = buffer(a1, 0, -1)
self.assertEqual(1, arrbuff1[0])
self.assertEqual(2, arrbuff1[1])
self.assertEqual(len(arrbuff1), 2)
a3 = System.Array[System.Guid]([])
self.assertRaises(TypeError, buffer, a3)
示例3: test_one_array
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_one_array(self):
import System
from Merlin.Testing.BaseClass import IInterface600
f = IInterface600.m_c
def checkEqual(first, second):
self.assertEqual(first, second)
class C(IInterface600):
def m_c(self, arg):
if arg:
checkEqual(sum(arg), expected)
arg[0] = 10
x = C()
a = System.Array[int]([1,2])
expected = 3
f(x, a)
self.assertEqual(a[0], 10)
f(x, None)
示例4: test_system_type_cs0644
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_system_type_cs0644(self):
# http://msdn2.microsoft.com/en-us/library/hxds244y(VS.80).aspx
# bug 363984
import System
def inheritDelegate():
class C(System.Delegate): pass
def inheritArray():
class C(System.Array): pass
def inheritValueType():
class C(System.ValueType): pass
def inheritEnum():
class C(System.Enum): pass
self.assertRaises(TypeError, inheritDelegate)
self.assertRaises(TypeError, inheritArray)
self.assertRaises(TypeError, inheritValueType)
self.assertRaises(TypeError, inheritEnum)
示例5: test_type_from_reflection_emit
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_type_from_reflection_emit(self):
import clr
import System
if is_netcoreapp:
clr.AddReference("System.Reflection.Emit")
sr = System.Reflection
sre = System.Reflection.Emit
array = System.Array
cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab) # tracking: 291888
else:
ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab) # tracking: 291888
mb = ab.DefineDynamicModule("temp", "temp.dll")
tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
tb.CreateType()
clr.AddReference(ab)
import EmittedNS
EmittedNS.EmittedType()
示例6: test_int_minvalue
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_int_minvalue(self):
# Test for type of System.Int32.MinValue
self.assertEqual(type(-2147483648), int)
self.assertEqual(type(-(2147483648)), long)
self.assertEqual(type(-2147483648L), long)
self.assertEqual(type(-0x80000000), int)
self.assertEqual(type(int('-2147483648')), int)
self.assertEqual(type(int('-80000000', 16)), int)
self.assertEqual(type(int('-2147483649')), long)
self.assertEqual(type(int('-80000001', 16)), long)
if is_cli:
import clr
import System
# verify our str.split doesn't replace CLR's String.Split
chars = System.Array[str]([' '])
res = 'a b c'.Split(chars, System.StringSplitOptions.RemoveEmptyEntries)
self.assertEqual(res[0], 'a')
self.assertEqual(res[1], 'b')
self.assertEqual(res[2], 'c')
示例7: test_str2
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_str2(self):
# verify we can assign to sys.exc_*
sys.exc_traceback = None
sys.exc_value = None
sys.exc_type = None
self.assertEqual(str(Exception()), '')
@skipUnlessIronPython()
def test_array(self):
import System
try:
a = System.Array()
except Exception, e:
self.assertEqual(e.__class__, TypeError)
else:
示例8: test_interface_inheritance
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_interface_inheritance(self):
"""Verify we can inherit from a class that inherits from an interface"""
class MyComparer(System.Collections.IComparer):
def Compare(self, x, y): return 0
class MyDerivedComparer(MyComparer): pass
class MyFurtherDerivedComparer(MyDerivedComparer): pass
# Check that MyDerivedComparer and MyFurtherDerivedComparer can be used as an IComparer
array = System.Array[int](range(10))
System.Array.Sort(array, 0, 10, MyComparer())
System.Array.Sort(array, 0, 10, MyDerivedComparer())
System.Array.Sort(array, 0, 10, MyFurtherDerivedComparer())
示例9: test_type_from_reflection_emit
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_type_from_reflection_emit(self):
import clr
import System
if is_netcoreapp:
clr.AddReference("System.Reflection.Emit")
sr = System.Reflection
sre = System.Reflection.Emit
array = System.Array
cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab) # tracking: 291888
else:
ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab) # tracking: 291888
mb = ab.DefineDynamicModule("temp", "temp.dll")
tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
tb.CreateType()
clr.AddReference(ab)
import EmittedNS
EmittedNS.EmittedType()
示例10: test_int_minvalue
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_int_minvalue(self):
# Test for type of System.Int32.MinValue
self.assertEqual(type(-2147483648), int)
self.assertEqual(type(-(2147483648)), long)
self.assertEqual(type(-long(2147483648)), long)
self.assertEqual(type(-0x80000000), int)
self.assertEqual(type(int('-2147483648')), int)
self.assertEqual(type(int('-80000000', 16)), int)
self.assertEqual(type(int('-2147483649')), long)
self.assertEqual(type(int('-80000001', 16)), long)
if is_cli:
import clr
import System
# verify our str.split doesn't replace CLR's String.Split
chars = System.Array[str]([' '])
res = 'a b c'.Split(chars, System.StringSplitOptions.RemoveEmptyEntries)
self.assertEqual(res[0], 'a')
self.assertEqual(res[1], 'b')
self.assertEqual(res[2], 'c')
示例11: test_interface_inheritance
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_interface_inheritance(self):
"""Verify we can inherit from a class that inherits from an interface"""
class MyComparer(System.Collections.IComparer):
def Compare(self, x, y): return 0
class MyDerivedComparer(MyComparer): pass
class MyFurtherDerivedComparer(MyDerivedComparer): pass
# Check that MyDerivedComparer and MyFurtherDerivedComparer can be used as an IComparer
array = System.Array[int](list(range(10)))
System.Array.Sort(array, 0, 10, MyComparer())
System.Array.Sort(array, 0, 10, MyDerivedComparer())
System.Array.Sort(array, 0, 10, MyFurtherDerivedComparer())
示例12: ghtree_to_list
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def ghtree_to_list(atree):
"""Returns a list representation of a Grasshopper DataTree
Examples:
>>> atree=Tree[object]()
>>> [atree.Add(str("entry: " + str(i)), Path(Array[int]([i]))) for i in range(3)]
>>> alist = ghtree_to_list(atree)
"""
def extend_at(path, index, simple_input, rest_list):
target = path[index]
if len(rest_list) <= target:
rest_list.extend([None]*(target-len(rest_list)+1))
if index == path.Length - 1:
rest_list[target] = list(simple_input)
else:
if rest_list[target] is None:
rest_list[target] = []
extend_at(path, index+1, simple_input, rest_list[target])
all = []
for i in range(atree.BranchCount):
path = atree.Path(i)
extend_at(path, 0, atree.Branch(path), all)
return all
示例13: vector_from_array
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def vector_from_array(a):
"""Make a Matlab-compatible vector from a (Numpy) array.
Parameters
----------
a : ndarray
The input array.
Returns
-------
System.Array
The vector.
Examples
--------
>>>
"""
raise NotImplementedError
示例14: to_numpy
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def to_numpy(src):
"""
Convert .NET array to numpy array
Parameters
----------
src : System.Array
Returns
-------
np.ndarray
"""
src_hndl = GCHandle.Alloc(src, GCHandleType.Pinned)
try:
src_ptr = src_hndl.AddrOfPinnedObject().ToInt64()
bufType = ctypes.c_float * len(src)
cbuf = bufType.from_address(src_ptr)
d = np.frombuffer(cbuf, dtype=cbuf._type_)
finally:
if src_hndl.IsAllocated:
src_hndl.Free()
return d
示例15: test_len
# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_len(self):
testData = ('hello world', array.array('b', 'hello world'), buffer('hello world'), buffer('abchello world', 3))
if is_cli:
import System
testData += (System.Array[System.Char]('hello world'), )
for x in testData:
b = buffer(x, 6)
self.assertEqual(len(b), 5)
b = buffer(x, 6, 2)
self.assertEqual(len(b), 2)
self.assertEqual(len(buffer("abc", 5)), 0)
self.assertEqual(len(buffer("abc", 5, 50)), 0)