Esempio n. 1
0
        /// <summary>
        /// Generates a string that can be used as a name for the entity that will be created for this preview.
        /// </summary>
        /// <returns></returns>
        protected string BuildName()
        {
            var    description     = DisplayAttribute.GetDisplay(typeof(T));
            string typeDisplayName = description != null && !string.IsNullOrEmpty(description.Name) ? description.Name : typeof(T).Name;

            return(string.Format("Preview entity for {0} '{1}'", typeDisplayName, AssetItem.Location));
        }
        /// <summary>經由 DisplayAttribute 取得顯示名稱</summary>
        /// <param name="enumVal">The enum value</param>
        /// <param name="prop">公開屬性名稱</param>
        /// <returns>顯示名稱</returns>
        public static string GetDisplayName(this Enum enumVal, string prop = "Name")
        {
            Type type = enumVal.GetType();

            if (type.GetCustomAttributes(typeof(FlagsAttribute), false).Any())
            {
                Array         enumValues    = type.GetEnumValues();
                StringBuilder stringBuilder = new StringBuilder();
                string        str           = string.Empty;
                foreach (Enum @enum in enumValues.Cast <Enum>())
                {
                    if (enumVal.HasFlag(@enum) && ((int)(object)enumVal <= 0 || (int)(object)@enum != 0))
                    {
                        DisplayAttribute attributeOfType = @enum.GetAttributeOfType <DisplayAttribute>();
                        stringBuilder.Append(str);
                        stringBuilder.Append(attributeOfType == null ? @enum.ToString() : attributeOfType.GetDisplay(prop));
                        str = ", ";
                    }
                }

                return(stringBuilder.ToString());
            }

            DisplayAttribute attributeOfType1 = enumVal.GetAttributeOfType <DisplayAttribute>();

            if (attributeOfType1 != null)
            {
                return(attributeOfType1.GetDisplay(prop));
            }

            return(enumVal.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// 取得DisplayAttribute公開屬性內容
        /// </summary>
        /// <param name="propertyInfo">Discovers the attributes of a property and provides access to property metadata.</param>
        /// <returns>The value that is used for display in the UI.</returns>
        public static string GetDisplayName(this PropertyInfo propertyInfo)
        {
            if ((PropertyInfo)null == propertyInfo)
            {
                return(string.Empty);
            }

            DisplayAttribute attr = propertyInfo.GetCustomAttributes(typeof(DisplayAttribute), true).Cast <DisplayAttribute>().SingleOrDefault <DisplayAttribute>();

            if (attr == null)
            {
                return(string.Empty);
            }

            return(attr.GetDisplay());
        }
Esempio n. 4
0
        internal AssetToImportMergeGroup(AssetToImportByImporter parent, AssetItem item)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            this.Parent = parent;
            Item        = item;
            Merges      = new List <AssetToImportMerge>();
            Enabled     = true;
            var assetDescription = DisplayAttribute.GetDisplay(item.Asset.GetType());

            Log = new LoggerResult(string.Format("Import {0} {1}", assetDescription != null ? assetDescription.Name : "Asset", item));
        }
        /// <summary>
        /// Display components that are tagged with the <see cref="DisplayAttribute"/>.
        /// </summary>
        /// <param name="context">Context of the view model.</param>
        /// <param name="viewModel">The current view model</param>
        /// <param name="component">The entity component to display</param>
        private void AutoDisplayComponent(ViewModelContext context, IViewModelNode viewModel, EntityComponent component)
        {
            var displayComp = DisplayAttribute.GetDisplay(component.GetType());

            if (displayComp == null)
            {
                return;
            }

            var componentViewModel = viewModel.GetChildrenByName("Component");

            if (componentViewModel == null)
            {
                return;
            }

            // Change the name of the component being displayed
            if (!string.IsNullOrEmpty(displayComp.Name))
            {
                var componentName = viewModel.GetChildrenByName("PropertyKeyName");
                if (componentName != null)
                {
                    componentName.Value = displayComp.Name;
                }
            }

            var propertyToDisplay = new List <Tuple <DisplayAttribute, ViewModelNode> >();
            var memberInfos       = new List <MemberInfo>();

            memberInfos.AddRange(component.GetType().GetProperties());
            memberInfos.AddRange(component.GetType().GetFields());

            // Process fields and properties
            foreach (var property in memberInfos)
            {
                var display = DisplayAttribute.GetDisplay(property);
                if (display == null)
                {
                    continue;
                }

                IViewModelContent modelContent = null;
                object            modelValue   = null;

                var propertyInfo = property as PropertyInfo;
                if (propertyInfo != null)
                {
                    if (typeof(ParameterCollection).IsAssignableFrom(propertyInfo.PropertyType))
                    {
                        modelValue = propertyInfo.GetValue(component, null);
                    }
                    else
                    {
                        modelContent = new PropertyInfoViewModelContent(new ParentNodeValueViewModelContent(), propertyInfo);
                    }
                }

                var fieldInfo = property as FieldInfo;
                if (fieldInfo != null)
                {
                    if (typeof(ParameterCollection).IsAssignableFrom(fieldInfo.FieldType))
                    {
                        modelValue = fieldInfo.GetValue(component);
                    }
                    else
                    {
                        modelContent = new FieldInfoViewModelContent(new ParentNodeValueViewModelContent(), fieldInfo);
                    }
                }

                var propertyViewModel = modelValue != null ? new ViewModelNode(display.Name ?? property.Name, modelValue) : new ViewModelNode(display.Name ?? property.Name, modelContent);
                propertyViewModel.GenerateChildren(context);
                propertyToDisplay.Add(new Tuple <DisplayAttribute, ViewModelNode>(display, propertyViewModel));
            }

            foreach (var item in propertyToDisplay.OrderBy((left) => left.Item1.Order))
            {
                componentViewModel.Children.Add(item.Item2);
            }
        }