using Apewer; using Apewer.Internals; using Apewer.Source; using Apewer.Web; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.IO; using System.Reflection; using System.Text; using System.Collections.Specialized; #if !NET20 using System.Dynamic; #endif /// 扩展方法。 public static class Extensions { /// 是 NULL 值,或是 DBNULL 值。 public static bool IsNull(this object @this) => @this == null || @this.Equals(DBNull.Value); /// 不是 NULL 值,且不是 DBNULL 值。 public static bool NotNull(this object @this) => @this != null && !@this.Equals(DBNull.Value); /// 是默认值。 public static bool IsDefault(this object @this) => RuntimeUtility.IsDefault(@this); #region Class /// 装箱。 public static Class Class(this T value) => new Class(value); #endregion #region Class Utility /// 调用 Get 方法。 public static object Get(this PropertyInfo @this, object instance) => RuntimeUtility.InvokeGet(instance, @this); /// 调用 Set 方法。 public static void Set(this PropertyInfo @this, object instance, object value) => RuntimeUtility.InvokeSet(instance, @this, value); /// 调用 Get 方法。 public static T Get(this PropertyInfo @this, object instance) => RuntimeUtility.InvokeGet(instance, @this); /// 调用 Set 方法。 public static void Set(this PropertyInfo @this, object instance, T value) => RuntimeUtility.InvokeSet(instance, @this, value); /// 判断静态属性。 public static bool IsStatic(this PropertyInfo @this) => RuntimeUtility.IsStatic(@this); /// 以安全的方式获取消息内容,对无效的 Exception 返回 NULL 值。 public static string Message(this Exception ex) => RuntimeUtility.Message(ex); #if NET20 /// 为指定对象设置属性值。 /// 属性。 /// 要设置属性的对象。 /// 属性值。 /// public static void SetValue(this PropertyInfo property, object obj, object value) { if (property == null) throw new ArgumentNullException(nameof(property)); property.SetValue(obj, value, null); } #endif #endregion #region Dynamic #if !NET20 /// 转换 对象。 public static ExpandoObject Expando(this ObjectSet os) => ObjectSet.Expando(os); /// 转换 数组到 数组。 public static ExpandoObject[] Expando(this ObjectSet[] oss) => ObjectSet.Expando(oss); /// 设置 的 Always 属性,对动态属性的访问始终返回 TRUE 值。 public static void SetAlways(this ObjectSet os, bool always) => os._always = always; #endif #endregion #region Number /// 判断此值为零。 public static bool IsZero(this decimal @this) => @this.Equals(0M); /// 判断此值为零。 public static bool IsZero(this double @this) => @this.Equals(0D); /// 判断此值为零。 public static bool IsZero(this float @this) => @this.Equals(0F); /// 判断此值非零。 public static bool NotZero(this decimal @this) => !@this.Equals(0M); /// 判断此值非零。 public static bool NotZero(this double @this) => !@this.Equals(0D); /// 判断此值非零。 public static bool NotZero(this float @this) => !@this.Equals(0F); /// 约束值范围,若源值不在范围中,则修改为接近的值。 public static T Restrict(this T @this, T min, T max) where T : IComparable => NumberUtility.Restrict(@this, min, max); #endregion #region String、StringBuilder /// 转换文本为驼峰形式。 public static string Camel(this string @this) => TextUtility.Camel(@this); /// 转换为 Boolean 值。 public static bool Boolean(this string @this) => NumberUtility.Boolean(@this); /// 转换为 Byte 值。 public static byte Byte(this string @this) => NumberUtility.Byte(@this); /// 转换为 Int32 值。 public static int Int32(this string @this) => NumberUtility.Int32(@this); /// 转换为 Int64 值。 public static long Int64(this string @this) => NumberUtility.Int64(@this); /// 转换为 Decimal 值。 public static decimal Decimal(this string @this) => NumberUtility.Decimal(@this); /// 转换为单精度浮点值。 public static float Float(this string @this) => NumberUtility.Float(@this); /// 转换为双精度浮点值。 public static double Double(this string @this) => NumberUtility.Double(@this); /// 将文本转换为字节数组,默认使用 UTF-8。 public static byte[] Bytes(this string @this, Encoding encoding = null) => TextUtility.Bytes(@this, encoding); /// 验证字符串为 NULL、为空或仅含空白。 public static bool IsEmpty(this string @this) => TextUtility.IsEmpty(@this); /// 验证字符串为 NULL、为空或仅含空白。 public static bool NotEmpty(this string @this) => TextUtility.NotEmpty(@this); /// 验证字符串为 NULL、为空或无实际内容。 public static bool IsBlank(this string @this) => TextUtility.IsBlank(@this); /// 验证字符串含有实际内容。 public static bool NotBlank(this string @this) => TextUtility.NotBlank(@this); /// 用指定的分隔符拆分文本。 public static string[] Split(this string @this, string separator) => TextUtility.Split(@this, separator); /// 使用多个分隔符切分字符串,得到多个子字符串。 public static string[] Split(this string @this, params char[] separators) => TextUtility.Split(@this, separators); /// 返回此字符串的安全键副本。 public static string SafeKey(this string @this, int maxLength = 255) => TextUtility.SafeKey(@this, maxLength); /// 移除字符串前后的空字符。 /// trimBlank:移除空格、全角空格、换行符、回车符、制表符和换页符。 public static string Trim(this string @this, bool trimBlank = false) => TextUtility.Trim(@this, trimBlank); /// 移除字符串前后的空字符。 /// trimBlank:移除空格、全角空格、换行符、回车符、制表符和换页符。 public static string ToTrim(this string @this, bool trimBlank = false) => TextUtility.Trim(@this, trimBlank); /// 返回此字符串转换为小写形式的副本。 public static string Lower(this string @this) => TextUtility.Lower(@this); /// 返回此字符串转换为大写形式的副本。 public static string Upper(this string @this) => TextUtility.Upper(@this); /// 追加字符串。 public static string Append(this string @this, params object[] text) => TextUtility.Merge(@this, TextUtility.Merge(text)); /// 追加文本。 public static void Append(this StringBuilder @this, params object[] text) => TextUtility.Append(@this, text); /// 防注入处理,去除会引发代码注入的字符。可限定字符串长度。 public static string AntiInject(this string @this, int length = -1, string blacklist = null) => TextUtility.AntiInject(@this, length, blacklist); /// 将 Base64 字符串转换为字节数组。 public static byte[] Base64(this string text) => BytesUtility.FromBase64(text); /// 对 URL 编码。 public static string EncodeUrl(this string @this) => UrlEncoding.Encode(@this); /// 对 URL 解码。 public static string DecodeUrl(this string @this) => UrlEncoding.Decode(@this); /// 获取指定长度的字符串片段,可指定 trim 参数对片段再次修剪。 public static string Left(this string text, int maxLength, bool trim = false) => TextUtility.Left(text, maxLength, trim); /// 获取指定长度的字符串片段,可指定 trim 参数对片段再次修剪。 public static string Right(this string text, int maxLength, bool trim = false) => TextUtility.Right(text, maxLength, trim); /// 剪取文本内容,若指定头部为空则从原文本首部起,若指定尾部为空则至原文本末尾。 /// 剪取后的内容,不包含 head 和 foot。 public static string Cut(this string text, string head = null, string foot = null) => TextUtility.Cut(text, head, foot); /// 约束字符串中的字符,只包含指定的字符。 public static string Restrict(this string text, char[] chars) => TextUtility.Restrict(text, chars); /// 约束字符串中的字符,只包含指定的字符。 public static string Restrict(this string text, string chars) => TextUtility.Restrict(text, chars); /// 连接字符串。 public static string Join(this IEnumerable strings, string separator) => TextUtility.Join(separator, strings); #endregion #region Byte[] /// 将字节数组转换为 Base64 字符串。 public static string Base64(this byte[] @this) => BytesUtility.ToBase64(@this); /// 将字节数组转换为文本,默认为 UTF-8。 public static string Text(this byte[] @this, Encoding encoding = null) => TextUtility.FromBytes(@this, encoding); /// 检查字节数组是 UTF-8 文本,默认最多检测 1MB 数据(指定为 0 将不限制检查长度)。 public static bool IsUTF8(this byte[] @this, int checkLength = 1048576) => TextUtility.IsUTF8(@this, checkLength, null); /// 检查字节数组包含 UTF-8 BOM 头。 public static bool ContainsBOM(this byte[] @this) => TextUtility.ContainsBOM(@this); #endregion #region DateTime /// 获取毫秒时间戳。当指定了 时将优先使用自定义的方法。 /// 默认不判断参数的时区,与 相同。 public static long Stamp(this DateTime dt) => ClockUtility.ToStamp(dt); /// 转换为易于阅读的文本。 /// 格式:1970-01-01 00:00:00.000 public static string Lucid(this DateTime @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => ClockUtility.Lucid(@this, date, time, seconds, milliseconds); /// 转换为紧凑的文本。 public static string Compact(this DateTime @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => ClockUtility.Compact(@this, date, time, seconds, milliseconds); /// 当前 DateTime 为闰年。 public static bool LeapYear(this DateTime @this) => ClockUtility.IsLeapYear(@this); /// 解析毫秒时间戳,获取 DateTime 对象。当指定了 时将优先使用自定义的方法。 /// 默认不判断系统时区,返回的结果是 /// public static DateTime DateTime(this long stamp) => ClockUtility.FromStamp(stamp); #region Nullable /// 转换为易于阅读的文本。 /// 格式:1970-01-01 00:00:00.000 public static string Lucid(this DateTime? @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => @this == null ? default : ClockUtility.Lucid(@this.Value, date, time, seconds, milliseconds); /// 转换为紧凑的文本。 public static string Compact(this DateTime? @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => @this == null ? default : ClockUtility.Compact(@this.Value, date, time, seconds, milliseconds); /// 获取毫秒时间戳。当指定了 时将优先使用自定义的方法。 /// 默认不判断参数的时区,与 相同。 public static long Stamp(this DateTime? @this) => @this == null ? default : ClockUtility.ToStamp(@this.Value); /// 转换为易于阅读的文本。 /// 格式:1970-01-01 00:00:00.000 public static string Lucid(this Class @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => @this == null ? default : ClockUtility.Lucid(@this.Value, date, time, seconds, milliseconds); /// 转换为紧凑的文本。 public static string Compact(this Class @this, bool date = true, bool time = true, bool seconds = true, bool milliseconds = true) => @this == null ? default : ClockUtility.Compact(@this.Value, date, time, seconds, milliseconds); /// 获取毫秒时间戳。 public static long Stamp(this Class @this) => @this == null ? default : ClockUtility.ToStamp(@this.Value); #endregion #endregion #region ArrayBuilder /// 拼接 为字符串。 /// 连接后的字符串,返回值不为 NULL。 public static string Text(this ArrayBuilder ab) => ArrayBuilder.Text(ab); /// 拼接 为字符串。 /// 连接后的字符串,返回值不为 NULL。 /// public static string Text(this ArrayBuilder ab, int start, int count) => ArrayBuilder.Text(ab, start, count); /// 使用指定的分隔符连接 中的元素,指定分隔符为 NULL 将忽略分隔符。 /// 连接后的字符串,返回值不为 NULL。 public static string Join(this ArrayBuilder ab, string separator = null) => ArrayBuilder.Join(ab, separator); /// 使用指定的分隔符连接 中的元素,指定分隔符为 NULL 将忽略分隔符。 /// 连接后的字符串,返回值不为 NULL。 /// public static string Join(this ArrayBuilder ab, string separator, int startIndex, int maxCount) => ArrayBuilder.Join(ab, separator, startIndex, maxCount); #endregion #region Json /// Json 对象可用。 public static bool Available(this Json @this) => @this != null && @this.Available; /// 生成 JSON 对象,失败时返回 NULL。 /// 将要解析的对象。 /// 在 Json 中将属性名称转换为小写。 /// 解析深度。 /// 强制解析所有属性,忽略 Serializable 特性。 public static Json Json(this IDictionary @this, bool lowerCase = false, int depth = -1, bool force = false) => Apewer.Json.From(@this, lowerCase, depth, force); /// 解析实现 IList 的对象为 Json 对象,失败时返回 Null。 /// 将要解析的对象。 /// 在 Json 中将属性名称转换为小写。 /// 解析深度。 /// 强制解析所有属性,忽略 Serializable 特性。 public static Json Json(this IList @this, bool lowerCase = false, int depth = -1, bool force = false) => Apewer.Json.From(@this, lowerCase, depth, force); /// /// 解析对象为 Json 对象,包含所有公共属性,失败时返回 Null。 /// String 对象将解析文本;Json 对象将返回实例;String 对象将解析文本;实现 IDictionary 或 IList 的对象将解析内容。 /// /// 将要解析的对象。 /// 在 Json 中将属性名称转换为小写。 /// 解析深度。 /// 强制解析所有属性,忽略 Serializable 特性。 /// public static Json Json(object @this, bool lowerCase = false, int depth = -1, bool force = false) => Apewer.Json.From(@this, lowerCase, depth, force); /// 填充类型实例,失败时返回 NULL 值。 /// 将要解析的对象。 /// 忽略属性名称大小写。 /// 忽略的属性名称字符。 /// 强制填充,忽略 的 Serializable 特性。 public static T Object(this Json @this, bool ignoreCase = true, string ignoreChars = null, bool force = false) where T : class, new() => Apewer.Json.Object(@this, ignoreCase, ignoreChars, force); /// 填充类型实例,失败时返回 NULL 值。 /// 将要解析的对象。 /// 忽略属性名称大小写。 /// 忽略的属性名称字符。 /// 强制填充,忽略 的 Serializable 特性。 public static T[] Array(this Json @this, bool ignoreCase = true, string ignoreChars = null, bool force = false) => Apewer.Json.Array(@this, ignoreCase, ignoreChars, force); /// 设置属性名称为小写。 public static Json Lower(this Json @this) => Apewer.Json.Lower(@this); /// 设置属性名称为驼峰形式。 public static Json Camel(this Json @this) => Apewer.Json.Camel(@this); #endregion #region Logger /// 记录文本。多个 Content 参数将以“ | ”分隔。 public static void Write(this Logger logger, params object[] content) => logger?.Output(null, content, null); /// 记录异常。 public static void Exception(this Logger logger, T exception, params object[] content) where T : Exception => logger?.Output("Exception", content, exception); /// 记录错误。多个 Content 参数将以“ | ”分隔。 public static void Error(this Logger logger, params object[] content) => logger?.Output("Error", content, null); /// 记录警告。多个 Content 参数将以“ | ”分隔。 public static void Warning(this Logger logger, params object[] content) => logger?.Output("Warning", content, null); /// 记录警告。多个 Content 参数将以“ | ”分隔。 public static void Info(this Logger logger, params object[] content) => logger?.Output("Info", content, null); /// 记录文本。多个 Content 参数将以“ | ”分隔。 public static void Text(this Logger logger, params object[] content) => logger?.Output(null, content, null); /// 记录调试。多个 Content 参数将以“ | ”分隔。 [Conditional("DEBUG")] public static void Debug(this Logger logger, params object[] content) => logger?.Output("Debug", content, null); #endregion #region Stream /// 重置流的位置到开始位置。 public static bool ResetPosition(this Stream @this) => BytesUtility.ResetPosition(@this); /// 读取源流中的数据,并将数据写入目标流,获取写入的字节数。 public static long Read(this Stream @this, Stream destination, Action progress = null) => BytesUtility.Read(@this, destination, progress); /// 读取源流中的数据,并将数据写入目标流,获取写入的字节数。 public static long Read(this Stream @this, Stream destination, Func progress) => BytesUtility.Read(@this, destination, progress); /// 读取源流中的数据,获取写入的字节。 public static byte[] Read(this Stream @this, bool dispose) => BytesUtility.Read(@this, 1024, dispose); /// 读取源流中的数据。 public static byte[] Read(this Stream @this, int buffer = 1024, bool dispose = false) => BytesUtility.Read(@this, buffer, dispose); /// 向流写入数据。 /// 源流。 /// 要写入的数据。 public static long Write(this Stream @this, params byte[] bytes) => BytesUtility.Write(@this, bytes); /// 读取源流中的数据,并将数据写入当前流,获取写入的字节数。 /// 目标流。 /// 源流。 public static long Write(this Stream @this, Stream source) => BytesUtility.Read(source, @this); /// 获取 MD5 值。 public static byte[] MD5(this Stream @this) => BytesUtility.MD5(@this); /// 获取 SHA1 值。 public static byte[] SHA1(this Stream @this) => BytesUtility.SHA1(@this); #if !NET20 /// 获取 SHA256 值。 public static byte[] SHA256(this Stream @this) => BytesUtility.SHA256(@this); #endif #endregion #region Rrflection /// 判断指定类型具有特性。 public static bool Contains(this ICustomAttributeProvider @this, bool inherit = false) where T : Attribute => RuntimeUtility.Contains(@this, inherit); #endregion #region Collection /// 添加多个元素。 public static void Add(this List @this, params T[] items) { if (@this != null && items != null) @this.AddRange(items); } /// 添加元素。 public static bool Add(this IList> @this, TKey key, TValue value) => CollectionUtility.Add(@this, key, value); /// 判断集合为空。 public static bool IsEmpty(this IEnumerable @this) => CollectionUtility.IsEmpty(@this); /// 判断集合存在元素。 public static bool NotEmpty(this IEnumerable @this) => CollectionUtility.NotEmpty(@this); /// 检查集合是否包含 item。 public static bool Contains(this IEnumerable @this, T item) => CollectionUtility.Contains(@this, item); /// 获取 item 在集合中的偏移位置,不存在时返回 -1。 public static int IndexOf(this IEnumerable objects, T item) => CollectionUtility.IndexOf(objects, item); /// 获取集合中元素的数量。 public static int Count(this IEnumerable @this) => CollectionUtility.Count(@this); /// 获取可枚举集合的部分元素。 public static T[] Slice(this IEnumerable @this, int start = 0, int count = -1, Func stuffer = null) => CollectionUtility.Slice(@this, start, count, stuffer); /// 安全转换为 List<> 对象。可指定排除 NULL 值元素。 public static List List(this IEnumerable @this, bool excludeNull = false) => CollectionUtility.List(@this, excludeNull); /// 安全转换为 <>[] 对象。可指定排除 NULL 值元素。 public static T[] Array(IEnumerable @this, bool excludeNull = false) => CollectionUtility.Array(@this, excludeNull); /// 对列表中的元素排序。 public static List Sort(this List @this, Func comparison) => CollectionUtility.Sort(@this, comparison); /// 对字典中的键排序。 public static Dictionary SortKey(this Dictionary @this, Func comparison) => CollectionUtility.SortKey(@this, comparison); /// 对字典中的键排序。 public static Dictionary SortKey(this Dictionary @this) where TKey : IComparable => CollectionUtility.SortKey(@this, (a, b) => a.CompareTo(b)); /// 对字典中的值排序。 public static Dictionary SortValue(this Dictionary @this, Func comparison) => CollectionUtility.SortValue(@this, comparison); /// 对字典中的值排序。 public static Dictionary SortValue(this Dictionary @this) where TValue : IComparable => CollectionUtility.SortValue(@this, (a, b) => a.CompareTo(b)); /// 获取集合中的第一个元素。可指定失败时的默认返回值。 public static T First(this IEnumerable collection, T failed = default(T)) => CollectionUtility.First(collection, failed); /// 获取集合中的最后一个元素。可指定失败时的默认返回值。 public static T Last(this IEnumerable collection, T failed = default(T)) => CollectionUtility.Last(collection, failed); /// 生成 StringPairs 对象实例为副本。 public static StringPairs StringPairs(this NameValueCollection @this) => Apewer.StringPairs.From(@this); /// 对数组排序。 /// public static void Sort(this T[] @this, Func func) { if (@this != null && func != null) System.Array.Sort(@this, new Comparison(func)); } /// 对数组升序排序。 /// public static void Ascend(this T[] @this) where T : IComparable { if (@this != null) Sort(@this, (a, b) => a.CompareTo(b)); } /// 对数组升序排序。 /// public static void Ascend(this T[] @this, Func func) where TProp : IComparable { if (@this != null && func != null) Sort(@this, (a, b) => func(a).CompareTo(func(b))); } /// 对数组降序排序。 /// public static void Descend(this T[] @this) where T : IComparable { if (@this != null) Sort(@this, (a, b) => 0 - a.CompareTo(b)); } /// 对数组降序排序。 /// public static void Descend(this T[] @this, Func func) where TProp : IComparable { if (@this != null && func != null) Sort(@this, (a, b) => 0 - func(a).CompareTo(func(b))); } #endregion #region Sets /// 解析源对象。 public static Dictionary Origin(this ObjectSet instance) => instance == null ? null : instance.Origin; /// 解析源对象。 public static Dictionary Origin(this ObjectSet instance) => instance == null ? null : instance.Origin; /// 清空元素。 public static void Clear(this ObjectSet instance) => instance?.Origin?.Clear(); /// 解析源对象。 public static Dictionary Origin(this TextSet instance) => instance == null ? null : instance.Origin; /// 清空元素。 public static void Clear(this TextSet instance) => instance?.Origin?.Clear(); #endregion #region Source /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。 public static Class DateTime(this IQuery @this, int row, int column) => @this == null ? null : ClockUtility.DateTime(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。 public static Class DateTime(this IQuery @this, int row, string column) => @this == null ? null : ClockUtility.DateTime(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。 public static Int32 Int32(this IQuery @this, int row, int column) => @this == null ? 0 : NumberUtility.Int32(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。 public static Int32 Int32(this IQuery @this, int row, string column) => @this == null ? 0 : NumberUtility.Int32(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。 public static Int64 Int64(this IQuery @this, int row, int column) => @this == null ? 0L : NumberUtility.Int64(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。 public static Int64 Int64(this IQuery @this, int row, string column) => @this == null ? 0L : NumberUtility.Int64(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。 public static Decimal Decimal(this IQuery @this, int row, int column) => @this == null ? 0M : NumberUtility.Decimal(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。 public static Decimal Decimal(this IQuery @this, int row, string column) => @this == null ? 0M : NumberUtility.Decimal(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。> public static Double Double(this IQuery @this, int row, int column) => @this == null ? 0D : NumberUtility.Double(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。> public static Double Double(this IQuery @this, int row, string column) => @this == null ? 0D : NumberUtility.Double(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行第 0 列开始。 public static string Text(this IQuery @this, int row, int column) => @this == null ? null : TextUtility.Text(@this.Value(row, column)); /// 获取默认表中指定单元格的内容。从第 0 行开始。 public static string Text(this IQuery @this, int row, string column) => @this == null ? null : TextUtility.Text(@this.Value(row, column)); /// 转换 数组,每行记录为一个 ObjectSet 对象。 /// 当参数 table 无效时返回 0 长度的 数组。 public static ObjectSet[] ObjectSet(this IQuery @this) => @this == null ? null : SourceUtility.ObjectSet(@this.Table); /// 转换 为 CSV 文本,不存在表时返回 NULL 值。可指定是否包含表头。 public static string Csv(this IQuery query, bool withHead = false) => query == null ? null : SourceUtility.Csv(query.Table, withHead); #endregion #region Web /// 获取参数,指定可能的参数名,默认将修剪参数值。 /// 当从 URL 中获取参数时将解码。 public static string Parameter(this ApiRequest @this, params string[] names) => ApiUtility.Parameter(@this, true, names); /// 设置 status 为 error,并设置 message 的内容。 public static void Error(this ApiResponse @this, string message = "未知错误。") => ApiUtility.Error(@this, message); /// 输出字节数组。 public static void Bytes(this ApiResponse @this, byte[] bytes, string type = "application/octet-stream") => ApiUtility.Model(@this, new ApiBytesModel(bytes, type)); /// 输出 UTF-8 文本。 public static void Text(this ApiResponse @this, string text, string contentType = "text/plain") => ApiUtility.Model(@this, new ApiTextModel(text, contentType)); /// 输出 Json 文本。 public static void Json(this ApiResponse @this, Json json, bool indented = false, bool camel = true) => ApiUtility.Model(@this, new ApiJsonModel(json, indented, camel)); /// 输出文件。 public static void File(this ApiResponse @this, string path) => ApiUtility.Model(@this, new ApiFileModel(path)); /// 重定向。 public static void Redirect(this ApiResponse @this, string location) => ApiUtility.Model(@this, new ApiRedirectModel(location)); #endregion }