Inheritance - System.Net.Mail namespace

  • Thread starter Prefers Golfing
  • Start date
P

Prefers Golfing

We are having to extend the System.Net.Mail namespace and need some help
with coding it.

We have added several properties to System.Net.Mail.Attachment and need to
add our several of them to System.Net.Mail.MailMessage.Attachments.

// public AttachmentCollection Attachments { get; }

How do we override AttachmentCollection to be a collection of
OurNamespace.Attachments?

How then do we override MailMessage to be the above collection?

public class MailMessage : System.Net.Mail.MailMessage

{

public MailMessage()

{

}


private int _shipmentID;

public int ShipmentID

{

get { return _shipmentID; }

set { _shipmentID = value; }

}

private int _shipmentEmailsID;

public int ShipmentEmailsID

{

get { return _shipmentEmailsID; }

set { _shipmentEmailsID = value; }

}

// overide attachments

public override ?

}

public class Attachment : System.Net.Mail.Attachment

{private int _documentsID;

public int DocumentsID

{

get { return _documentsID; }

set { _documentsID = value; }

}

}
 
I

Ignacio Machin ( .NET/ C# MVP )

We are having to extend the System.Net.Mail namespace and need some help
with coding it.

We have added several properties to System.Net.Mail.Attachment and need to
add our several of them to System.Net.Mail.MailMessage.Attachments.

// public AttachmentCollection Attachments { get; }

How do we override AttachmentCollection to be a collection of
OurNamespace.Attachments?

you can't Attachments is not a virtual member in MailMessage.
What this means is that if you pass an instance of your new class to a
method that use a MailMessage it will use MailMessage's member, not
yours.

If you will use your class only with your new classes then you are ok,
just define Attachments in the same way.
 
A

Arne Vajhøj

Prefers said:
We are having to extend the System.Net.Mail namespace and need some help
with coding it.

We have added several properties to System.Net.Mail.Attachment and need to
add our several of them to System.Net.Mail.MailMessage.Attachments.

// public AttachmentCollection Attachments { get; }

How do we override AttachmentCollection to be a collection of
OurNamespace.Attachments?

How then do we override MailMessage to be the above collection?

I think we have a classic case of trying to extend classes that
were not intended to be extended.

Or to put it another way: I think you need to either live with
the standard .NET functionality or implement your own mail
framework from scratch (the protocols are reasonable simple
to implement).

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top