예제 #1
0
        /// <summary>
        /// Makes and returns connection string.
        /// </summary>
        /// <returns>Can not be null.</returns>
        public override string ToString()
        {
            using (var parameters = new FxParams())
            {
                foreach (var element in this.GetValidProperties())
                {
                    var obj  = element.GetValue(this, null);
                    var type = obj.GetType();

                    if (type == typeof(int))
                    {
                        var value = (int)obj;
                        parameters.SetInt32(element.Name, value);
                    }
                    else if (type == typeof(double))
                    {
                        var value = (double)obj;
                        parameters.SetReal(element.Name, value);
                    }
                    else if (type == typeof(string))
                    {
                        var value = (string)obj;
                        parameters.SetString(element.Name, value);
                    }
                    else if (type == typeof(bool))
                    {
                        var value = (bool)obj;
                        parameters.SetBool(element.Name, value);
                    }
                    else
                    {
                        var message = string.Format("Unsupported property type = {0}", type);
                        throw new ArgumentException(message);
                    }
                }

                var result = parameters.ToString();
                return(result);
            }
        }