/// <summary> /// 获取枚举项的Description特性的描述文字 /// </summary> /// <param name="enumeration"> </param> /// <returns> </returns> public static string ToDescription(this Enum enumeration) { Type type = enumeration.GetType(); MemberInfo[] members = type.GetMember(enumeration.CastTo<string>()); if (members.Length > 0) { return members[0].ToDescription(); } return enumeration.CastTo<string>(); }
public static IHtmlNode AsNode( this AP.HtmlNode node ) { switch ( node.NodeType ) { case AP.HtmlNodeType.Element: return new HtmlElementAdapter( node ); case AP.HtmlNodeType.Text: return node.CastTo<AP.HtmlTextNode>().AsTextNode(); case AP.HtmlNodeType.Comment: return node.CastTo<AP.HtmlCommentNode>().AsComment(); default: throw new NotSupportedException(); } }
public static string FullExceptionString(this Exception ex) { var exceptionStringBuilder = new StringBuilder(); while (ex != null) { if (ex is SoapException) { var detail = ex.CastTo<SoapException>().Detail; if (detail != null) { var detailString = detail.InnerText; if (!string.IsNullOrEmpty(detailString)) { exceptionStringBuilder.AppendLine(detailString); } } } if (!string.IsNullOrEmpty(ex.Message)) { exceptionStringBuilder.AppendLine(ex.Message); } if (!string.IsNullOrEmpty(ex.StackTrace)) { exceptionStringBuilder.AppendLine(ex.StackTrace); } ex = ex.InnerException; } return exceptionStringBuilder.ToString(); }
public static int ForSql(this Enum value) { return value.CastTo<int>(); }
public static CodeCastExpression CastTo(this CodeExpression expr, Type type) { return expr.CastTo(Easy.TypeRef(type)); }