Ejemplo n.º 1
0
        /// <summary>
        /// Creates an options entry wrapper for the specified property.
        /// </summary>
        /// <param name="info">The property to wrap.</param>
        /// <param name="oa">The option title and tool tip.</param>
        /// <returns>An options wrapper, or null if none can handle this type.</returns>
        private static OptionsEntry CreateOptions(PropertyInfo info, OptionAttribute oa)
        {
            OptionsEntry entry = null;
            Type         type  = info.PropertyType;
            string       field = info.Name;

            // Enumeration type
            if (type.IsEnum)
            {
                entry = new SelectOneOptionsEntry(field, oa.Title, oa.Tooltip, type);
            }
            else if (type == typeof(bool))
            {
                entry = new CheckboxOptionsEntry(field, oa.Title, oa.Tooltip);
            }
            else if (type == typeof(int))
            {
                entry = new IntOptionsEntry(oa.Title, oa.Tooltip, info);
            }
            else if (type == typeof(float))
            {
                entry = new FloatOptionsEntry(oa.Title, oa.Tooltip, info);
            }
            else if (type == typeof(string))
            {
                entry = new StringOptionsEntry(oa.Title, oa.Tooltip, info);
            }
            return(entry);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an options entry wrapper for the specified property.
        /// </summary>
        /// <param name="info">The property to wrap.</param>
        /// <param name="spec">The option title and tool tip.</param>
        /// <returns>An options wrapper, or null if none can handle this type.</returns>
        private static OptionsEntry FindOptionClass(IOptionSpec spec, PropertyInfo info)
        {
            OptionsEntry entry = null;
            Type         type  = info.PropertyType;
            string       field = info.Name;

            // Enumeration type
            if (type.IsEnum)
            {
                entry = new SelectOneOptionsEntry(field, spec, type);
            }
            else if (type == typeof(bool))
            {
                entry = new CheckboxOptionsEntry(field, spec);
            }
            else if (type == typeof(int))
            {
                entry = new IntOptionsEntry(field, spec, info.
                                            GetCustomAttribute <LimitAttribute>());
            }
            else if (type == typeof(int?))
            {
                entry = new NullableIntOptionsEntry(field, spec, info.
                                                    GetCustomAttribute <LimitAttribute>());
            }
            else if (type == typeof(float))
            {
                entry = new FloatOptionsEntry(field, spec, info.
                                              GetCustomAttribute <LimitAttribute>());
            }
            else if (type == typeof(float?))
            {
                entry = new NullableFloatOptionsEntry(field, spec, info.
                                                      GetCustomAttribute <LimitAttribute>());
            }
            else if (type == typeof(string))
            {
                entry = new StringOptionsEntry(field, spec, info.
                                               GetCustomAttribute <LimitAttribute>());
            }
            else if (type == typeof(Action <object>))
            {
                // Should not actually be serialized to the JSON
                entry = new ButtonOptionsEntry(field, spec);
            }
            else if (type == typeof(LocText))
            {
                entry = new TextBlockOptionsEntry(field, spec);
            }
            return(entry);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an options entry wrapper for the specified property.
        /// </summary>
        /// <param name="info">The property to wrap.</param>
        /// <param name="oa">The option title and tool tip.</param>
        /// <returns>An options wrapper, or null if none can handle this type.</returns>
        private static OptionsEntry CreateOptions(PropertyInfo info, OptionAttribute oa)
        {
            OptionsEntry entry = null;
            Type         type  = info.PropertyType;
            string       field = info.Name;

            // Enumeration type
            if (type.IsEnum)
            {
                entry = new SelectOneOptionsEntry(field, oa, type);
            }
            else if (type == typeof(bool))
            {
                entry = new CheckboxOptionsEntry(field, oa);
            }
            else if (type == typeof(int))
            {
                entry = new IntOptionsEntry(oa, info);
            }
            else if (type == typeof(float))
            {
                entry = new FloatOptionsEntry(oa, info);
            }
            else if (type == typeof(string))
            {
                entry = new StringOptionsEntry(oa, info);
            }
            else if (type == typeof(System.Action))
            {
                // Should not actually be serialized to the JSON
                entry = new ButtonOptionsEntry(oa, info);
            }
            else if (type == typeof(LocText))
            {
                entry = new TextBlockOptionsEntry(oa, info);
            }
            return(entry);
        }