InitValues() public method

public InitValues ( ) : void
return void
Example #1
0
        public static Config Parse(object obj)
        {
            var config = new Config();

            if (obj == null)
            {
                throw new ArgumentNullException("obj", "Can't parse null object");
            }

            PropertyInfo[] props = obj.GetType().GetProperties();

            foreach (PropertyInfo prop in props)
            {
                object val  = prop.GetValue(obj, null);
                string type = prop.PropertyType.FullName;
                string name = prop.Name.ToLower();

                switch (name)
                {
                case "keylength":
                    config.keyLength = ParseInt(name, type, val);
                    break;

                case "width":
                    config.imageWidth = ParseInt(name, type, val);
                    break;

                case "height":
                    config.imageHeight = ParseInt(name, type, val);
                    break;

                case "foreground":
                    config.foregroundColor = ParseColor(name, type, val);
                    break;

                case "background":
                    config.backgroundColor = ParseColor(name, type, val);
                    break;

                case "overlay":
                    config.overlayEnabled = ParseBool(name, type, val);
                    break;

                case "waves":
                    config.wavesFilterEnabled = ParseBool(name, type, val);
                    break;

                case "font":
                    config.fontPath = ParseString(name, type, val);
                    break;
                }
            }

            config.InitValues();
            return(config);
        }
Example #2
0
        public static Config Parse(object obj)
        {
            var config = new Config();

            if (obj == null)
            {
                throw new ArgumentNullException("obj", "Can't parse null object");
            }

            PropertyInfo[] props = obj.GetType().GetProperties();

            foreach (PropertyInfo prop in props)
            {
                object val = prop.GetValue(obj, null);
                string type = prop.PropertyType.FullName;
                string name = prop.Name.ToLower();

                switch (name)
                {
                    case "keylength":
                        config.keyLength = ParseInt(name, type, val);
                        break;

                    case "width":
                        config.imageWidth = ParseInt(name, type, val);
                        break;

                    case "height":
                        config.imageHeight = ParseInt(name, type, val);
                        break;

                    case "foreground":
                        config.foregroundColor = ParseColor(name, type, val);
                        break;

                    case "background":
                        config.backgroundColor = ParseColor(name, type, val);
                        break;

                    case "overlay":
                        config.overlayEnabled = ParseBool(name, type, val);
                        break;

                    case "waves":
                        config.wavesFilterEnabled = ParseBool(name, type, val);
                        break;

                    case "font":
                        config.fontPath = ParseString(name, type, val);
                        break;
                }
            }

            config.InitValues();
            return config;
        }