コード例 #1
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return(((PropertyInfo)value).Name);
 }
コード例 #2
0
        public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
        {
            var dateOnly = (DateOnly)value;

            formattedGraph.AddFragment(dateOnly.ToString("<yyyy-MM-dd>", CultureInfo.InvariantCulture));
        }
コード例 #3
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return(((short)value).ToString(CultureInfo.InvariantCulture) + "s");
 }
コード例 #4
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return("<null>");
 }
        /// <inheritdoc />
        public string Format(object value, FormattingContext context, FormatChild formatChild)
        {
            DateTimeOffset dateTimeOffset;

            if (value is DateTime dateTime)
            {
                dateTimeOffset = dateTime.ToDateTimeOffset();
            }
            else
            {
                dateTimeOffset = (DateTimeOffset)value;
            }

            var fragments = new List <string>();

            if (HasDate(dateTimeOffset))
            {
                fragments.Add(dateTimeOffset.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
            }

            if (HasTime(dateTimeOffset))
            {
                if (HasNanoSeconds(dateTimeOffset))
                {
                    fragments.Add(dateTimeOffset.ToString("HH:mm:ss.fffffff", CultureInfo.InvariantCulture));
                }
                else if (HasMicroSeconds(dateTimeOffset))
                {
                    fragments.Add(dateTimeOffset.ToString("HH:mm:ss.ffffff", CultureInfo.InvariantCulture));
                }
                else if (HasMilliSeconds(dateTimeOffset))
                {
                    fragments.Add(dateTimeOffset.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture));
                }
                else
                {
                    fragments.Add(dateTimeOffset.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
                }
            }

            if (dateTimeOffset.Offset > TimeSpan.Zero)
            {
                fragments.Add("+" + formatChild("offset", dateTimeOffset.Offset));
            }

            if (dateTimeOffset.Offset < TimeSpan.Zero)
            {
                fragments.Add(formatChild("offset", dateTimeOffset.Offset));
            }

            if (!fragments.Any())
            {
                if (HasMilliSeconds(dateTimeOffset))
                {
                    fragments.Add("0001-01-01 00:00:00." + dateTimeOffset.ToString("fff", CultureInfo.InvariantCulture));
                }
                else
                {
                    fragments.Add("0001-01-01 00:00:00.000");
                }
            }

            return("<" + string.Join(" ", fragments.ToArray()) + ">");
        }
コード例 #6
0
        private static string Format(object value, FormattingContext context, FormatChild formatChild)
        {
            IValueFormatter firstFormatterThatCanHandleValue = Formatters.First(f => f.CanHandle(value));

            return(firstFormatterThatCanHandleValue.Format(value, context, formatChild));
        }
コード例 #7
0
 public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
 {
     formattedGraph.AddFragment(value.ToString().Replace(" = ", " == ", StringComparison.Ordinal));
 }
コード例 #8
0
        public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
        {
            DateTimeOffset dateTimeOffset;
            bool           significantOffset = false;

            if (value is DateTime dateTime)
            {
                dateTimeOffset = dateTime.ToDateTimeOffset();
            }
            else
            {
                dateTimeOffset    = (DateTimeOffset)value;
                significantOffset = true;
            }

            formattedGraph.AddFragment("<");

            bool hasDate = HasDate(dateTimeOffset);

            if (hasDate)
            {
                formattedGraph.AddFragment(dateTimeOffset.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
            }

            bool hasTime = HasTime(dateTimeOffset);

            if (hasTime)
            {
                if (hasDate)
                {
                    formattedGraph.AddFragment(" ");
                }

                if (HasNanoSeconds(dateTimeOffset))
                {
                    formattedGraph.AddFragment(dateTimeOffset.ToString("HH:mm:ss.fffffff", CultureInfo.InvariantCulture));
                }
                else if (HasMicroSeconds(dateTimeOffset))
                {
                    formattedGraph.AddFragment(dateTimeOffset.ToString("HH:mm:ss.ffffff", CultureInfo.InvariantCulture));
                }
                else if (HasMilliSeconds(dateTimeOffset))
                {
                    formattedGraph.AddFragment(dateTimeOffset.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture));
                }
                else
                {
                    formattedGraph.AddFragment(dateTimeOffset.ToString("HH:mm:ss", CultureInfo.InvariantCulture));
                }
            }

            if (dateTimeOffset.Offset > TimeSpan.Zero)
            {
                formattedGraph.AddFragment(" +");
                formatChild("offset", dateTimeOffset.Offset, formattedGraph);
            }
            else if (dateTimeOffset.Offset < TimeSpan.Zero)
            {
                formattedGraph.AddFragment(" ");
                formatChild("offset", dateTimeOffset.Offset, formattedGraph);
            }
            else if (significantOffset && (hasDate || hasTime))
            {
                formattedGraph.AddFragment(" +0h");
            }
            else
            {
                // No offset added, since it was deemed unnecessary
            }

            if (!hasDate && !hasTime)
            {
                if (HasMilliSeconds(dateTimeOffset))
                {
                    formattedGraph.AddFragment("0001-01-01 00:00:00." + dateTimeOffset.ToString("fff", CultureInfo.InvariantCulture));
                }
                else
                {
                    formattedGraph.AddFragment("0001-01-01 00:00:00.000");
                }
            }

            formattedGraph.AddFragment(">");
        }
コード例 #9
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return(value.ToString().Replace(" = ", " == ", StringComparison.Ordinal));
 }
コード例 #10
0
        public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
        {
            var arr = (Array)value;

            if (arr.Length == 0)
            {
                formattedGraph.AddFragment("{empty}");
                return;
            }

            int[] dimensionIndices = Enumerable.Range(0, arr.Rank).Select(dimension => arr.GetLowerBound(dimension)).ToArray();

            int         currentLoopIndex = 0;
            IEnumerator enumerator       = arr.GetEnumerator();

            // Emulate n-ary loop
            while (currentLoopIndex >= 0)
            {
                int currentDimensionIndex = dimensionIndices[currentLoopIndex];

                if (IsFirstIteration(arr, currentDimensionIndex, currentLoopIndex))
                {
                    formattedGraph.AddFragment("{");
                }

                if (IsInnerMostLoop(arr, currentLoopIndex))
                {
                    enumerator.MoveNext();
                    formatChild(string.Join("-", dimensionIndices), enumerator.Current, formattedGraph);
                    if (!IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                    {
                        formattedGraph.AddFragment(", ");
                    }

                    ++dimensionIndices[currentLoopIndex];
                }
                else
                {
                    ++currentLoopIndex;
                    continue;
                }

                while (IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                {
                    formattedGraph.AddFragment("}");

                    // Reset current loop's variable to start value ...and move to outer loop
                    dimensionIndices[currentLoopIndex] = arr.GetLowerBound(currentLoopIndex);
                    --currentLoopIndex;

                    if (currentLoopIndex < 0)
                    {
                        break;
                    }

                    currentDimensionIndex = dimensionIndices[currentLoopIndex];
                    if (!IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                    {
                        formattedGraph.AddFragment(", ");
                    }

                    ++dimensionIndices[currentLoopIndex];
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance.
 /// </summary>
 /// <param name="value">The value for which to create a <see cref="System.String"/>.</param>
 /// <param name="useLineBreaks"> </param>
 /// <param name="processedObjects">
 /// A collection of objects that
 /// </param>
 /// <param name="nestedPropertyLevel">
 /// The level of nesting for the supplied value. This is used for indenting the format string for objects that have
 /// no <see cref="object.ToString()"/> override.
 /// </param>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return("0x" + ((byte)value).ToString("X2"));
 }
コード例 #12
0
        public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
        {
            var timeOnly = (TimeOnly)value;

            formattedGraph.AddFragment(timeOnly.ToString("<HH:mm:ss.fff>", CultureInfo.InvariantCulture));
        }
コード例 #13
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return((context.UseLineBreaks ? Environment.NewLine : "") + "\"" + value.ToString().Escape() + "\"");
 }
コード例 #14
0
 public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
 {
     formattedGraph.AddFragment(((XAttribute)value).ToString());
 }
コード例 #15
0
        private static string GetPropertyValueTextFor(object value, SelectedMemberInfo selectedMemberInfo, FormattingContext context, FormatChild formatChild)
        {
            object propertyValue;

            try
            {
                propertyValue = selectedMemberInfo.GetValue(value, null);
            }
            catch (Exception ex)
            {
                propertyValue = string.Format("[Member '{0}' threw an exception: '{1}']", selectedMemberInfo.Name, ex.Message);
            }

            return(string.Format("{0}{1} = {2}",
                                 CreateWhitespaceForLevel(context.Depth + 1),
                                 selectedMemberInfo.Name,
                                 formatChild(selectedMemberInfo.Name, propertyValue)));
        }
コード例 #16
0
        /// <inheritdoc />
        public string Format(object value, FormattingContext context, FormatChild formatChild)
        {
            var arr = (Array)value;

            if (arr.Length == 0)
            {
                return("{empty}");
            }

            var sb = new StringBuilder();

            int[] dimensionIndices = Enumerable.Range(0, arr.Rank).Select(dimension => arr.GetLowerBound(dimension)).ToArray();

            int         currentLoopIndex = 0;
            IEnumerator enumerator       = arr.GetEnumerator();

            // Emulate n-ary loop
            while (currentLoopIndex >= 0)
            {
                int currentDimensionIndex = dimensionIndices[currentLoopIndex];

                if (IsFirstIteration(arr, currentDimensionIndex, currentLoopIndex))
                {
                    sb.Append('{');
                }

                if (IsInnerMostLoop(arr, currentLoopIndex))
                {
                    enumerator.MoveNext();
                    sb.Append(formatChild(string.Join("-", dimensionIndices), enumerator.Current));
                    if (!IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                    {
                        sb.Append(", ");
                    }

                    ++dimensionIndices[currentLoopIndex];
                }
                else
                {
                    ++currentLoopIndex;
                    continue;
                }

                while (IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                {
                    sb.Append('}');

                    // Reset current loop's variable to start value ...and move to outer loop
                    dimensionIndices[currentLoopIndex] = arr.GetLowerBound(currentLoopIndex);
                    --currentLoopIndex;

                    if (currentLoopIndex < 0)
                    {
                        break;
                    }

                    currentDimensionIndex = dimensionIndices[currentLoopIndex];
                    if (!IsLastIteration(arr, currentDimensionIndex, currentLoopIndex))
                    {
                        sb.Append(", ");
                    }

                    ++dimensionIndices[currentLoopIndex];
                }
            }

            return(sb.ToString());
        }
コード例 #17
0
 /// <inheritdoc />
 public string Format(object value, FormattingContext context, FormatChild formatChild)
 {
     return("{" + value + "}");
 }
        /// <inheritdoc />
        public string Format(object value, FormattingContext context, FormatChild formatChild)
        {
            var attribute = (XAttribute)value;

            return(attribute.ToString());
        }
コード例 #19
0
 public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
 {
     formattedGraph.AddFragment(((sbyte)value).ToString(CultureInfo.InvariantCulture) + "y");
 }
コード例 #20
0
 public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
 {
     formattedGraph.AddFragment("{" + value + "}");
 }