示例#1
0
        /// <summary>
        /// Builds up a string representation of the information inside this object.
        /// </summary>
        /// <param name="format">
        /// The format to use for the address formatting (<see cref="AddressFormatting"/>).
        /// </param>
        /// <returns>
        /// a well formatted string representation of the data
        /// </returns>
        public string ToString(AddressFormatting format)
        {
            var result = string.Empty;

            switch (format)
            {
            case AddressFormatting.StreetAndCity:
                result += this.StreetName ?? string.Empty;
                result += string.IsNullOrEmpty(result) ? string.Empty : "\n";

                result += string.IsNullOrEmpty(this.PostalCode) ? string.Empty : this.PostalCode + " ";
                result += string.IsNullOrEmpty(this.CityName) ? string.Empty : this.CityName;
                break;

            default:
                result += this.StreetName ?? string.Empty;
                result += string.IsNullOrEmpty(result) ? string.Empty : " / ";

                result += string.IsNullOrEmpty(this.PostalCode) ? string.Empty : this.PostalCode + " ";
                result += string.IsNullOrEmpty(this.CityName) ? string.Empty : this.CityName + " ";
                result += string.IsNullOrEmpty(this.StateName) ? string.Empty : "(" + this.StateName + ") ";
                result += string.IsNullOrEmpty(this.CountryName) ? string.Empty : this.CountryName + " ";
                result += (this.Phone == null) ? string.Empty : (" Phone: " + this.Phone);

                result = result.Trim().Replace("  ", " ");
                break;
            }

            return(result);
        }
示例#2
0
        static void Main(string[] args)
        {
            var addressFormatting = new AddressFormatting();

            addressFormatting.LoadComponentAliases();

            foreach (var x in addressFormatting._componentMapping)
            {
                Console.WriteLine(x.Key, x.Value);
            }
        }