/// <summary> /// Parse an object from <paramref name="r"/> using the type hint <paramref name="t"/> /// </summary> /// <param name="r">The reader to read from</param> /// <param name="t">The type hint for the formatter</param> /// <returns>A structured result</returns> public IFormatterParseResult Parse(XmlReader r, Type t) { // Get the struct attribute IDatatypeFormatter formatter = null; Type cType = t; //if (formatter != null && t != typeof(GTS) && formatter.GenericArguments == null ) // formatter.GenericArguments = t.GetGenericArguments(); if (t.GetInterface(typeof(IEnumerable).FullName) != null && !t.IsAbstract) { formatter = GetFormatter(t); } else { // Force processing as an XSI:Type if (r.GetAttribute("type", NS_XSI) != null) { cType = Util.ParseXSITypeName(r.GetAttribute("type", NS_XSI)); } formatter = GetFormatter(cType); } if (formatter == null) { return(null); } // Set host and parse DatatypeR2FormatterParseResult result = new DatatypeR2FormatterParseResult(ResultCode.Accepted, null, this.ValidateConformance); formatter.Host = (IXmlStructureFormatter)(this.Host ?? this); // Structure graph var structure = formatter.Parse(r, result); object retVal = null; if (!Util.TryFromWireFormat(structure, cType, out retVal)) { retVal = structure as IGraphable; //, cType) as IGraphable; } // Set the return structure result.Structure = retVal as IGraphable; return(result); }
/// <summary> /// Parse an object from <paramref name="r"/> using the type hint <paramref name="t"/> /// </summary> /// <param name="r">The reader to read from</param> /// <param name="t">The type hint for the formatter</param> /// <returns>A structured result</returns> public IFormatterParseResult Parse(XmlReader r, Type t) { // Get the struct attribute IDatatypeFormatter formatter = null; Type cType = t; //if (formatter != null && t != typeof(GTS) && formatter.GenericArguments == null ) // formatter.GenericArguments = t.GetGenericArguments(); if (t.GetInterface(typeof(IEnumerable).FullName) != null && !t.IsAbstract) formatter = GetFormatter(t); else { // Force processing as an XSI:Type if (r.GetAttribute("type", NS_XSI) != null) cType = Util.ParseXSITypeName(r.GetAttribute("type", NS_XSI)); formatter = GetFormatter(cType); } if (formatter == null) return null; // Set host and parse DatatypeR2FormatterParseResult result = new DatatypeR2FormatterParseResult(ResultCode.Accepted, null, this.ValidateConformance); formatter.Host = (IXmlStructureFormatter)(this.Host ?? this); // Structure graph var structure = formatter.Parse(r, result); object retVal = null; if (!Util.TryFromWireFormat(structure, cType, out retVal)) retVal = structure as IGraphable; //, cType) as IGraphable; // Set the return structure result.Structure = retVal as IGraphable; return result; }