Beispiel #1
0
        }         // proc WriteXml

        public static void WriteObject(this IDEContext context, object value, string contentType = null)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            else if (value is XElement)
            {
                WriteXml(context, (XElement)value, contentType ?? MimeTypes.Text.Xml);
            }
            else if (value is XDocument)
            {
                WriteXml(context, (XDocument)value, contentType ?? MimeTypes.Text.Xml);
            }
            else if (value is string)
            {
                WriteText(context, (string)value, contentType ?? MimeTypes.Text.Plain);
            }
            else if (value is Stream)
            {
                WriteStream(context, (Stream)value, contentType ?? MimeTypes.Application.OctetStream);
            }
            else if (value is byte[])
            {
                WriteBytes(context, (byte[])value, contentType ?? MimeTypes.Application.OctetStream);
            }
            else if (value is LuaTable)
            {
                WriteXml(context, new XDocument(Procs.ToXml((LuaTable)value)));
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest, String.Format("Can not send return value of type '{0}'.", value.GetType().FullName));
            }
        }         // proc WriteObject