本文整理汇总了C#中System.Variant.AsObject方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.AsObject方法的具体用法?C# Variant.AsObject怎么用?C# Variant.AsObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Variant
的用法示例。
在下文中一共展示了Variant.AsObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteElement
//.........这里部分代码省略.........
WriteAttributes(m_stack.Peek().m_attributes);
foreach(VariantItem item in element)
{
Push();
WriteVariant(item.Value);
Pop();
}
break;
}
case VariantBase.EnumType.TimeSeries:
{
WriteAttributes(m_stack.Peek().m_attributes);
foreach(VariantItem item in element)
{
Push().Add("time", new Variant(item.Time));
WriteVariant(item.Value);
Pop();
}
break;
}
case VariantBase.EnumType.Buffer:
{
WriteAttributes(m_stack.Peek().m_attributes);
m_writer.WriteBase64(element.AsBuffer(), 0, element.AsBuffer().Length);
break;
}
case VariantBase.EnumType.Object:
{
IVariantObject obj = element.AsObject();
// write class name
m_stack.Peek().m_attributes.Add("class", new Variant(obj.Class));
m_stack.Peek().m_attributes.Add("version", new Variant(obj.Version));
WriteAttributes(m_stack.Peek().m_attributes);
// write parameter dictionary
Push("params");
WriteVariant(obj.Deflate());
Pop();
break;
}
case VariantBase.EnumType.Exception:
{
WriteAttributes(m_stack.Peek().m_attributes);
VariantExceptionInfo e = element.AsException();
Push("type");
WriteElement(new Variant(e.Class));
Pop();
Push("message");
WriteElement(new Variant(e.Message));
Pop();
if (e.Source.Length!=0)
{
Push("source");
WriteElement(new Variant(e.Source));
示例2: WriteVariant
protected void WriteVariant(Variant v)
{
VariantBase.EnumType type = v.Type;
Write((Int32)type);
switch (type)
{
case VariantBase.EnumType.None:
break;
case VariantBase.EnumType.String:
case VariantBase.EnumType.Any:
Write(v.As<string>());
break;
case VariantBase.EnumType.Float:
Write(v.As<float>());
break;
case VariantBase.EnumType.Double:
Write(v.As<double>());
break;
case VariantBase.EnumType.Int32:
Write(v.As<Int32>());
break;
case VariantBase.EnumType.UInt32:
Write(v.As<UInt32>());
break;
case VariantBase.EnumType.Int64:
Write(v.As<Int64>());
break;
case VariantBase.EnumType.UInt64:
Write(v.As<UInt64>());
break;
case VariantBase.EnumType.Boolean:
Write(v.As<bool>());
break;
case VariantBase.EnumType.Time:
Write(v.As<TimeSpan>());
break;
case VariantBase.EnumType.DateTime:
Write(v.As<DateTime>());
break;
case VariantBase.EnumType.List:
case VariantBase.EnumType.Tuple:
Write(v.Count);
foreach (VariantItem item in v)
{
WriteVariant(item.Value);
}
break;
case VariantBase.EnumType.Dictionary:
case VariantBase.EnumType.Bag:
Write(v.Count);
foreach (VariantItem item in v)
{
Write(item.Key);
WriteVariant(item.Value);
}
break;
case VariantBase.EnumType.TimeSeries:
Write(v.Count);
foreach (VariantItem item in v)
{
Write(item.Time);
WriteVariant(item.Value);
}
break;
case VariantBase.EnumType.Object:
IVariantObject o = v.AsObject();
Write(o.Class);
Write(o.Version);
WriteVariant(o.Deflate());
break;
case VariantBase.EnumType.Exception:
VariantExceptionInfo x = v.AsException();
Write(x.Class);
Write(x.Message);
Write(x.Source);
Write(x.Stack);
break;
case VariantBase.EnumType.Buffer:
Write(v.AsBuffer().Length);
Write(v.AsBuffer(), true);
break;
case VariantBase.EnumType.DataTable:
Write(v.AsDataTable());
break;
case VariantBase.EnumType.Array:
Write(v.AsArray());
break;
default:
throw new VariantException("Case exhaustion: " + type.ToString());
}
}