/// <summary> /// code originally in method ParseConstantFromElement(XElement xml, string elemName, Type expectedType) /// </summary> /// <param name="x"></param> /// <param name="e"></param> /// <returns></returns> public override bool TryDeserialize(XElement x, out Expression e) { if (x.Name.LocalName == typeof(ConstantExpression).Name) { var serializedType = resolver.GetType(x.Element("Type").Value); if (resolver.HasMappedKnownType(serializedType)) { var xml = x.Element("Value").Value; DataContractSerializer dserializer; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { //if (typeof(IQueryable).IsAssignableFrom(expectedType) && IsIEnumerableOf(expectedType, knownType)) //{ // dserializer = new DataContractSerializer(knownType.MakeArrayType(), this.resolver.knownTypes); // result = dserializer.ReadObject(ms); // result = Enumerable.ToArray(result); //} dserializer = new DataContractSerializer(serializedType, resolver.knownTypes); var instance = dserializer.ReadObject(ms); e = Expression.Constant(instance); return(true); } } } e = null; return(false); }
/// <summary> ///code originally in method ParseConstantFromElement(XElement xml, string elemName, Type expectedType) /// </summary> /// <param name="x"></param> /// <param name="e"></param> /// <returns></returns> public override bool TryDeserialize(XElement x, out Expression e) { if (x.Name.LocalName == typeof(ConstantExpression).Name) { String typeName = x.Element("Type").Value; if (String.IsNullOrEmpty(typeName)) { //added by leilei,for EnumType typeName = ((XElement)(((XContainer)(x.Element("Type"))).FirstNode)).FirstAttribute.Value; // typeName = ((XElement)(((XElement)(x.Element("Type").NextNode)).FirstNode)).FirstAttribute.Value; } Type serializedType = resolver.GetType(typeName); if (resolver.HasMappedKnownType(serializedType)) { string xml = x.Element("Value").Value; DataContractSerializer dserializer; using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { //if (typeof(IQueryable).IsAssignableFrom(expectedType) && IsIEnumerableOf(expectedType, knownType)) //{ // dserializer = new DataContractSerializer(knownType.MakeArrayType(), this.resolver.knownTypes); // result = dserializer.ReadObject(ms); // result = Enumerable.ToArray(result); //} dserializer = new DataContractSerializer(serializedType, this.resolver.knownTypes); object instance = dserializer.ReadObject(ms); e = Expression.Constant(instance); return(true); } } } e = null; return(false); }