private static bool TryWriteFactoryMethodCall(
                long value,
                double totalValue,
                string valueName,
                TranslationWriter writer)
            {
                if (value == 0)
                {
                    return(false);
                }

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (value != totalValue)
                {
                    return(false);
                }

                var factoryMethodName = "From" + valueName;

                writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                writer.WriteDotToTranslation();
                writer.WriteToTranslation(factoryMethodName, MethodName);
                writer.WriteToTranslation('(');
                writer.WriteToTranslation(value);
                writer.WriteToTranslation(')');
                return(true);
            }
            public void WriteTo(TranslationWriter writer)
            {
                if (TryWriteFactoryMethodCall(_timeSpan.Days, _timeSpan.TotalDays, "Days", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Hours, _timeSpan.TotalHours, "Hours", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Minutes, _timeSpan.TotalMinutes, "Minutes", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Seconds, _timeSpan.TotalSeconds, "Seconds", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Milliseconds, _timeSpan.TotalMilliseconds, "Milliseconds", writer))
                {
                    return;
                }

                if ((_timeSpan.Days == 0) && (_timeSpan.Hours == 0) && (_timeSpan.Minutes == 0) && (_timeSpan.Seconds == 0))
                {
                    writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                    writer.WriteDotToTranslation();
                    writer.WriteToTranslation("FromTicks", MethodName);
                    writer.WriteToTranslation('(');
                    writer.WriteToTranslation(Math.Floor(_timeSpan.TotalMilliseconds * 10000).ToString(CurrentCulture));
                    goto EndTranslation;
                }

                writer.WriteNewToTranslation();
                writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                writer.WriteToTranslation('(');

                if (_timeSpan.Days == 0)
                {
                    WriteTimeSpanHoursMinutesSeconds(writer, _timeSpan);
                    goto EndTranslation;
                }

                writer.WriteToTranslation(_timeSpan.Days);
                writer.WriteToTranslation(", ");
                WriteTimeSpanHoursMinutesSeconds(writer, _timeSpan);

                if (_timeSpan.Milliseconds != 0)
                {
                    writer.WriteToTranslation(", ");
                    writer.WriteToTranslation(_timeSpan.Milliseconds);
                }

EndTranslation:
                writer.WriteToTranslation(')');
            }
        public void WriteTo(TranslationWriter writer)
        {
            if (_subject != null)
            {
                _subject.WriteInParenthesesIfRequired(writer, _context);
                writer.WriteDotToTranslation();
            }

            writer.WriteToTranslation(_memberName);
        }
예제 #4
0
            public void WriteTo(TranslationWriter writer)
            {
                _subjectTranslation.WriteInParenthesesIfRequired(writer, _context);

                if (_isPartOfMethodCallChain)
                {
                    writer.WriteNewLineToTranslation();
                    writer.Indent();
                }

                writer.WriteDotToTranslation();
                _methodInvocationTranslation.WriteTo(writer);

                if (_isPartOfMethodCallChain)
                {
                    writer.Unindent();
                }
            }
 public void WriteTo(TranslationWriter writer)
 {
     _subjectTranslation.WriteTo(writer);
     writer.WriteDotToTranslation();
     writer.WriteToTranslation(_subjectMethodName, MethodName);
 }
 public void WriteTo(TranslationWriter writer)
 {
     _typeNameTranslation.WriteTo(writer);
     writer.WriteDotToTranslation();
     writer.WriteToTranslation(_enumValue);
 }
 public void WriteTo(TranslationWriter writer)
 {
     writer.WriteTypeNameToTranslation("DBNull");
     writer.WriteDotToTranslation();
     writer.WriteToTranslation("Value");
 }