static public object Fill <T>(System.Array a, T value) { for (long i = 0, len = a.GetLongLength(0); i != len; ++i) { a.SetValue(value, i); } return(a); }
static public object Fill <T>(System.Array a, int lwr, int upr, T value) { for (long i = lwr, len = a.GetLongLength(0); i < len && i < upr; ++i) { a.SetValue(value, i); } return(a); }
static public object Fill <T>(System.Array a, int lwr, int upr, T[] values) { for (long i = lwr, len = a.GetLongLength(0), j = 0; i < len && i < upr && j < values.LongLength; ++i, ++j) { a.SetValue(values[j], i); } return(a); }
static public object Fill(System.Array a, System.Array slice) { long srcLen = slice.GetLongLength(0); long destLen = a.GetLongLength(0); for (long i = 0; (i < srcLen) && (i < destLen); ++i) { a.SetValue(slice.GetValue(i), i); } return(a); }
static public int GetLongLength(IntPtr l) { try { System.Array self = (System.Array)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); var ret = self.GetLongLength(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static int GetLongLength(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.Array obj = (System.Array)ToLua.CheckObject(L, 1, typeof(System.Array)); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); long o = obj.GetLongLength(arg0); LuaDLL.lua_pushnumber(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private string FormatArrayTypeName(Type arrayType, Array arrayOpt, ObjectFormattingOptions options) { StringBuilder sb = new StringBuilder(); // print the inner-most element type first: Type elementType = arrayType.GetElementType(); while (elementType.IsArray) { elementType = elementType.GetElementType(); } sb.Append(FormatTypeName(elementType, options)); // print all components of a jagged array: Type type = arrayType; do { if (arrayOpt != null) { sb.Append('['); int rank = type.GetArrayRank(); bool anyNonzeroLowerBound = false; for (int i = 0; i < rank; i++) { if (arrayOpt.GetLowerBound(i) > 0) { anyNonzeroLowerBound = true; break; } } for (int i = 0; i < rank; i++) { int lowerBound = arrayOpt.GetLowerBound(i); long length = arrayOpt.GetLongLength(i); if (i > 0) { sb.Append(", "); } if (anyNonzeroLowerBound) { AppendArrayBound(sb, lowerBound, options.UseHexadecimalNumbers); sb.Append(".."); AppendArrayBound(sb, length + lowerBound, options.UseHexadecimalNumbers); } else { AppendArrayBound(sb, length, options.UseHexadecimalNumbers); } } sb.Append(']'); arrayOpt = null; } else { AppendArrayRank(sb, type); } type = type.GetElementType(); } while (type.IsArray); return sb.ToString(); }
private void CollectMultiArrayItems(List<STypeInstanceProxy> items, Array array, int dimension, params long[] indices) { // visszaállítási adatok mentése long originalIndicesValueOnDimension = 0; if (dimension + 1 < array.GetType().GetArrayRank()) { originalIndicesValueOnDimension = indices[dimension + 1]; } for (long i = 0; i < array.GetLongLength(dimension); i++) { STypeInstanceProxy proxy = null; indices[dimension] = i; if (indices.Length - 1 == dimension) { object value = array.GetValue(indices); if (value != null) { proxy = GetTypeInstanceProxy(value, value.GetType()); // array.GetType().GetElementType() } } else { proxy = (STypeInstanceProxy)GetTypeInfo(array.GetType().GetElementType()).Clone(); bool firstTime = false; proxy.InstanceId = mGenerator.GetId(proxy, out firstTime); //mProxyIdGenerator; proxy.InstanceValue = dimension; // level of the array proxy.IsArrayDimensionRepresentation = true; mReferenceVsTypeInstances.Add(proxy.InstanceId, proxy); } items.Add(proxy); if (dimension + 1 < array.GetType().GetArrayRank()) { proxy.ArrayItems = new List<STypeInstanceProxy>(); CollectMultiArrayItems(proxy.ArrayItems, array, dimension + 1, indices); indices[dimension + 1] = originalIndicesValueOnDimension; } } }
private void CollectArrayItems(List<STypeInstanceProxy> items, Array array, params long[] indices) { long length = array.GetLongLength(0); for (long i = 0; i < length; i++) { indices[0] = i; object arrayItem = array.GetValue(indices); if (arrayItem == null) { items.Add(null); } else if (arrayItem.GetType().IsGenericType && arrayItem.GetType().GetGenericTypeDefinition().Equals(typeof(Nullable<>))) { items.Add(GetTypeInstanceProxy(arrayItem, arrayItem.GetType())); } else { items.Add(GetTypeInstanceProxy(arrayItem, null)); } } }
private void DeclareArrayInitializer(Array array, int dim, long[] indices, StringBuilder sb) { long length = array.GetLongLength(dim); sb.Append("("); if (length == 1) { sb.Append("0 => "); } int linelen = 0; for (long i = 0; i < length; i++) { if (i > 0) sb.Append(","); ++linelen; if (linelen < 200) { sb.Append(" "); } else { sb.AppendLine(); linelen = 0; } indices[dim] = i; if (dim < array.Rank - 1) { DeclareArrayInitializer(array, dim + 1, indices, sb); } else { object element = array.GetValue(indices); string value = GetValueID(element); sb.Append(value); linelen += value.Length; } } sb.Append(")"); }
private void DeclareArrayInitializer(Array array, int dim, long[] indices, StringBuilder sb, string name) { long length = array.GetLongLength(dim); //sb.Append(" /*"); //if (length == 1) //{ // sb.Append("0 => "); //} int linelen = 0; for (long i = 0; i < length; i++) { if (i > 0) sb.Append(";"); ++linelen; if (linelen < 200) { sb.Append(" "); } else { sb.AppendLine(); linelen = 0; } indices[dim] = i; if (dim < array.Rank - 1) { DeclareArrayInitializer(array, dim + 1, indices, sb, name); } else { object element = array.GetValue(indices); string value = GetValueID(element); if(dim == 0) sb.Append(name + "[" + i + "] = " + value); else sb.Append(name + "[" + dim + "][" + i + "] = " + value); linelen += value.Length; } } sb.Append(";"); sb.AppendLine(); }