Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / mail / SmtpFailedRecipientsException.cs
1 using System;
2 using System.Collections;
3 using System.Diagnostics.CodeAnalysis;
4 using System.Runtime.Serialization;
5 using System.Security.Permissions;
6
7 namespace System.Net.Mail
8 {
9     /// <summary>
10     /// Summary description for SmtpFailedRecipientsException.
11     /// </summary>
12     [Serializable]
13     public class SmtpFailedRecipientsException : SmtpFailedRecipientException, ISerializable
14     {
15         SmtpFailedRecipientException[] innerExceptions;
16
17
18         // FxCop
19         public SmtpFailedRecipientsException()
20         {
21             innerExceptions = new SmtpFailedRecipientException[0];
22         }
23
24         public SmtpFailedRecipientsException(string message) : base(message)
25         {
26             innerExceptions = new SmtpFailedRecipientException[0];
27         }
28
29         public SmtpFailedRecipientsException(string message, Exception innerException) : base(message, innerException)
30         {
31             SmtpFailedRecipientException smtpException = innerException as SmtpFailedRecipientException;
32             this.innerExceptions = smtpException == null ? new SmtpFailedRecipientException[0] : new SmtpFailedRecipientException[] { smtpException };
33         }
34
35         protected SmtpFailedRecipientsException(SerializationInfo info, StreamingContext context) : base(info, context)
36         {
37             innerExceptions = (SmtpFailedRecipientException[]) info.GetValue("innerExceptions", typeof(SmtpFailedRecipientException[]));
38         }
39
40
41         public SmtpFailedRecipientsException(string message, SmtpFailedRecipientException[] innerExceptions) :
42             base(message, innerExceptions != null && innerExceptions.Length > 0 ? innerExceptions[0].FailedRecipient : null,
43             innerExceptions != null && innerExceptions.Length > 0 ? innerExceptions[0] : null)
44         {
45             if (innerExceptions == null)
46             {
47                 throw new ArgumentNullException("innerExceptions");
48             }
49
50             this.innerExceptions = innerExceptions == null ? new SmtpFailedRecipientException[0] : innerExceptions;
51         }
52
53         internal SmtpFailedRecipientsException(ArrayList innerExceptions, bool allFailed) :
54             base(allFailed ? SR.GetString(SR.SmtpAllRecipientsFailed) : SR.GetString(SR.SmtpRecipientFailed),
55             innerExceptions != null && innerExceptions.Count > 0 ? ((SmtpFailedRecipientException) innerExceptions[0]).FailedRecipient : null,
56             innerExceptions != null && innerExceptions.Count > 0 ? (SmtpFailedRecipientException) innerExceptions[0] : null)
57         {
58             if (innerExceptions == null)
59             {
60                 throw new ArgumentNullException("innerExceptions");
61             }
62
63             this.innerExceptions = new SmtpFailedRecipientException[innerExceptions.Count];
64             int i = 0;
65             foreach(SmtpFailedRecipientException e in innerExceptions) {
66                 this.innerExceptions[i++]=e;
67             }
68         }
69
70         public SmtpFailedRecipientException[] InnerExceptions
71         { 
72             get
73             {
74                 return innerExceptions;
75             }
76         }
77
78
79         //
80         // ISerializable
81         //
82
83         /// <internalonly/>
84
85         [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase", Justification = "System.dll is still using pre-v4 security model and needs this demand")]
86         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
87         void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
88         {
89             GetObjectData(serializationInfo, streamingContext);
90         }
91
92         //
93         // FxCop: provide some way for derived classes to access GetObjectData even if the derived class
94         // explicitly re-inherits ISerializable.
95         //
96         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]           
97         public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
98         {
99             base.GetObjectData(serializationInfo, streamingContext);
100             serializationInfo.AddValue("innerExceptions", innerExceptions, typeof(SmtpFailedRecipientException[]));
101         }
102     }
103 }