本文整理汇总了C#中Variant类的典型用法代码示例。如果您正苦于以下问题:C# Variant类的具体用法?C# Variant怎么用?C# Variant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Variant类属于命名空间,在下文中一共展示了Variant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStreams
public void TestStreams()
{
Variant dict = new Variant(Variant.EnumType.Dictionary);
dict.Add("key1", new Variant("value1"));
dict.Add("key2", new Variant("value2"));
Variant input = new Variant(Variant.EnumType.List);
for (int i = 0; i < 10000; ++i)
{
input.Add(dict);
}
System.IO.MemoryStream istream = new System.IO.MemoryStream();
using(BinaryWriter writer = new BinaryWriter(istream))
{
writer.Write(input);
}
Variant output;
System.IO.MemoryStream ostream = new System.IO.MemoryStream(istream.GetBuffer());
using (BinaryReader reader = new BinaryReader(ostream))
{
output = reader.Read();
}
Assert.True(input.Equals(output));
}
示例2: TestComparison
public void TestComparison()
{
TypedArray a1 = new TypedArray(Variant.EnumType.Double, 2);
a1[0] = 1.0;
a1[1] = 2.0;
Variant v1 = new Variant(a1);
TypedArray a2 = new TypedArray(Variant.EnumType.Double, 2);
a2[0] = 1.0;
a2[1] = 2.0;
Variant v2 = new Variant(a2);
TypedArray a3 = new TypedArray(Variant.EnumType.Double, 2);
a3[0] = 2.0;
a3[1] = 1.0;
Variant v3 = new Variant(a3);
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));
}
示例3: ConvertToNamedValueList
public static List<NamedValue> ConvertToNamedValueList(IntPtr pXmlSection)
{
if (IntPtr.Zero == pXmlSection)
return null;
List<Rhino.Render.NamedValue> list = new List<NamedValue>();
IntPtr pIterator = UnsafeNativeMethods.Rdk_XmlSection_GetIterator(pXmlSection);
//Fill the property list from the XML section
if (pIterator != IntPtr.Zero)
{
while (true)
{
using (var sh = new StringHolder())
{
Variant variant = new Variant();
if (1 == UnsafeNativeMethods.Rdk_XmlSection_NextParam(pXmlSection, pIterator, sh.ConstPointer(), variant.ConstPointer()))
{
NamedValue nv = new NamedValue(sh.ToString(), variant.AsObject());
list.Add(nv);
}
else
break;
}
}
UnsafeNativeMethods.Rdk_XmlSection_DeleteIterator(pIterator);
}
return list;
}
示例4: NewName
public static Variant NewName(BlockBase parent, string name)
{
var ret = new Variant();
ret.Parent = parent;
ret.name = name;
return ret;
}
示例5: Npc
public Npc(Variant config)
{
ID = config.GetStringOrDefault("_id");
NpcType = config.GetStringOrDefault("SubType");
Name = config.GetStringOrDefault("Name");
m_value = config.GetVariantOrDefault("Value");
if (m_value != null)
{
m_task = m_value.GetVariantOrDefault("Task");
SceneID = m_value.GetStringOrDefault("SceneID");
X = m_value.GetIntOrDefault("X");
Y = m_value.GetIntOrDefault("Y");
object lev;
if (m_value.TryGetValueT("MustKill", out lev))
{
if (lev is bool)
{
if ((bool)lev)
{
m_killLev = 1;
}
}
else if (lev != null)
{
int.TryParse(lev.ToString(), out m_killLev);
}
}
}
}
示例6: TestDictionaryEnumerator
public void TestDictionaryEnumerator()
{
Variant dict = new Variant(Variant.EnumType.Dictionary);
for (int i = 0; i < 1; ++i)
{
dict.Add(i.ToString(), new Variant(i));
}
// Generic enumerator
int count = 0;
foreach (VariantItem item in dict)
{
Assert.True(item.Value.AsInt32().Equals(count));
Assert.True(item.Key.Equals(count.ToString()));
Assert.Throws(typeof(VariantException),
delegate { DateTime time = item.Time; }
);
++count;
}
// Non-generic enumerator
count = 0;
foreach (var item in dict)
{
Assert.True(item.Value.AsInt32().Equals(count));
Assert.True(item.Key.Equals(count.ToString()));
Assert.Throws(typeof(VariantException),
delegate { DateTime time = item.Time; }
);
++count;
}
}
示例7: TestString
public void TestString()
{
String s = "hello";
Variant v = new Variant(s);
Assert.AreEqual(s, v.AsString());
}
示例8: TestStringAsDouble
public void TestStringAsDouble()
{
String s = "hello";
Variant v = new Variant(s);
v.AsDouble();
}
示例9: Broadcast
public override void Broadcast(uint appId, BaseProtocol pFrom, Variant invokeInfo)
{
foreach (var inboundClusterProtocol in InboundClusters.Where(inboundClusterProtocol => pFrom != inboundClusterProtocol))
{
inboundClusterProtocol.Broadcast(appId, pFrom, invokeInfo);
}
}
示例10: UpdateList
/// <summary>
/// Updates the list control.
/// </summary>
private void UpdateList(Session session, Argument[] arguments, string browseName)
{
for (int ii = 0; ii < arguments.Length; ii++)
{
Argument argument = arguments[ii];
Variant defaultValue = new Variant(TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank));
ListViewItem item = new ListViewItem(arguments[ii].Name);
if (browseName == BrowseNames.InputArguments)
{
item.SubItems.Add("IN");
m_firstOutputArgument++;
}
else
{
item.SubItems.Add("OUT");
}
string dataType = session.NodeCache.GetDisplayText(arguments[ii].DataType);
if (arguments[ii].ValueRank >= 0)
{
dataType += "[]";
}
item.SubItems.Add(defaultValue.ToString());
item.SubItems.Add(dataType);
item.SubItems.Add(Utils.Format("{0}", arguments[ii].Description));
item.Tag = defaultValue;
ArgumentsLV.Items.Add(item);
}
}
示例11: GenerateVariants
private static IEnumerable<Variant> GenerateVariants(Variant variant, Potter aBook, IEnumerable<Variant> alreadyGenerated)
{
return variant.Piles
.Where(pile => !pile.Contains(aBook))
.Select(pile => CreateNewVariant(variant, pile, aBook))
.Where(newVariant => alreadyGenerated.All(v => !v.Equals(newVariant)));
}
示例12: SO
public SO(BaseClientApplication app,string name, bool persistent)
{
Name = name;
Application = app;
IsPersistent = persistent;
Version = 1;
if (persistent)
{
_filePath = app.SOPath + Name + ".so";
if (File.Exists(_filePath))
{
Variant.DeserializeFromFile(_filePath, out Payload);
}
else
{
Payload = Variant.Get();
//File.Create(_filePath).Close();
}
}
else
{
Payload = Variant.Get();
}
if (ClientApplicationManager.ClusterApplication != null)
ClientApplicationManager.ClusterApplication.GetProtocolHandler<BaseClusterAppProtocolHandler>().OnSOCreated(this);
}
示例13: ProcessSharedObjectPrimitive
private bool ProcessSharedObjectPrimitive(BaseRTMPProtocol pFrom, SO pSO, string name, Variant request,
int primitiveId)
{
var primitive = request[Defines.RM_SHAREDOBJECT,Defines.RM_SHAREDOBJECT_PRIMITIVES][ primitiveId];
switch ((byte)primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_TYPE])
{
case Defines.SOT_CS_CONNECT:
pSO.RegisterProtocol(pFrom);
return true;
case Defines.SOT_CS_DISCONNECT:
UnRegisterProtocol(pFrom);
return true;
case Defines.SOT_CSC_DELETE_DATA:
pSO.UnSet(primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD],pFrom);
return true;
case Defines.SOT_CS_SET_ATTRIBUTE:
if (pSO == null)
{
Logger.FATAL("SO is null");
return false;
}
foreach (KeyValuePair<string,Variant> item in primitive [Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD])
{
pSO.Set(item.Key, item.Value.Clone(), pFrom);
}
return true;
case Defines.SOT_BW_SEND_MESSAGE:
pSO?.Send(primitive, pFrom);
return true;
default:
Logger.FATAL("SO primitive not allowed here");
return false;
}
}
示例14: TestConstruction
public void TestConstruction()
{
TestObject1 obj1 = new TestObject1("some value");
Variant v1 = new Variant(obj1);
Assert.AreEqual(v1.Type, Variant.EnumType.Object);
TestObject1 obj2 = v1.AsObject<TestObject1>();
Assert.AreEqual(obj1, obj2);
Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); });
Assert.Throws<VariantException>(delegate { v1.AsObject<VariantObjectProxy>(); });
VariantObjectProxy obj3 = new VariantObjectProxy(obj1.Class);
obj3.Inflate(obj2.Deflate(), obj2.Version);
Assert.AreEqual(obj3.Class, "TestObject1");
Assert.AreEqual(obj3.Version, 1);
Assert.AreEqual(obj3.Deflate().Type, Variant.EnumType.Dictionary);
Variant v2 = new Variant(obj3);
Assert.IsInstanceOf<VariantObjectProxy>(v2.AsObject());
Assert.Throws<VariantException>(delegate { v1.AsObject<TestObject2>(); });
TestObject1 obj5 = v2.AsObject<TestObject1>();
Assert.AreEqual(obj5.Class, "TestObject1");
Assert.AreEqual(obj5.Version, 1);
Assert.IsInstanceOf<TestObject1>(v2.AsObject());
}
示例15: TestBasic
public void TestBasic()
{
Variant v = new Variant(new byte[] { 0x01, 0x02, 0x03 });
Assert.AreEqual(v.Type, Variant.EnumType.Buffer);
Assert.IsTrue(v.Is(Variant.EnumType.Buffer));
Assert.IsTrue(SequenceComparer.Compare(v.AsBuffer(), new byte[] { 0x01, 0x02, 0x03 })==0);
}