public static void SetValue(PropertyInfo info, object obj, object value) { AtawDebug.AssertArgumentNull(info, "info", null); AtawDebug.AssertArgumentNull(obj, "obj", null); try { info.SetValue(obj, value, null); } catch (System.ArgumentException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "对象{0}未找到属性{1}的 set 访问器或者数组不包含所需类型的参数", obj.GetType(), info.Name), ex, null); } catch (TargetException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "对象{0}中可能不存在属性{1},请检查", obj.GetType(), info.Name), ex, null); } catch (MethodAccessException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "无法设置对象{0}中属性{1}的值,请检查set的访问权限", obj.GetType(), info.Name), ex, null); } }
public static object CreateObject(Type type) { AtawDebug.AssertArgumentNull(type, "type", null); try { return(Activator.CreateInstance(type)); } catch (MissingMethodException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "没有找到类型{0}的默认构造函数,请确认", type), ex, null); } catch (TargetInvocationException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "调用类型{0}的默认构造函数时,发生例外,请调试你的代码", type), ex, null); } catch (MethodAccessException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "类型{0}的默认构造函数访问权限不够", type), ex, null); } catch (MemberAccessException ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "类型{0}可能是一个抽象类型,无法创建", type), ex, null); } catch (Exception ex) { AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture, "调用类型{0}的默认构造函数是发生例外", type), ex, null); } return(null); }
public static void SendSMTPEMail(string strto, string strSubject, string strBody) { SmtpClient client = new SmtpClient(SMTPHost); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword); client.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage message = new MailMessage(SMTPUser, strto, strSubject, strBody); message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); message.IsBodyHtml = true; try { client.Send(message); } catch (Exception ex) { AtawDebug.ThrowAtawException(ex.Message, null); } }