Example #1
0
        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();
        }
Example #2
0
            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;
                    }
                }
            }
Example #3
0
        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(")");
        }
Example #4
0
 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));
         }
     }
 }
Example #5
0
        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();
        }