29 using System.Collections;
31 using System.Reflection;
34 namespace OpenSim.Framework.Capabilities
43 StringWriter sw =
new StringWriter();
44 XmlTextWriter writer =
new XmlTextWriter(sw);
45 writer.Formatting = Formatting.None;
46 writer.WriteStartElement(String.Empty,
"llsd", String.Empty);
47 SerializeOSDType(writer, obj);
48 writer.WriteEndElement();
56 private static void SerializeOSDType(XmlTextWriter writer,
object obj)
58 Type myType = obj.GetType();
60 if (llsdattributes.Length > 0)
62 switch (llsdattributes[0].ObjectType)
65 writer.WriteStartElement(String.Empty,
"map", String.Empty);
66 FieldInfo[] fields = myType.GetFields();
67 for (
int i = 0; i < fields.Length; i++)
69 if (fields[i] != null && fields[i].GetValue(obj) != null)
71 object fieldValue = fields[i].GetValue(obj);
73 (
LLSDType[]) fieldValue.GetType().GetCustomAttributes(typeof (
LLSDType),
false);
74 if (fieldAttributes.Length > 0)
76 writer.WriteStartElement(String.Empty,
"key", String.Empty);
77 string fieldName = fields[i].Name;
78 fieldName = fieldName.Replace(
"___",
"-");
79 writer.WriteString(fieldName);
80 writer.WriteEndElement();
81 SerializeOSDType(writer, fieldValue);
85 writer.WriteStartElement(String.Empty,
"key", String.Empty);
86 string fieldName = fields[i].Name;
87 fieldName = fieldName.Replace(
"___",
"-");
88 writer.WriteString(fieldName);
89 writer.WriteEndElement();
90 LLSD.LLSDWriteOne(writer, fieldValue);
102 writer.WriteEndElement();
107 ArrayList a = (ArrayList) obj.GetType().GetField(
"Array").GetValue(obj);
110 writer.WriteStartElement(String.Empty,
"array", String.Empty);
111 foreach (
object item
in a)
113 SerializeOSDType(writer, item);
115 writer.WriteEndElement();
122 LLSD.LLSDWriteOne(writer, obj);
130 Type myType = obj.GetType();
132 if (llsdattributes.Length > 0)
134 switch (llsdattributes[0].ObjectType)
137 IDictionaryEnumerator enumerator = llsd.GetEnumerator();
138 while (enumerator.MoveNext())
140 string keyName = (string)enumerator.Key;
141 keyName = keyName.Replace(
"-",
"_");
142 FieldInfo field = myType.GetField(keyName);
146 if (enumerator.Value is Hashtable)
148 object fieldValue = field.GetValue(obj);
149 DeserialiseOSDMap((Hashtable) enumerator.Value, fieldValue);
152 else if (enumerator.Value is ArrayList)
154 object fieldValue = field.GetValue(obj);
155 fieldValue.GetType().GetField(
"Array").SetValue(fieldValue, enumerator.Value);
162 field.SetValue(obj, enumerator.Value);
static object DeserialiseOSDMap(Hashtable llsd, object obj)
static string SerialiseLLSDReply(object obj)