Пример #1
0
        /// <summary>
        /// An IMetric extension method that converts a given metric value into a string representation based on the given MetricFormat.
        /// </summary>
        /// <exception cref="ArgumentNullException">	Thrown when the metric is null. </exception>
        /// <exception cref="ArgumentException">		Thrown when the key is invalid. </exception>
        /// <param name="metric">	The metric to act on. </param>
        /// <param name="key">      The optional key to prefix metrics with. </param>
        /// <param name="format">	Describes the format to use. </param>
        /// <returns>	A string representation of this object. </returns>
        public static string ToString(this IMetric metric, string key, MetricFormat format)
        {
            if (null == metric)
            {
                throw new ArgumentNullException("metric");
            }
            if (!key.IsValidKey())
            {
                throw new ArgumentException("contains invalid characters", "key");
            }

            string converted = null;

            switch (format)
            {
            case MetricFormat.StatSite:
                converted = metric.ToStatSiteString();
                break;

            case MetricFormat.StatsD:
            default:
                converted = metric.ToStatsDString();
                break;
            }

            return(string.IsNullOrEmpty(key) ? converted : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", key, converted));
        }