예제 #1
0
        /// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult" /> class.
        /// </summary>
        /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;

            response.ContentType     = "text/xml";
            response.ContentEncoding = this.Encoding;

            var ser = XmlSerializationBuilder.Build <T>().Create();

            ser.Serialize(context.HttpContext.Response.OutputStream, this.Data);
        }
예제 #2
0
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="section">Section XML node.</param>
        /// <returns>
        /// The created section handler object.
        /// </returns>
        /// <exception cref="System.ArgumentException">Unknown Xml Node Type</exception>
        /// <ignore>true</ignore>
        public static T CreateConfigurationInstanceFromConfigurationNode <T> (this XmlNode section)
        {
            // the node has to be an xml element.
            if (!section.Is <XmlElement> ( ))
            {
                throw new ArgumentException(Resources.XmlNode_UnknownNodeType);
            }
            var serializer = XmlSerializationBuilder.Build <T> ( ).Create( );
            var doc        = new XmlDocument( );
            var ele        = (XmlElement)doc.ImportNode(section, true);

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
            doc.AppendChild(ele);
            using (var ms = new MemoryStream( )) {
                doc.Save(ms);
                ms.Position = 0;
                return((T)serializer.Deserialize(ms));
            }
        }