本文整理汇总了C#中System.Variant.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.Equals方法的具体用法?C# Variant.Equals怎么用?C# Variant.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Variant
的用法示例。
在下文中一共展示了Variant.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBag
public void TestBag()
{
Variant v1 = new Variant(Variant.EnumType.Bag);
v1.Add("key1", new Variant("value1"));
v1.Add("key2", new Variant(1.0));
byte[] bytes = BinaryWriter.ToBytes(v1);
Variant v2 = BinaryReader.FromBytes(bytes);
Assert.AreEqual(v2.Type, Variant.EnumType.Bag);
Assert.IsTrue(v1.Equals(v2));
}
示例2: TestList
public void TestList()
{
Variant v1 = new Variant(Variant.EnumType.List);
v1.Add(new Variant("value1"));
v1.Add(new Variant(1.0));
string xml = XmlWriter.ToString(v1);
Variant v2 = XmlReader.FromString(xml);
Assert.AreEqual(v2.Type, Variant.EnumType.List);
Assert.IsTrue(v1.Equals(v2));
}
示例3: TestBuffer
public void TestBuffer()
{
byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
Variant v1 = new Variant(bytes);
string xml = XmlWriter.ToString(v1);
Variant v2 = XmlReader.FromString(xml);
Assert.AreEqual(v2.Type, Variant.EnumType.Buffer);
Assert.IsTrue(v1.Equals(v2));
}
示例4: TestBuffer
public void TestBuffer()
{
byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
Variant v1 = new Variant(bytes);
byte[] bin = BinaryWriter.ToBytes(v1);
Variant v2 = BinaryReader.FromBytes(bin);
Assert.AreEqual(v2.Type, Variant.EnumType.Buffer);
Assert.IsTrue(v1.Equals(v2));
}
示例5: 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));
}
示例6: 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; });
}
示例7: 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));
}
示例8: TestTimeSeries
public void TestTimeSeries()
{
Variant v1 = new Variant(Variant.EnumType.TimeSeries);
v1.Add(new DateTime(2010, 1, 2, 3, 4, 5, 6), new Variant("value1"));
v1.Add(new DateTime(2010, 1, 3, 3, 4, 5, 6), new Variant("value2"));
string xml = XmlWriter.ToString(v1);
Variant v2 = XmlReader.FromString(xml);
Assert.AreEqual(v2.Type, Variant.EnumType.TimeSeries);
Assert.IsTrue(v1.Equals(v2));
}
示例9: TestTuple
public void TestTuple()
{
Variant v1 = new Variant(Variant.EnumType.Tuple, 2);
v1[0] = new Variant("value");
v1[1] = new Variant(1.0);
byte[] bytes = BinaryWriter.ToBytes(v1);
Variant v2 = BinaryReader.FromBytes(bytes);
Assert.AreEqual(v2.Type, Variant.EnumType.Tuple);
Assert.IsTrue(v1.Equals(v2));
}
示例10: TestTimeSeries
public void TestTimeSeries()
{
Variant v1 = new Variant(Variant.EnumType.TimeSeries);
v1.Add(new DateTime(2010, 1, 2, 3, 4, 5, 6), new Variant("value1"));
v1.Add(new DateTime(2010, 1, 3, 3, 4, 5, 6), new Variant("value2"));
byte[] bytes = BinaryWriter.ToBytes(v1);
Variant v2 = BinaryReader.FromBytes(bytes);
Assert.AreEqual(v2.Type, Variant.EnumType.TimeSeries);
Assert.IsTrue(v1.Equals(v2));
}
示例11: TestPrimitives
public void TestPrimitives()
{
Int32 argInt32 = -1;
UInt32 argUInt32 = 0xffffffff;
Int64 argInt64 = -1;
UInt64 argUInt64 = 0xffffffffffffffff;
bool argBoolean = true;
double argDouble = 2.0;
string argString = "test string";
DateTime argDateTime = new DateTime(2010, 1, 2, 3, 4, 5, 6);
TimeSpan argTime = new TimeSpan(0, 1, 2, 3, 4);
Variant v1 = new Variant(Variant.EnumType.Dictionary);
v1.Add("Int32", new Variant(argInt32));
v1.Add("UInt32", new Variant(argUInt32));
v1.Add("Int64", new Variant(argInt64));
v1.Add("UInt64", new Variant(argUInt64));
v1.Add("Boolean", new Variant(argBoolean));
v1.Add("Double", new Variant(argDouble));
v1.Add("String", new Variant(argString));
v1.Add("DateTime", new Variant(argDateTime));
v1.Add("Time", new Variant(argTime));
v1.Add("None", new Variant(Variant.EnumType.None));
string xml = XmlWriter.ToString(v1);
Variant v2 = XmlReader.FromString(xml);
Assert.IsTrue(v1.Equals(v2));
}
示例12: TestComparison
public void TestComparison()
{
System.Data.DataTable dt1 = new DataTable();
dt1.Columns.Add(new DataColumn("Double", typeof(double)));
dt1.Columns.Add(new DataColumn("String", typeof(string)));
DataRow dr1 = dt1.NewRow();
dr1[0] = 1.0;
dr1[1] = "value";
dt1.Rows.Add(dr1);
Variant v1 = new Variant(dt1);
System.Data.DataTable dt2 = new DataTable();
dt2.Columns.Add(new DataColumn("Double", typeof(double)));
dt2.Columns.Add(new DataColumn("String", typeof(string)));
DataRow dr2 = dt2.NewRow();
dr2[0] = 1.0;
dr2[1] = "value";
dt2.Rows.Add(dr2);
Variant v2 = new Variant(dt2);
System.Data.DataTable dt3 = new DataTable();
dt3.Columns.Add(new DataColumn("Double", typeof(double)));
dt3.Columns.Add(new DataColumn("String", typeof(string)));
DataRow dr3 = dt3.NewRow();
dr3[0] = 2.0;
dr3[1] = "value";
dt3.Rows.Add(dr3);
Variant v3 = new Variant(dt3);
Assert.IsTrue(v1.Equals(v2));
Assert.IsFalse(v1.Equals(v3));
Assert.AreEqual(0, v1.CompareTo(v2));
Assert.AreEqual(-1, v2.CompareTo(v3));
Assert.AreEqual(1, v3.CompareTo(v2));
}
示例13: 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));
}
示例14: 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));
}
示例15: 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));
}