當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。