Exemple #1
0
            private static void FlattenStatus(StatusData status)
            {
                if (status.Value != null)
                {
                    return;
                }

                var type = status.Object.GetType();
                var attr = type.GetAttribute <StatusNameAttribute>();

                if (status.Statuses == null || status.Statuses.Count == 0)
                {
                    if (status.Object == StatusContainer.Root)
                    {
                        return;
                    }

                    var name = attr?.Name;
                    if (name == null)
                    {
                        if (type.IsGenericType)
                        {
                            if (type.GetInterface("IList") != null)
                            {
                                var innerType = type.IsArray ? type.GetElementType() : type.GenericTypeArguments[0];
                                name = (type.IsArray ? "Array Of ~ " : "List Of ~ ") + innerType.Namespace + "." + innerType.Name;
                            }
                            else
                            {
                                name = type.Namespace + "." + type.Name + " [" + type.GenericTypeArguments.Select(ga => ga.Namespace + "." + ga.Name).Join(", ") + "]";
                            }
                        }
                        else
                        {
                            name = type.Namespace + "." + type.Name;
                        }
                    }
                    status.Value = new StatusItem
                    {
                        Name = name
                    };
                    return;
                }

                var sValue = status.Statuses.Count > 1
                    ? status.Statuses.FirstOrDefault(s => s.Name == null)
                    : status.Statuses[0];

                if (sValue == null)
                {
                    sValue = new StatusItem();
                }
                else
                {
                    status.Statuses.Remove(sValue);
                }
                if (sValue.Name == null)
                {
                    var name = attr?.Name;
                    if (name == null)
                    {
                        if (type.IsGenericType)
                        {
                            if (type.GetInterface("IList") != null)
                            {
                                var innerType = type.IsArray ? type.GetElementType() : type.GenericTypeArguments[0];
                                name = (type.IsArray ? "Array Of ~ " : "List Of ~ ") + innerType.Namespace + "." + innerType.Name;
                            }
                            else
                            {
                                name = type.Namespace + "." + type.Name + " [" + type.GenericTypeArguments.Select(ga => ga.Namespace + "." + ga.Name).Join(", ") + "]";
                            }
                        }
                        else
                        {
                            name = type.Namespace + "." + type.Name;
                        }
                    }
                    sValue.Name = name;
                }
                sValue.Children.AddRange(status.Statuses);
                status.Statuses = null;
                status.Value    = sValue;
            }