Пример #1
0
        }         // func GetConfigurationValue

        internal static object GetConfigurationValue(IDEConfigurationValue attr, string value)
        {
            var type = attr.Type;

            if (attr.IsList)
            {
                return(Procs.GetStrings(value).Select(v => GetConfigurationValueSingle(attr, v)).ToArray());
            }
            else
            {
                return(GetConfigurationValueSingle(attr, value));
            }
        }         // func GetAttributeValue
Пример #2
0
        }         // ctor

        private static object GetConfigurationValueSingle(IDEConfigurationValue attr, string value)
        {
            var type = attr.Type;

            if (type == typeof(LuaType))
            {
                if (value == null)
                {
                    value = attr.DefaultValue ?? "object";
                }
                return(LuaType.GetType(value, false, false).Type);
            }
            else if (type == typeof(Encoding))
            {
                if (String.IsNullOrEmpty(value))
                {
                    value = attr.DefaultValue;
                }

                if (String.IsNullOrEmpty(value))
                {
                    return(Encoding.Default);
                }
                else if (Int32.TryParse(value, out var codePage))
                {
                    return(Encoding.GetEncoding(codePage));
                }
                else
                {
                    return(Encoding.GetEncoding(value));
                }
            }
            else if (type == typeof(CultureInfo))
            {
                return(String.IsNullOrEmpty(value)
                                        ? CultureInfo.GetCultureInfo(attr.DefaultValue)
                                        : CultureInfo.GetCultureInfo(value));
            }
            else if (type == typeof(DirectoryInfo))
            {
                return(String.IsNullOrEmpty(value)
                                        ? null
                                        : new DirectoryInfo(value));
            }
            else if (type == typeof(SecureString))
            {
                try
                {
                    return(Passwords.DecodePassword(value));
                }
                catch
                {
                    return(null);
                }
            }
            else if (type == typeof(FileSize))
            {
                return(FileSize.TryParse(value ?? attr.DefaultValue, out var fileSize)
                                        ? fileSize
                                        : FileSize.Empty);
            }
            else
            {
                try
                {
                    return(Procs.ChangeType(value ?? attr.DefaultValue, type));
                }
                catch
                {
                    return(Procs.ChangeType(attr.DefaultValue, type));
                }
            }
        }         // func GetConfigurationValue