当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.GetType方法代码示例

本文整理汇总了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));
        }
开发者ID:kumaraswamy86d12,项目名称:Albedo,代码行数:40,代码来源:Scenario.cs

示例2: SetReminderTime

 private void SetReminderTime(TimeSpan newTime)
 {
     this.reminderTime.ValidatingType = newTime.GetType();
     this.reminderTime.Text = Format.MaskedText(newTime);
 }
开发者ID:gayancc,项目名称:lazycure-code,代码行数:5,代码来源:Options.cs

示例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));
        }
开发者ID:tleviathan,项目名称:Albedo,代码行数:29,代码来源:Scenario.cs

示例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);
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:13,代码来源:XmlSerializationWriter1.cs


注:本文中的System.TimeSpan.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。