public DeserializeResult DeserializeProperty(SerializationToken serializationToken, PropertyInfo property) { if (serializationToken.Type == null) { return new DeserializeResult { Use = false } } ; if (serializationToken.TokenType == SerializationTokenType.Null) { return(new DeserializeResult()); } if (_reverseTokens.ContainsKey(serializationToken)) { return new DeserializeResult { Result = _reverseTokens[serializationToken] } } ; DeserializeResult result = new DeserializeResult(); ISerializerToken serializerToken = null; if (property != null) { ConverterAttribute converterAttribute = property.GetCustomAttribute <ConverterAttribute>(); if (converterAttribute != null) { serializerToken = (ISerializerToken)Activator.CreateInstance(converterAttribute.SerializerTokenType); } } if (serializerToken == null) { serializerToken = Resolve(serializationToken.Type); } serializerToken.Deserialize(serializationToken, this, result); if (result.Use) { _reverseTokens[serializationToken] = result.Result; } return(result); }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { object graph; try { graph = Activator.CreateInstance(serializationToken.Type); } catch (Exception e) { deserializeResult.Result = null; deserializeResult.Use = false; return; } serializerToken.RegisterReverseToken(serializationToken, graph); for (int i = 0; i < serializationToken.SerializationTokens.Length / 2; i++) { string propertyName = (string)serializerToken.Deserialize(serializationToken.SerializationTokens[2 * i]).Result; PropertyInfo propertyInfo = serializationToken.Type.GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (propertyInfo != null && propertyInfo.CanRead && propertyInfo.CanWrite && propertyInfo.GetIndexParameters().Length == 0) { DeserializeResult dResult = serializerToken.DeserializeProperty(serializationToken.SerializationTokens[2 * i + 1], propertyInfo); if (dResult.Use) { try { propertyInfo.SetValue(graph, dResult.Result, new object[0]); } catch (Exception) { // ignored } } } } deserializeResult.Result = graph; }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { Array array = Array.CreateInstance(serializationToken.Type.GetElementType(), serializationToken.SerializationTokens.Length); serializerToken.RegisterReverseToken(serializationToken, array); for (int i = 0; i < serializationToken.SerializationTokens.Length; i++) { DeserializeResult dResult = serializerToken.Deserialize(serializationToken.SerializationTokens[i]); if (dResult.Use) { try { array.SetValue(dResult.Result, i); } catch (Exception) { // ignored } } } deserializeResult.Result = array; }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { IDictionary dictionary = (IDictionary)Activator.CreateInstance(serializationToken.Type); serializerToken.RegisterReverseToken(serializationToken, dictionary); for (int i = 0; i < serializationToken.SerializationTokens.Length / 2; i++) { DeserializeResult key = serializerToken.Deserialize(serializationToken.SerializationTokens[2 * i]); DeserializeResult value = serializerToken.Deserialize(serializationToken.SerializationTokens[2 * i + 1]); if (key.Use && key.Result != null && !dictionary.Contains(key.Result) && value.Use) { try { dictionary.Add(key.Result, value.Result); } catch (Exception) { // ignored } } } deserializeResult.Result = dictionary; }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { Type parentIListType = GetParentTypes(serializationToken.Type) .First(type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IList <>)); MethodInfo insertMethod = parentIListType.GetMethod("Insert"); object list = Activator.CreateInstance(serializationToken.Type); serializerToken.RegisterReverseToken(serializationToken, list); for (int i = 0; i < serializationToken.SerializationTokens.Length; i++) { DeserializeResult dResult = serializerToken.Deserialize(serializationToken.SerializationTokens[i]); if (dResult.Use) { insertMethod.Invoke(list, new[] { i, dResult.Result }); } else { Type elementType = parentIListType.GetGenericArguments().First(); insertMethod.Invoke(list, new[] { i, elementType.GetDefault() }); } } deserializeResult.Result = list; }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { Type result = null; try { result = Type.GetType((string)serializationToken.Data); } catch (Exception) { // ignored } if (result == null) { deserializeResult.Use = false; } deserializeResult.Result = result; }
public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken, DeserializeResult deserializeResult) { deserializeResult.Result = serializationToken.Data; }