public object DeserializeObject(IDataAdapter data, ISubDeserializer subDeserializer) { string a = data.GetStringValue("someData", true); CustomSerializationClass obj = new CustomSerializationClass(a); obj.B = (NanoState)Enum.Parse(typeof(NanoState), data.GetStringValue("someOtherData", true)); return(obj); }
private static void ScanArrayRanks(IDataAdapter data, Type elementType, int[] lengths, int index) { if (index == lengths.Length - 1 && elementType.IsPrimitive) { string value = data.GetStringValue(); lengths[index] = ByteUtils.GetBytesInBase64(value) / ByteUtils.GetSizeOf(elementType); return; } int count = 0; IDataAdapter firstChild = null; foreach (IDataAdapter e in data.GetArray().GetChildren()) { if (firstChild == null) { firstChild = e; } count++; } lengths[index] = count; if (index < lengths.Length - 1) { ScanArrayRanks(firstChild, elementType, lengths, index + 1); } }
private void DeserializeContainer(ref object container, Type type, Type elementType, IDataAdapter data, string addMethodName, bool reverse = false) { if (container == null) { container = TypeCache.CreateParameterless(type); } Action <object, object> addAction = null; if (!TypeCache.TryGetTypeAccessor(type, ref addAction)) { addAction = InvocationHelper.CreateSetDelegate(type, elementType, addMethodName); TypeCache.AddTypeAccessor(type, addAction); } if (elementType.IsPrimitive) { byte[] buffer = Convert.FromBase64String(data.GetStringValue()); int size = ByteUtils.GetSizeOf(elementType); int count = buffer.Length / size; Func <byte[], int, object> reader = ByteUtils.GetBinaryReader(elementType); if (reverse) { for (int i = count - 1; i >= 0; i--) { addAction(container, reader(buffer, size * i)); } } else { for (int i = 0; i < count; i++) { addAction(container, reader(buffer, size * i)); } } return; } IDataArray array = data.GetArray(); if (reverse) { foreach (IDataAdapter element in array.GetChildrenReversed()) { addAction(container, DeserializeObject(elementType, element, null)); } } else { foreach (IDataAdapter element in array.GetChildren()) { addAction(container, DeserializeObject(elementType, element, null)); } } }
void INanoSerializable.Deserialize(IDataAdapter data, ISubDeserializer subDeserializer) { A = data.GetStringValue("1", true); object b = null; subDeserializer.ContinueDeserialization(typeof(object), data.GetChild("1").GetChild("2"), ref b); B = b; }
protected static object DeserializePrimitive(Type type, IDataAdapter data, string name, bool isAttribute, bool enumAsValue) { Func <IDataAdapter, string, bool, object> func; if (primitiveNamedDeserializers.TryGetValue(type, out func)) { return(func(data, name, isAttribute)); } if (type.IsEnum) { if (enumAsValue) { return(Enum.ToObject(type, data.GetIntValue(name, isAttribute))); } return(Enum.Parse(type, data.GetStringValue(name, isAttribute))); } return(null); }
private void DeserializeArrayRank(Array array, Type elementType, int[] coords, int r, IDataAdapter data) { if (r == coords.Length - 1) { if (elementType.IsPrimitive) { byte[] buffer = Convert.FromBase64String(data.GetStringValue()); int size = ByteUtils.GetSizeOf(elementType); int count = array.GetLength(r); Func <byte[], int, object> reader = ByteUtils.GetBinaryReader(elementType); for (int i = 0; i < count; i++) { coords[r] = i; array.SetValue(reader(buffer, i * size), coords); } } else { int index = 0; foreach (IDataAdapter element in data.GetArray().GetChildren()) { coords[r] = index++; array.SetValue(DeserializeObject(elementType, element, null), coords); } } } else { int index = 0; foreach (IDataAdapter element in data.GetArray().GetChildren()) { coords[r] = index++; DeserializeArrayRank(array, elementType, coords, r + 1, element); } } }