Exemple #1
0
        /// <summary>
        /// Get the display string in the editor of the given object.
        /// </summary>
        /// <param name="obj">The given object.</param>
        /// <returns>Returns the string value for displaying the object.</returns>
        public static string RetrieveDisplayValue(object obj, object parent = null, string paramName = null, int indexInArray = -1)
        {
            string str = string.Empty;

            if (obj != null)
            {
                Type type = obj.GetType();

                // ISerializableData type
                if (obj is ISerializableData)
                {
                    str = ((ISerializableData)obj).GetDisplayValue();
                }

                // Array type
                else if (Plugin.IsArrayType(type))
                {
                    str = DesignerArray.RetrieveDisplayValue(obj);
                }

                // Struct type
                else if (Plugin.IsCustomClassType(type))
                {
                    str = DesignerStruct.RetrieveDisplayValue(obj, parent, paramName, indexInArray);
                }

                // Enum type
                else if (type.IsEnum)
                {
                    str = DesignerEnum.GetDisplayName(obj);
                }

                // Other types
                else
                {
                    str = obj.ToString();

                    if (Plugin.IsStringType(type))
                    {
                        str = string.Format("\"{0}\"", str);
                    }
                    else
                    {
                        string[] tokens = str.Split(' ');
                        str = tokens[tokens.Length - 1];
                    }
                }
            }

            return(str);
        }
Exemple #2
0
        private static void parseStringValue(NodeTag.DefaultObject node, System.Collections.IList structArray, Type itemType, string str, int startIndex, int endIndex)
        {
            string propertyName  = string.Empty;
            string propertyValue = string.Empty;

            int nextIndex = getItemStr(str, startIndex, endIndex, out propertyName, out propertyValue);

            if (nextIndex > 0)
            {
                object item = DesignerStruct.ParseStringValue(itemType, null, propertyValue, node);
                structArray.Add(item);

                parseStringValue(node, structArray, itemType, str, nextIndex, endIndex);
            }
        }
        /// <summary>
        /// Get the string value when saving or exporting the given object.
        /// </summary>
        /// <param name="obj">The given object.</param>
        /// <returns>Returns the string value for saving or exporting the object.</returns>
        public static string RetrieveExportValue(object obj, object parent = null, string paramName = null)
        {
            string str = "\"\"";

            if (obj != null)
            {
                Type type = obj.GetType();

                // ISerializableData type
                if (obj is ISerializableData)
                {
                    str = ((ISerializableData)obj).GetExportValue();
                }
                // Array type
                else if (Plugin.IsArrayType(type))
                {
                    str = DesignerArray.RetrieveExportValue(obj);
                }
                // Struct type
                else if (Plugin.IsCustomClassType(type))
                {
                    str = DesignerStruct.RetrieveExportValue(obj, parent, paramName, true);
                }
                // Other types
                else
                {
                    str = obj.ToString();

                    if (Plugin.IsStringType(type))
                    {
                        str = string.Format("\"{0}\"", str);
                    }
                    else if (Plugin.IsBooleanType(type))
                    {
                        str = str.ToLowerInvariant();
                    }
                }
            }

            return(str);
        }