本文整理汇总了C#中System.TimeSpan.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.GetType方法的具体用法?C# TimeSpan.GetType怎么用?C# TimeSpan.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromSeveralPropertiesAndFields
public void ReadFromSeveralPropertiesAndFields()
{
var ts = new TimeSpan(2, 4, 3, 8, 9);
var flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
var elements = ts.GetType()
.GetProperties(flags)
.Select(pi => new PropertyInfoElement(pi))
.Cast<IReflectionElement>()
.Concat(ts.GetType()
.GetFields(flags)
.Select(fi => new FieldInfoElement(fi))
.Cast<IReflectionElement>())
.ToArray();
var visitor = new ValueCollectingVisitor(ts);
var actual =
new CompositeReflectionElement(elements).Accept(visitor);
var actualValues = actual.Value.Cast<object>().ToArray();
Assert.Equal(elements.Length, actualValues.Length);
Assert.Equal(1, actualValues.Count(ts.Days.Equals));
Assert.Equal(1, actualValues.Count(ts.Hours.Equals));
Assert.Equal(1, actualValues.Count(ts.Milliseconds.Equals));
Assert.Equal(1, actualValues.Count(ts.Minutes.Equals));
Assert.Equal(1, actualValues.Count(ts.Seconds.Equals));
Assert.Equal(1, actualValues.Count(ts.Ticks.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalDays.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalHours.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalMilliseconds.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalMinutes.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalSeconds.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.MaxValue.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.MinValue.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerDay.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerHour.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerMillisecond.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerMinute.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerSecond.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.Zero.Equals));
}
示例2: SetReminderTime
private void SetReminderTime(TimeSpan newTime)
{
this.reminderTime.ValidatingType = newTime.GetType();
this.reminderTime.Text = Format.MaskedText(newTime);
}
示例3: ReadFromSeveralPropertiesAndFields
public void ReadFromSeveralPropertiesAndFields()
{
var ts = new TimeSpan(2, 4, 3, 8, 9);
var elements = ts.GetType().GetPublicPropertiesAndFields().ToArray();
var actual = elements.Accept(new ValueCollectingVisitor(ts));
var actualValues = actual.Value.ToArray();
Assert.Equal(elements.Length, actualValues.Length);
Assert.Equal(1, actualValues.Count(ts.Days.Equals));
Assert.Equal(1, actualValues.Count(ts.Hours.Equals));
Assert.Equal(1, actualValues.Count(ts.Milliseconds.Equals));
Assert.Equal(1, actualValues.Count(ts.Minutes.Equals));
Assert.Equal(1, actualValues.Count(ts.Seconds.Equals));
Assert.Equal(1, actualValues.Count(ts.Ticks.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalDays.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalHours.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalMilliseconds.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalMinutes.Equals));
Assert.Equal(1, actualValues.Count(ts.TotalSeconds.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.MaxValue.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.MinValue.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerDay.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerHour.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerMillisecond.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerMinute.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.TicksPerSecond.Equals));
Assert.Equal(1, actualValues.Count(TimeSpan.Zero.Equals));
}
示例4: Write186_TimeSpan
private void Write186_TimeSpan(string n, string ns, TimeSpan o, bool needType)
{
if (!needType && (o.GetType() != typeof(TimeSpan)))
{
throw base.CreateUnknownTypeException(o);
}
base.WriteStartElement(n, ns, o, false, null);
if (needType)
{
base.WriteXsiType("TimeSpan", "");
}
base.WriteEndElement(o);
}