Exemple #1
0
        /// <summary>
        /// Object details as a string
        /// </summary>
        /// <param name="pObj">The object extended</param>
        /// <param name="session">The session managing this object</param>
        /// <param name="skipArrays">Indicates if string should contain detailed array data.</param>
        ///<returns><see cref="string"/> containing all details of this object.</returns>
        static public string ToStringDetails(this OptimizedPersistable pObj, SessionBase session, bool skipArrays = true)
        {
            Schema schema = session.OpenSchema(false);

            if (pObj.GetWrappedObject() == null)
            {
                return(pObj.ToString() + pObj.ToStringDetails(schema, pObj.GetTypeVersion(), skipArrays));
            }
            else
            {
                Array array = pObj.GetWrappedObject() as Array;
                if (array != null)
                {
                    return(pObj.GetWrappedObject().ToString() + " (" + array.Length + ") " + Oid.AsString(pObj.Id) + pObj.ToStringDetails(schema, pObj.GetTypeVersion(), skipArrays));
                }
                else
                {
                    return(pObj.GetWrappedObject().ToString() + " " + Oid.AsString(pObj.Id) + pObj.ToStringDetails(schema, pObj.GetTypeVersion(), skipArrays));
                }
            }
        }
Exemple #2
0
        internal static string ToStringDetails(object obj, Schema schema, Page page, TypeVersion _shape, bool skipArrays)
        {
            OptimizedPersistable pObj = obj as OptimizedPersistable;

            if (pObj != null && pObj.GetWrappedObject() != null)
            {
                obj = pObj.GetWrappedObject();
            }
            IOptimizedPersistable ipObj = pObj;
            StringBuilder         sb    = new StringBuilder(100);
            Array       array           = obj as Array;
            SessionBase session         = page.Database.GetSession();

            if (array != null && !skipArrays)
            {
                int  i           = 0;
                bool isValueType = array.GetType().GetElementType().GetTypeInfo().IsValueType;
                foreach (object arrayObj in array)
                {
                    if (isValueType == false || i % 10 == 0)
                    {
                        //sb.AppendLine();
                        if (arrayObj == null)
                        {
                            sb.Append("\t[" + i.ToString() + "]\t" + "null");
                        }
                        else
                        {
                            ipObj = arrayObj as IOptimizedPersistable;
                            if (arrayObj != null && ipObj != null)
                            {
                                sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(ipObj.Id));
                            }
                            else
                            {
                                bool foundIt = session.GlobalObjWrapperGet(arrayObj, out ipObj);
                                if (foundIt)
                                {
                                    sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(ipObj.Id));
                                }
                                else
                                {
                                    sb.Append("\t[" + i.ToString() + "]\t" + arrayObj.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        if (arrayObj == null)
                        {
                            sb.Append("\t" + "null");
                        }
                        else
                        {
                            ipObj = arrayObj as IOptimizedPersistable;
                            if (arrayObj != null && ipObj != null)
                            {
                                sb.Append("\t" + Oid.AsString(ipObj.Id));
                            }
                            else
                            {
                                bool foundIt = session.GlobalObjWrapperGet(arrayObj, out ipObj);
                                if (foundIt)
                                {
                                    sb.Append("\t" + Oid.AsString(ipObj.Id));
                                }
                                else
                                {
                                    sb.Append("\t" + arrayObj.ToString());
                                }
                            }
                        }
                    }
                    i++;
                }
            }
            else
            {
                if (_shape.BaseShape != null && _shape.BaseShape.Type != CommonTypes.s_typeOfValueType)
                {
                    //TypeVersion baseClassShape = schema.lookupByNumber.TypeVersionLookup(_shape.baseShape);
                    sb.Append(ToStringDetails(obj, schema, page, _shape.BaseShape, skipArrays));
                }
                if (_shape.DataMemberArray.Length == 0 && sb.Length == 0)
                {
                    sb.Append(obj.ToString()); // an object without member fields (like used in NodaTime)
                }
                else
                {
                    foreach (DataMember m in _shape.DataMemberArray)
                    {
                        FieldInfo field = m.GetField(_shape.Type);
                        object    o     = m.GetMemberValue(obj);
                        //sb.AppendLine();
                        if (o == null)
                        {
                            sb.Append("  " + field.Name + " : " + "null");
                        }
                        else
                        {
                            bool foundIt = session.GlobalObjWrapperGet(o, out ipObj);
                            if (foundIt)
                            {
                                sb.Append("  " + field.Name + " : " + pObj.GetWrappedObject().ToString() + " " + Oid.AsString(ipObj.Id));
                            }
                            else
                            {
                                array = o as Array;
                                if (array != null)
                                {
                                    Type elementType = m.FieldType.GetElementType();
                                    sb.Append("  " + field.Name + " " + field.FieldType.ToGenericTypeString());
                                    if (!skipArrays)
                                    {
                                        sb.Append(ArrayToString(array, false, page, elementType));
                                    }
                                }
                                else
                                {
                                    IList list = o as IList;
                                    if (list != null)
                                    {
                                        int i = 0;
                                        sb.Append("  " + field.Name + " " + o.ToString());
                                        foreach (object listObj in list)
                                        {
                                            //sb.AppendLine();
                                            ipObj = listObj as IOptimizedPersistable;
                                            if (listObj != null && pObj != null)
                                            {
                                                sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(ipObj.Id));
                                            }
                                            else
                                            {
                                                if (session.GlobalObjWrapperGet(listObj, out ipObj))
                                                {
                                                    sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(ipObj.Id));
                                                }
                                                else
                                                {
                                                    sb.Append("\t[" + i.ToString() + "]\t" + listObj.ToString());
                                                }
                                            }
                                            i++;
                                        }
                                    }
                                    else if (field.FieldType.GetTypeCode() != TypeCode.Object || m.HasId || !field.FieldType.GetTypeInfo().IsSerializable || (o as WeakIOptimizedPersistableReferenceBase) != null)
                                    {
                                        sb.Append("  " + field.Name + " : " + o.ToString());
                                    }
                                    else
                                    {
                                        TypeVersion memberShape = schema.RegisterClass(field.FieldType, session);
                                        sb.Append("  " + field.Name + " : " + ToStringDetails(o, schema, page, memberShape, skipArrays));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(sb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Currently only used by Database Manager
        /// </summary>
        /// <param name="pObj">Object for which we want detailed to string data</param>
        /// <param name="schema">The active schema</param>
        /// <param name="typeVersion">describes the type of the pObj</param>
        /// <param name="skipArrays">if <c>true</c> include array data in generated string</param>
        /// <returns>content of an object as string</returns>
        static public string ToStringDetails(this OptimizedPersistable pObj, Schema schema, TypeVersion typeVersion, bool skipArrays)
        {
            object obj = pObj.GetWrappedObject() ?? pObj;

            return(ToStringDetails(obj, schema, pObj.GetPage(), typeVersion, skipArrays));
        }