Class AttachmentCollectionExtensions

Namespace
Wolfgang.Extensions.Mail
Assembly
Wolfgang.Extensions.Mail.dll

A collection of extension methods for the AttachmentCollection class.

public static class AttachmentCollectionExtensions
Inheritance
AttachmentCollectionExtensions
Inherited Members

Methods

AddRange(AttachmentCollection, IEnumerable<Attachment>)

Adds a range of Attachment objects to the AttachmentCollection.

public static void AddRange(this AttachmentCollection source, IEnumerable<Attachment> attachments)

Parameters

source AttachmentCollection

The collection to add to

attachments IEnumerable<Attachment>

The list of Attachment to add

Exceptions

ArgumentNullException

source is null

ArgumentNullException

attachments is null

AddRange(AttachmentCollection, IEnumerable<string>)

Adds a range of Attachment objects to the AttachmentCollection.

public static void AddRange(this AttachmentCollection source, IEnumerable<string> fileNames)

Parameters

source AttachmentCollection

The collection to add to

fileNames IEnumerable<string>

The list of string containing file names to add

Exceptions

ArgumentNullException

source is null

ArgumentNullException

fileNames is null

AddRange(AttachmentCollection, params Attachment[])

Adds a range of Attachment objects to the AttachmentCollection.

public static void AddRange(this AttachmentCollection source, params Attachment[] attachments)

Parameters

source AttachmentCollection

The collection to add to

attachments Attachment[]

The list of Attachment to add

Exceptions

ArgumentNullException

source is null

ArgumentNullException

attachments is null

AddRange(AttachmentCollection, params string[])

Adds a range of Attachment objects to the AttachmentCollection.

public static void AddRange(this AttachmentCollection source, params string[] fileNames)

Parameters

source AttachmentCollection

The collection to add to

fileNames string[]

The list of string containing file names to add

Exceptions

ArgumentNullException

source is null

ArgumentNullException

fileNames is null

ExceedsLimit(AttachmentCollection, long)

Returns a value indicating whether the total size of all attachments exceeds the specified maximum number of bytes.

public static bool ExceedsLimit(this AttachmentCollection source, long maxBytes)

Parameters

source AttachmentCollection

The AttachmentCollection to check.

maxBytes long

The maximum allowed total size in bytes.

Returns

bool

true if the total attachment size exceeds maxBytes; otherwise, false.

Exceptions

ArgumentNullException

source is null.

TotalSize(AttachmentCollection)

Returns the total size in bytes of all attachments in the AttachmentCollection whose underlying streams support seeking. Non-seekable streams are excluded from the total.

public static long TotalSize(this AttachmentCollection source)

Parameters

source AttachmentCollection

The AttachmentCollection to measure.

Returns

long

The total size in bytes of all seekable attachment streams.

Examples

using var message = new MailMessage();
message.Attachments.AddRange("report.pdf", "data.csv");
long totalBytes = message.Attachments.TotalSize();

Exceptions

ArgumentNullException

source is null.