protected override object ReadObjectBody(DataType dataType) { DataNode result = null; if (dataType.IsPrimitiveType()) { result = new PrimitiveNode(dataType, this.ReadPrimitive(dataType)); } else if (dataType == DataType.String) { result = new StringNode(this.ReadString()); } else if (dataType == DataType.Enum) { result = this.ReadEnum(); } else if (dataType == DataType.Struct) { result = this.ReadStruct(false); } else if (dataType == DataType.ObjectRef) { result = this.ReadObjectRef(); } else if (dataType == DataType.Array) { result = this.ReadArray(); } else if (dataType == DataType.Class) { result = this.ReadStruct(true); } else if (dataType == DataType.Delegate) { result = this.ReadDelegate(); } else if (dataType.IsMemberInfoType()) { result = this.ReadMemberInfo(dataType); } return(result); }
public PrimitiveTreeNode(PrimitiveNode data) : base(data) { this.primitiveData = data; }
protected override object ReadObjectBody(DataType dataType) { DataNode result = null; if (dataType.IsPrimitiveType()) result = new PrimitiveNode(dataType, this.ReadPrimitive(dataType)); else if (dataType == DataType.String) result = new StringNode(this.reader.ReadString()); else if (dataType == DataType.Enum) result = this.ReadEnum(); else if (dataType == DataType.Struct) result = this.ReadStruct(false); else if (dataType == DataType.ObjectRef) result = this.ReadObjectRef(); else if (dataType == DataType.Array) result = this.ReadArray(); else if (dataType == DataType.Class) result = this.ReadStruct(true); else if (dataType == DataType.Delegate) result = this.ReadDelegate(); else if (dataType.IsMemberInfoType()) result = this.ReadMemberInfo(dataType); return result; }
/// <summary> /// Reads an <see cref="Duality.Serialization.MetaFormat.ArrayNode"/>, including possible child nodes. /// </summary> /// <param name="node"></param> protected ArrayNode ReadArray() { string arrTypeString = this.reader.GetAttribute("type"); string objIdString = this.reader.GetAttribute("id"); string arrRankString = this.reader.GetAttribute("rank"); string arrLengthString = this.reader.GetAttribute("length"); uint objId = objIdString == null ? 0 : XmlConvert.ToUInt32(objIdString); int arrRank = arrRankString == null ? 1 : XmlConvert.ToInt32(arrRankString); int arrLength = arrLengthString == null ? 0 : XmlConvert.ToInt32(arrLengthString); Type arrType = ReflectionHelper.ResolveType(arrTypeString, false); ArrayNode result = new ArrayNode(arrTypeString, objId, arrRank, arrLength); // Prepare object reference this.idManager.Inject(result, objId); // Store primitive data block bool nonPrimitive; if (arrType != null) { Array arrObj = Array.CreateInstance(arrType.GetElementType(), arrLength); if (arrObj is bool[] || arrObj is byte[] || arrObj is sbyte[] || arrObj is short[] || arrObj is ushort[] || arrObj is int[] || arrObj is uint[] || arrObj is long[] || arrObj is ulong[] || arrObj is float[] || arrObj is double[] || arrObj is decimal[] || arrObj is char[] || arrObj is string[]) { nonPrimitive = false; } else { nonPrimitive = true; } if (!nonPrimitive) { if (arrObj is byte[]) { byte[] byteArr = arrObj as byte[]; string binHexString = this.reader.ReadString(); byte[] byteArr2 = this.StringToByteArray(binHexString); for (int l = 0; l < arrLength; l++) { byteArr[l] = byteArr2[l]; } } else { for (int l = 0; l < arrLength; l++) { PrimitiveNode elemNode = this.ReadObject() as PrimitiveNode; if (arrObj != null) { arrObj.SetValue(elemNode.PrimitiveValue, l); } } } result.PrimitiveData = arrObj; } } else { nonPrimitive = true; } // Store other data as sub-nodes if (nonPrimitive) { for (int i = 0; i < arrLength; i++) { DataNode child = this.ReadObject() as DataNode; child.Parent = result; } } return(result); }