public ExtensionObject ReadExtensionObject(string fieldName)
{
object token = null;
if (!ReadField(fieldName, out token))
{
return null;
}
var value = token as Dictionary<string, object>;
if (value == null)
{
return null;
}
try
{
m_stack.Push(value);
NodeId typeId = ReadNodeId("TypeId");
ExpandedNodeId absoluteId = NodeId.ToExpandedNodeId(typeId, m_context.NamespaceUris);
if (!NodeId.IsNull(typeId) && NodeId.IsNull(absoluteId))
{
Utils.Trace("Cannot de-serialized extension objects if the NamespaceUri is not in the NamespaceTable: Type = {0}", typeId);
}
Type systemType = m_context.Factory.GetSystemType(typeId);
if (systemType != null)
{
var encodeable = ReadEncodeable("Object", systemType);
return new ExtensionObject(typeId, encodeable);
}
if (value.ContainsKey("Binary"))
{
var bytes = ReadByteString("Binary");
return new ExtensionObject(typeId, bytes);
}
if (value.ContainsKey("Xml"))
{
var xml = ReadXmlElement("Xml");
return new ExtensionObject(typeId, xml);
}
return new ExtensionObject();
}
finally
{
m_stack.Pop();
}
}