我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用System.Array()。
def list_to_tree(input, none_and_holes=True, source=[0]): """Transforms nestings of lists or tuples to a Grasshopper DataTree""" from Grasshopper import DataTree as Tree from Grasshopper.Kernel.Data import GH_Path as Path from System import Array def proc(input,tree,track): path = Path(Array[int](track)) if len(input) == 0 and none_and_holes: tree.EnsurePath(path); return for i,item in enumerate(input): if hasattr(item, '__iter__'): #if list or tuple track.append(i); proc(item,tree,track); track.pop() else: if none_and_holes: tree.Insert(item,path,i) elif item is not None: tree.Add(item,path) if input is not None: t=Tree[object]();proc(input,t,source[:]);return t #================================================================
def CRStringToList(strList): return strList.Split(Array[str](CRLISTDELIMITER), StringSplitOptions.RemoveEmptyEntries)
def IsList(value): return isinstance(value, list) or isinstance(value, Array[str]) #all of the below will throw errors if the conversion is not possible #this behaviour is intended and should be caught in the calling function #which should report errors at runtime or in the log
def FieldConvert(self, strValue, strField=None): if dmGlobals.TraceFunctionMessages: print 'Method: dmParameters:FieldConvert(stringValue, stringFieldName)' FieldValue = self.Field if strField != None: FieldValue = strField theVal = strValue try: if FieldValue in dmGlobals.ALLOWEDVALS: if FieldValue in dmGlobals.FIELDSLIST and not dmGlobals.IsList(strValue): theVal = strValue.Split(Array[str](dmGlobals.CRLISTDELIMITER), StringSplitOptions.RemoveEmptyEntries) elif FieldValue in dmGlobals.FIELDSBOOL and not dmGlobals.IsBool(strValue): theVal = dmGlobals.StringToBool(strValue) elif FieldValue in dmGlobals.FIELDSDATETIME and not dmGlobals.IsDateTime(strValue): theVal = dmGlobals.StringToDate(strValue) elif FieldValue in dmGlobals.FIELDSNUMERIC and not dmGlobals.IsFloat(strValue): theVal = dmGlobals.StringToFloat(strValue) elif FieldValue in dmGlobals.FIELDSMANGAYESNO and not dmGlobals.IsMangaYesNo(strValue): theVal = dmGlobals.StringToMangaYesNo(strValue) elif FieldValue in dmGlobals.FIELDSYESNO and not dmGlobals.IsYesNo(strValue): theVal = dmGlobals.StringToYesNo(strValue) elif FieldValue in dmGlobals.FIELDSPSUEDONUMERIC and not isinstance(strValue,str): try: theVal = strValue.ToString() except: pass #otherwise just return the value except Exception as ex: pass return theVal