예제 #1
0
        /// <summary>
        /// This is a support function for the VelocityDbBrowser. It converts a field into a string.
        /// </summary>
        /// <param name="member">A field in an object</param>
        /// <param name="obj">The object containing the field</param>
        /// <param name="page">The page of the object</param>
        /// <param name="skipArrays">Option to skip arrays of the object</param>
        /// <returns>A <see cref="string"/> containing all details of this field.</returns>
        public static string ToStringDetails(DataMember member, object obj, IOptimizedPersistable pObj, Page page, bool skipArrays)
        {
            SessionBase           session = pObj.Page.Database.Session;
            IOptimizedPersistable placeHolder;
            Schema    schema = session.OpenSchema(false);
            FieldInfo field  = member.Field;
            object    o      = member.GetMemberValue(obj);

            if (member.IsGuid)
            {
                Guid guid = (Guid)o;
                return(guid.ToString());
            }
            StringBuilder sb = new StringBuilder(100);

            if (o == null)
            {
                sb.Append("  " + member.FieldName + " : " + "null");
            }
            else
            {
                bool foundIt = session.GlobalObjWrapperGet(o, out placeHolder);
                if (foundIt)
                {
                    sb.Append("  " + member.FieldName + " : " + placeHolder.WrappedObject.ToString() + " " + Oid.AsString(placeHolder.Id));
                }
                else
                {
                    Array array = o as Array;
                    if (array != null)
                    {
                        Type elementType = member.FieldType.GetElementType();
                        sb.Append("  " + member.FieldName + " " + field.FieldType.ToGenericTypeString() + " size: " + array.Length.ToString());
                        if (!skipArrays)
                        {
                            sb.Append(ArrayToString(array, false, page, elementType));
                        }
                    }
                    else
                    {
                        IList list = o as IList;
                        if (list != null)
                        {
                            int    i          = 0;
                            string listObjStr = "  " + member.FieldName + " " + o.GetType().ToGenericTypeString() + " size: " + list.Count.ToString();
                            sb.Append(listObjStr);
                            if (!skipArrays)
                            {
                                foreach (object listObj in list)
                                {
                                    sb.AppendLine();
                                    pObj = listObj as OptimizedPersistable;
                                    if (listObj != null && pObj != null)
                                    {
                                        sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(pObj.Id));
                                    }
                                    else
                                    {
                                        foundIt = session.GlobalObjWrapperGet(listObj, out placeHolder);
                                        if (foundIt)
                                        {
                                            sb.Append("\t[" + i.ToString() + "]\t" + Oid.AsString(placeHolder.Id));
                                        }
                                        else
                                        {
                                            sb.Append("\t[" + i.ToString() + "]\t" + listObj.ToString());
                                        }
                                    }
                                    i++;
                                }
                            }
                        }
                        else
                        {
                            VelocityDbType t = null;
                            if (field.FieldType == CommonTypes.s_typeOfType)
                            {
                                Type fieldType = o as Type;
                                sb.Append("  " + field.Name + " : " + fieldType.ToGenericTypeString());
                            }
                            else
                            {
                                bool cond1 = field.FieldType.GetTypeInfo().IsPrimitive || member.HasId || field.FieldType == CommonTypes.s_typeOfString || field.FieldType.GetTypeInfo().IsEnum;
                                if (cond1 || schema.LookupByType.TryGetValue(field.FieldType, out t) == false ||
                                    (field.FieldType.GetTypeInfo().IsGenericType&& field.FieldType.GetGenericTypeDefinition() == CommonTypes.s_typeOfWeakIOptimizedPersistableReference))
                                {
                                    sb.Append("  " + field.Name + " : " + o.ToString());
                                }
                                else
                                {
                                    TypeVersion memberShape = t.LastShape();
                                    bool        isNullable  = memberShape.Type.GetTypeInfo().IsGenericType&& memberShape.Type.GetGenericTypeDefinition() == CommonTypes.s_typeOfNullable;
                                    if (isNullable)
                                    {
                                        Type elementType = memberShape.Type.GetTypeInfo().GetGenericArguments()[0];
                                        schema.LookupByType.TryGetValue(elementType, out t);
                                        memberShape = t.LastShape();
                                    }
                                    sb.Append("  " + field.Name + " : " + ToStringDetails(o, schema, page, memberShape, skipArrays));
                                }
                            }
                        }
                    }
                }
            }
            return(sb.ToString());
        }
예제 #2
0
 public TypeViewModel(SchemasViewModel schemaViewModel, VelocityDbType type)
     : base(schemaViewModel, true)
 {
     _type             = type;
     _schemasViewModel = schemaViewModel;
 }