/// <summary> /// 获取Xml节点属性值 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="node">节点</param> /// <param name="name">属性名</param> /// <param name="defaultValue">>默认值。如果没有匹配属性存在</param> /// <returns></returns> public static T GetAttribute <T>(this XmlNode node, string name, T defaultValue = default(T)) { var value = node.GetAttribute(name); if (string.IsNullOrWhiteSpace(value)) { return(defaultValue); } return(ConvHelper.To <T>(value)); }
/// <summary> /// 获取指定键名的值 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="identity">标识</param> /// <param name="key">键名</param> /// <returns></returns> public static T GetValue <T>(this IIdentity identity, string key) { return(ConvHelper.To <T>(identity.GetValue(key))); }
/// <summary> /// 获取枚举值 /// </summary> /// <typeparam name="TResult">返回值类型</typeparam> /// <param name="instance">枚举实例</param> /// <returns></returns> public static TResult Value <TResult>(this System.Enum instance) { return(ConvHelper.To <TResult>(Value(instance))); }