joe_pool_is
Well-known member
I have recreated System.Net.Mail.Message, because Microsoft did not see a reason to implement the Serializable feature. It looks like everything in Microsofts Mail.Message class can be duplicated by organizing and naming strings appropriately.
I want to implement IDispose in my class so that it cleans itself up nicely, and (with the way I designed my class) all I need to dispose of are strings!
My email attachments are loaded from the local PC using a Stream Reader, then loaded into a string buffer (which gives me a 2 GB capacity - Im hoping this is going to work, but it is still being developed).
My custom Message object handles attachments by creating a List of MyAttachments like so:
When I dispose of the resources used by my mail message model, how should I handle the strings?
Take the attachments, for example - Should I:
I would show the code, but I had to create a Mail Address class and an Attachment class to enable my Mail Message class to look like Microsofts version (makes it easy to learn), so there are several lines of code and Ive commented it well. Perhaps one day, Ill post it on CodeProject...
For now, heres my snippet of disposing related code:
I want to implement IDispose in my class so that it cleans itself up nicely, and (with the way I designed my class) all I need to dispose of are strings!
My email attachments are loaded from the local PC using a Stream Reader, then loaded into a string buffer (which gives me a 2 GB capacity - Im hoping this is going to work, but it is still being developed).
My custom Message object handles attachments by creating a List of MyAttachments like so:
Code:
List<MyAttachment> Attachments
When I dispose of the resources used by my mail message model, how should I handle the strings?
Take the attachments, for example - Should I:
- Set each String to an Empty String (i.e. attachment = string.Empty)?
- Set the String to NULL (i.e attachment = null)?
- Clear the List [i.e. Attachments.Clear()]?
- A combination of above?
- Or, are strings managed (i.e. I dont need to do anything)?
I would show the code, but I had to create a Mail Address class and an Attachment class to enable my Mail Message class to look like Microsofts version (makes it easy to learn), so there are several lines of code and Ive commented it well. Perhaps one day, Ill post it on CodeProject...
For now, heres my snippet of disposing related code:
Code:
#region IDisposable Members
~JpMessage() {
Dispose(false);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
// If disposing equals false, the method has been called by the
// runtime from inside the finalizer and you should not reference
// other objects. Only unmanaged resources can be disposed.
protected virtual void Dispose(bool disposing) {
if (this._disposed == false) {
if (disposing == true) {
if (!_from.IsDisposed) _from.Dispose();
if (!_replyTo.IsDisposed) _replyTo.Dispose();
if (!_sender.IsDisposed) _sender.Dispose();
foreach (JpMailAddress obj in _bcc) {
if (!obj.IsDisposed) obj.Dispose();
}
foreach (JpMailAddress obj in _cc) {
if (!obj.IsDisposed) obj.Dispose();
}
foreach (JpMailAddress obj in _to) {
if (!obj.IsDisposed) obj.Dispose();
}
foreach (JpAttachment obj in _attachments) {
if (!obj.IsDisposed) obj.Dispose();
}
}
}
_disposed = true;
}
#endregion
Last edited by a moderator: