本文整理汇总了C#中System.Variant.Is方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.Is方法的具体用法?C# Variant.Is怎么用?C# Variant.Is使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Variant
的用法示例。
在下文中一共展示了Variant.Is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDateTime
public void TestDateTime()
{
DateTime arg = new DateTime(2010, 1, 2, 3, 4, 5, 6);
Variant v1 = new Variant(arg);
Assert.AreEqual(v1.Type, Variant.EnumType.DateTime);
Assert.IsTrue(v1.Is(Variant.EnumType.DateTime));
Assert.IsTrue(v1.Is<DateTime>());
Assert.AreEqual(v1.As<DateTime>(), arg);
Assert.AreEqual(Convert.ToDateTime(v1), arg);
Assert.AreEqual(v1.ToString(), "2010-01-02T03:04:05.006");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例2: TestTSConstruction
public void TestTSConstruction()
{
Variant v = new Variant(Variant.EnumType.TimeSeries);
Assert.AreEqual(v.Type, Variant.EnumType.TimeSeries);
Assert.IsTrue(v.Is(Variant.EnumType.TimeSeries));
Assert.AreEqual(v.Count, 0);
Assert.IsTrue(v.Empty);
}
示例3: TestBoolean
public void TestBoolean()
{
Variant vTrue = new Variant(true);
Assert.AreEqual(vTrue.Type, Variant.EnumType.Boolean);
Assert.IsTrue(vTrue.Is(Variant.EnumType.Boolean));
Assert.IsTrue(vTrue.Is<bool>());
Assert.IsTrue(vTrue.As<bool>());
Assert.IsTrue(Convert.ToBoolean(vTrue));
Assert.AreEqual(vTrue.ToString(), "true");
Variant vFalse = new Variant(false);
Assert.AreEqual(vFalse.Type, Variant.EnumType.Boolean);
Assert.IsTrue(vFalse.Is(Variant.EnumType.Boolean));
Assert.IsTrue(vFalse.Is<bool>());
Assert.IsFalse(vFalse.As<bool>());
Assert.IsFalse(Convert.ToBoolean(vFalse));
Assert.AreEqual(vFalse.ToString(), "false");
Variant v1 = new Variant(vTrue);
Assert.IsTrue(v1.Equals(vTrue));
Variant v2 = new Variant(vFalse);
Assert.IsTrue(v2.Equals(vFalse));
}
示例4: 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; });
}
示例5: TestBagConstruction
public void TestBagConstruction()
{
Variant v = new Variant(Variant.EnumType.Bag);
Assert.AreEqual(v.Type, Variant.EnumType.Bag);
Assert.IsTrue(v.Is(Variant.EnumType.Bag));
Assert.AreEqual(v.Count, 0);
Assert.IsTrue(v.Empty);
}
示例6: TestConstruction
public void TestConstruction()
{
System.Data.DataTable dt1 = new DataTable();
dt1.Columns.Add(new DataColumn("Double", typeof(double)));
dt1.Columns.Add(new DataColumn("String", typeof(string)));
DataRow dr = dt1.NewRow();
dr[0] = 1.0;
dr[1] = "value";
dt1.Rows.Add(dr);
Variant v1 = new Variant(dt1);
Assert.AreEqual(v1.Type, Variant.EnumType.DataTable);
Assert.IsTrue(v1.Is(Variant.EnumType.DataTable));
Assert.DoesNotThrow(delegate { v1.AsDataTable(); });
Assert.Throws<VariantException>(delegate { v1.As<int>(); });
}
示例7: WriteInstruction
void WriteInstruction(Variant instruction)
{
if (instruction.Is(VariantBase.EnumType.Mapping) && instruction.ContainsKey(XmlConst.Target) && instruction.ContainsKey(XmlConst.Data))
{
m_writer.WriteProcessingInstruction(instruction[XmlConst.Target].As<string>(), instruction[XmlConst.Data].As<string>());
}
else
{
throw new VariantException(string.Format("Expecting dictionary containing '{0}' and '{1}' for processing instruction", XmlConst.Target, XmlConst.Data));
}
}
示例8: WriteDocument
void WriteDocument(Variant document)
{
if ((m_mode & XmlMode.NoHeader) == 0)
{
WriteHeader();
}
if ((m_mode & XmlMode.Preserve)!=0)
{
string rootName = "";
if (document.Is(VariantBase.EnumType.Mapping))
{
foreach (VariantItem item in document)
{
if (item.Key == XmlConst.Text)
{
throw new VariantException("Encountered text in document node");
}
else if (item.Key == XmlConst.Attributes)
{
throw new VariantException("Encountered attributes in document node");
}
else if (item.Key == XmlConst.Instruction)
{
WriteInstruction(item.Value);
}
else if (item.Key == XmlConst.Comment)
{
WriteComment(item.Value);
}
else
{
if (rootName.Length==0)
{
rootName = item.Key;
}
else
{
throw new VariantException(string.Format("Illegal element {0} encountered in document, expecting single element {1} at root", item.Key, rootName));
}
Push(rootName);
WriteElement(item.Value);
Pop();
}
}
}
else
{
throw new VariantException("Invalid document structure, root node must be a Dictionary or Bag");
}
}
else
{
Push();
WriteVariant(document);
Pop();
}
}
示例9: TestDouble
public void TestDouble()
{
Variant v1 = new Variant((double)5.0);
Assert.AreEqual(v1.Type, Variant.EnumType.Double);
Assert.IsTrue(v1.Is(Variant.EnumType.Double));
Assert.IsTrue(v1.Is<double>());
Assert.AreEqual(v1.As<double>(), 5.0);
Assert.AreEqual(Convert.ToDouble(v1), 5.0);
Assert.AreEqual(v1.ToString(), "5");
Variant vNaN = new Variant(double.NaN);
Assert.AreEqual(vNaN.ToString(), "NaN");
Variant vINF = new Variant(double.PositiveInfinity);
Assert.AreEqual(vINF.ToString(), "INF");
Variant vNEGINF = new Variant(double.NegativeInfinity);
Assert.AreEqual(vNEGINF.ToString(), "-INF");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例10: TestUInt64
public void TestUInt64()
{
Variant v1 = new Variant((UInt64)4);
Assert.AreEqual(v1.Type, Variant.EnumType.UInt64);
Assert.IsTrue(v1.Is(Variant.EnumType.UInt64));
Assert.IsTrue(v1.Is<UInt64>());
Assert.AreEqual(v1.As<UInt64>(), 4);
Assert.AreEqual(Convert.ToUInt64(v1), 4);
Assert.AreEqual(v1.ToString(), "4");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例11: TestTime
public void TestTime()
{
TimeSpan arg = new TimeSpan(0, 2, 3, 4, 5);
Variant v1 = new Variant(arg);
Assert.AreEqual(v1.Type, Variant.EnumType.Time);
Assert.IsTrue(v1.Is(Variant.EnumType.Time));
Assert.IsTrue(v1.Is<TimeSpan>());
Assert.AreEqual(v1.As<TimeSpan>(), arg);
Assert.AreEqual(v1.ToString(), "02:03:04.005");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例12: TestString
public void TestString()
{
Variant v1 = new Variant("test string");
Assert.AreEqual(v1.Type, Variant.EnumType.String);
Assert.IsTrue(v1.Is(Variant.EnumType.String));
Assert.IsTrue(v1.Is<string>());
Assert.AreEqual(v1.As<string>(), "test string");
Assert.AreEqual(Convert.ToString(v1), "test string");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例13: TestNone
public void TestNone()
{
Variant v1 = new Variant();
Assert.AreEqual(v1.Type, Variant.EnumType.None);
Assert.IsTrue(v1.Is(Variant.EnumType.None));
Variant v2 = new Variant(Variant.EnumType.None);
Assert.AreEqual(v2.Type, Variant.EnumType.None);
Assert.IsTrue(v2.Is(Variant.EnumType.None));
Variant v3 = new Variant(v1);
Assert.IsTrue(v1.Equals(v3));
}
示例14: TestInt64
public void TestInt64()
{
Variant v1 = new Variant((Int64)3);
Assert.AreEqual(v1.Type, Variant.EnumType.Int64);
Assert.IsTrue(v1.Is(Variant.EnumType.Int64));
Assert.IsTrue(v1.Is<Int64>());
Assert.AreEqual(v1.As<Int64>(), 3);
Assert.AreEqual(Convert.ToInt64(v1), 3);
Assert.AreEqual(v1.ToString(), "3");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例15: TestInt32
public void TestInt32()
{
Variant v1 = new Variant((Int32)1);
Assert.AreEqual(v1.Type, Variant.EnumType.Int32);
Assert.IsTrue(v1.Is(Variant.EnumType.Int32));
Assert.IsTrue(v1.Is<Int32>());
Assert.AreEqual(v1.As<Int32>(), 1);
Assert.AreEqual(Convert.ToInt32(v1), 1);
Assert.AreEqual(v1.ToString(), "1");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}