本文整理汇总了C#中OSD.AsString方法的典型用法代码示例。如果您正苦于以下问题:C# OSD.AsString方法的具体用法?C# OSD.AsString怎么用?C# OSD.AsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSD
的用法示例。
在下文中一共展示了OSD.AsString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
case OSDType.UUID:
return new JsonData(osd.AsString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}
示例2: SerializeLisp
public static object SerializeLisp(OSD osd)
{
switch (osd.Type)
{
case OSDType.Unknown:
throw new InvalidCastException();
case OSDType.Boolean:
return osd.AsBoolean();
case OSDType.Integer:
return osd.AsInteger();
case OSDType.Real:
return osd.AsReal();
case OSDType.String:
return osd.AsString();
case OSDType.Date:
return osd.AsDate();
case OSDType.URI:
return osd.AsUri();
case OSDType.UUID:
return osd.AsUUID();
case OSDType.Binary:
return osd.AsBinary();
case OSDType.Array:
OSDArray args = (OSDArray) osd;
Cons ret = null;
for (int i = args.Count - 1; i >= 0; --i)
{
ret = new Cons(args[i], ret);
}
return ret;
case OSDType.Map:
Cons list = null;
OSDMap map = (OSDMap) osd;
foreach (KeyValuePair<string, OSD> kvp in map)
{
Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
list = new Cons(kv,list);
}
return Cons.Reverse(list);
default:
return osd;
}
}
示例3: osdToObject
private Object osdToObject(OSD decoded)
{
if ( decoded is OSDString ) {
return (string) decoded.AsString();
} else if ( decoded is OSDInteger ) {
return (int) decoded.AsInteger();
} else if ( decoded is OSDReal ) {
return (float) decoded.AsReal();
} else if ( decoded is OSDBoolean ) {
return (bool) decoded.AsBoolean();
} else if ( decoded is OSDMap ) {
return osdToHashtable((OSDMap) decoded);
} else if ( decoded is OSDArray ) {
return osdToArray((OSDArray) decoded);
} else {
return null;
}
}
示例4: SerializeLLSDXmlElement
/// <summary>
///
/// </summary>
/// <param name="writer"></param>
/// <param name="data"></param>
public static void SerializeLLSDXmlElement(XmlTextWriter writer, OSD data)
{
switch (data.Type)
{
case OSDType.Unknown:
writer.WriteStartElement(String.Empty, "undef", String.Empty);
writer.WriteEndElement();
break;
case OSDType.Boolean:
writer.WriteStartElement(String.Empty, "boolean", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Integer:
writer.WriteStartElement(String.Empty, "integer", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Real:
writer.WriteStartElement(String.Empty, "real", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.String:
writer.WriteStartElement(String.Empty, "string", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Guid:
writer.WriteStartElement(String.Empty, "Guid", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Date:
writer.WriteStartElement(String.Empty, "date", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.URI:
writer.WriteStartElement(String.Empty, "uri", String.Empty);
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Binary:
writer.WriteStartElement(String.Empty, "binary", String.Empty);
writer.WriteStartAttribute(String.Empty, "encoding", String.Empty);
writer.WriteString("base64");
writer.WriteEndAttribute();
writer.WriteString(data.AsString());
writer.WriteEndElement();
break;
case OSDType.Map:
OSDMap map = (OSDMap)data;
writer.WriteStartElement(String.Empty, "map", String.Empty);
foreach (KeyValuePair<string, OSD> kvp in map)
{
writer.WriteStartElement(String.Empty, "key", String.Empty);
writer.WriteString(kvp.Key);
writer.WriteEndElement();
SerializeLLSDXmlElement(writer, kvp.Value);
}
writer.WriteEndElement();
break;
case OSDType.Array:
OSDArray array = (OSDArray)data;
writer.WriteStartElement(String.Empty, "array", String.Empty);
for (int i = 0; i < array.Count; i++)
{
SerializeLLSDXmlElement(writer, array[i]);
}
writer.WriteEndElement();
break;
}
}
示例5: SerializeLLSDNotationElementFormatted
private static void SerializeLLSDNotationElementFormatted(StringWriter writer, string indent, OSD osd)
{
switch (osd.Type)
{
case OSDType.Unknown:
writer.Write(undefNotationValue);
break;
case OSDType.Boolean:
if (osd.AsBoolean())
writer.Write(trueNotationValueTwo);
else
writer.Write(falseNotationValueTwo);
break;
case OSDType.Integer:
writer.Write(integerNotationMarker);
writer.Write(osd.AsString());
break;
case OSDType.Real:
writer.Write(realNotationMarker);
writer.Write(osd.AsString());
break;
case OSDType.UUID:
writer.Write(uuidNotationMarker);
writer.Write(osd.AsString());
break;
case OSDType.String:
writer.Write(singleQuotesNotationMarker);
writer.Write(EscapeCharacter(osd.AsString(), singleQuotesNotationMarker));
writer.Write(singleQuotesNotationMarker);
break;
case OSDType.Binary:
writer.Write(binaryNotationMarker);
writer.Write("64");
writer.Write(doubleQuotesNotationMarker);
writer.Write(osd.AsString());
writer.Write(doubleQuotesNotationMarker);
break;
case OSDType.Date:
writer.Write(dateNotationMarker);
writer.Write(doubleQuotesNotationMarker);
writer.Write(osd.AsString());
writer.Write(doubleQuotesNotationMarker);
break;
case OSDType.URI:
writer.Write(uriNotationMarker);
writer.Write(doubleQuotesNotationMarker);
writer.Write(EscapeCharacter(osd.AsString(), doubleQuotesNotationMarker));
writer.Write(doubleQuotesNotationMarker);
break;
case OSDType.Array:
SerializeLLSDNotationArrayFormatted(writer, indent + baseIndent, (OSDArray)osd);
break;
case OSDType.Map:
SerializeLLSDNotationMapFormatted(writer, indent + baseIndent, (OSDMap)osd);
break;
default:
throw new OSDException("Notation serialization: Not existing element discovered.");
}
}
示例6: ConvertOutputValue
// -----------------------------------------------------------------
/// <summary>
///
/// </summary>
// -----------------------------------------------------------------
protected static bool ConvertOutputValue(OSD result, out string value, bool useJson)
{
value = String.Empty;
// If we couldn't process the path
if (result == null)
return false;
if (useJson)
{
// The path pointed to an intermediate hash structure
if (result.Type == OSDType.Map)
{
value = OSDParser.SerializeJsonString(result as OSDMap,true);
return true;
}
// The path pointed to an intermediate hash structure
if (result.Type == OSDType.Array)
{
value = OSDParser.SerializeJsonString(result as OSDArray,true);
return true;
}
value = "'" + result.AsString() + "'";
return true;
}
if (OSDBaseType(result.Type))
{
value = result.AsString();
return true;
}
return false;
}
示例7: SerializeJsonNoDefaults
private static JsonData SerializeJsonNoDefaults(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
bool b = osd.AsBoolean();
if (!b)
return null;
return new JsonData(b);
case OSDType.Integer:
int v = osd.AsInteger();
if (v == 0)
return null;
return new JsonData(v);
case OSDType.Real:
double d = osd.AsReal();
if (d == 0.0d)
return null;
return new JsonData(d);
case OSDType.String:
case OSDType.Date:
case OSDType.URI:
string str = osd.AsString();
if (String.IsNullOrEmpty(str))
return null;
return new JsonData(str);
case OSDType.UUID:
UUID uuid = osd.AsUUID();
if (uuid == UUID.Zero)
return null;
return new JsonData(uuid.ToString());
case OSDType.Binary:
byte[] binary = osd.AsBinary();
if (binary == Utils.EmptyBytes)
return null;
JsonData jsonbinarray = new JsonData();
jsonbinarray.SetJsonType(JsonType.Array);
for (int i = 0; i < binary.Length; i++)
jsonbinarray.Add(new JsonData(binary[i]));
return jsonbinarray;
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
{
JsonData data = SerializeJsonNoDefaults(kvp.Value);
if (data != null)
jsonmap[kvp.Key] = data;
}
return jsonmap;
case OSDType.Unknown:
default:
return null;
}
}
示例8: SerializeJson
public static JsonData SerializeJson(OSD osd)
{
switch (osd.Type)
{
case OSDType.Boolean:
return new JsonData(osd.AsBoolean());
case OSDType.Integer:
return new JsonData(osd.AsInteger());
case OSDType.Real:
return new JsonData(osd.AsReal());
case OSDType.String:
return new JsonData(osd.AsString());
case OSDType.Date:
return new JsonData("date::" + osd.AsString());
case OSDType.URI:
return new JsonData("uri::" + osd.AsString());
case OSDType.UUID:
return new JsonData("uuid::" + osd.AsString());
case OSDType.Binary:
return new JsonData("b64::" + Convert.ToBase64String(osd.AsBinary()));
case OSDType.Array:
JsonData jsonarray = new JsonData();
jsonarray.SetJsonType(JsonType.Array);
OSDArray array = (OSDArray)osd;
for (int i = 0; i < array.Count; i++)
jsonarray.Add(SerializeJson(array[i]));
return jsonarray;
case OSDType.Map:
JsonData jsonmap = new JsonData();
jsonmap.SetJsonType(JsonType.Object);
OSDMap map = (OSDMap)osd;
foreach (KeyValuePair<string, OSD> kvp in map)
jsonmap[kvp.Key] = SerializeJson(kvp.Value);
return jsonmap;
case OSDType.Unknown:
default:
return new JsonData();
}
}
示例9: ParseJsonNode
private object ParseJsonNode(OSD node)
{
if (node.Type == OSDType.Integer)
return new LSL_Integer(node.AsInteger());
if (node.Type == OSDType.Boolean)
return new LSL_Integer(node.AsBoolean() ? 1 : 0);
if (node.Type == OSDType.Real)
return new LSL_Float(node.AsReal());
if (node.Type == OSDType.UUID || node.Type == OSDType.String)
return new LSL_String(node.AsString());
if (node.Type == OSDType.Array)
{
LSL_List resp = new LSL_List();
OSDArray ar = node as OSDArray;
foreach (OSD o in ar)
resp.Add(ParseJsonNode(o));
return resp;
}
if (node.Type == OSDType.Map)
{
LSL_List resp = new LSL_List();
OSDMap ar = node as OSDMap;
foreach (KeyValuePair<string, OSD> o in ar)
{
resp.Add(new LSL_String(o.Key));
resp.Add(ParseJsonNode(o.Value));
}
return resp;
}
throw new Exception(ScriptBaseClass.JSON_INVALID);
}