예제 #1
0
            public bool TryWriteValue <T>(IValueWriter valueWriter, T value)
            {
                switch (value)
                {
                case TimeSpan timeSpan:
                    if (timeSpan.Days > 0)
                    {
                        valueWriter.SetTypeAnnotation("days");
                        valueWriter.WriteFloat(timeSpan.TotalDays);
                    }
                    else if (timeSpan.Hours > 0)
                    {
                        valueWriter.SetTypeAnnotation("hours");
                        valueWriter.WriteFloat(timeSpan.TotalHours);
                    }
                    else if (timeSpan.Minutes > 0)
                    {
                        valueWriter.SetTypeAnnotation("minutes");
                        valueWriter.WriteFloat(timeSpan.TotalMinutes);
                    }
                    else if (timeSpan.Seconds > 0)
                    {
                        valueWriter.SetTypeAnnotation("seconds");
                        valueWriter.WriteFloat(timeSpan.TotalSeconds);
                    }
                    else if (timeSpan.Milliseconds > 0)
                    {
                        valueWriter.SetTypeAnnotation("millis");
                        valueWriter.WriteFloat(timeSpan.TotalMilliseconds);
                    }
                    else
                    {
                        valueWriter.SetTypeAnnotation("ticks");
                        valueWriter.WriteInt(timeSpan.Ticks);
                    }

                    return(true);

                default:
                    return(false);
                }
            }