本文整理汇总了C#中System.Variant.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.GetEnumerator方法的具体用法?C# Variant.GetEnumerator怎么用?C# Variant.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Variant
的用法示例。
在下文中一共展示了Variant.GetEnumerator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestTSEnumeration
public void TestTSEnumeration()
{
Variant v = new Variant(Variant.EnumType.TimeSeries);
v.Add(new DateTime(2010, 1, 2, 3, 4, 5, 6), new Variant("value1"));
v.Add(new DateTime(2010, 1, 3, 3, 4, 5, 6), new Variant("value2"));
IEnumerator<VariantItem> en = v.GetEnumerator();
en.Reset();
Assert.IsTrue(en.MoveNext());
Assert.Throws<VariantException>(delegate { string k = en.Current.Key; });
Assert.AreEqual("value1", en.Current.Value.As<string>());
Assert.AreEqual(new DateTime(2010, 1, 2, 3, 4, 5, 6), en.Current.Time);
Assert.IsTrue(en.MoveNext());
Assert.Throws<VariantException>(delegate { string k = en.Current.Key; });
Assert.AreEqual("value2", en.Current.Value.As<string>());
Assert.AreEqual(new DateTime(2010, 1, 3, 3, 4, 5, 6), en.Current.Time);
Assert.IsFalse(en.MoveNext());
}
示例2: TestAny
public void TestAny()
{
Variant v1 = new Variant(Variant.EnumType.Any, "1.0");
Assert.AreEqual(v1.Type, Variant.EnumType.Any);
Assert.IsTrue(v1.Is(Variant.EnumType.Any));
Assert.AreEqual(1.0, v1.As<double>());
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
// Enumerating an Any variant with content should throw an exception
Assert.Throws<VariantException>(delegate { v1.GetEnumerator(); });
// We should be able to enumerate an Any variant with no content as this is a common occurance when reading untyped XML
Variant v3 = new Variant(Variant.EnumType.Any);
IEnumerator<VariantItem> enumerator = v3.GetEnumerator();
Assert.IsFalse(enumerator.MoveNext());
Assert.Throws<VariantException>(delegate { VariantItem item = enumerator.Current; });
}
示例3: TestBagEnumeration
public void TestBagEnumeration()
{
Variant v = new Variant(Variant.EnumType.Bag);
v.Add("key2", new Variant("value2"));
v.Add("key1", new Variant("value1"));
v.Add("key1", new Variant("value1"));
v.Add("key2", new Variant("value2"));
IEnumerator<VariantItem> en = v.GetEnumerator();
en.Reset();
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("key2", en.Current.Key);
Assert.AreEqual("value2", en.Current.Value.As<string>());
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("key1", en.Current.Key);
Assert.AreEqual("value1", en.Current.Value.As<string>());
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("key1", en.Current.Key);
Assert.AreEqual("value1", en.Current.Value.As<string>());
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("key2", en.Current.Key);
Assert.AreEqual("value2", en.Current.Value.As<string>());
Assert.IsFalse(en.MoveNext());
}
示例4: TestListEnumeration
public void TestListEnumeration()
{
Variant v = new Variant(Variant.EnumType.List);
v.Add(new Variant("value1"));
v.Add(new Variant(2.0));
IEnumerator<VariantItem> en = v.GetEnumerator();
en.Reset();
Assert.IsTrue(en.MoveNext());
Assert.Throws<VariantException>(delegate { string k = en.Current.Key; });
Assert.Throws<VariantException>(delegate { DateTime t = en.Current.Time; });
Assert.AreEqual("value1", en.Current.Value.As<string>());
Assert.IsTrue(en.MoveNext());
Assert.Throws<VariantException>(delegate { string k = en.Current.Key; });
Assert.Throws<VariantException>(delegate { DateTime t = en.Current.Time; });
Assert.AreEqual(2.0, en.Current.Value.As<double>());
Assert.IsFalse(en.MoveNext());
}