add ISafeSerializationData
[mcs.git] / class / System / System.Net.Mail / AlternateView.cs
blob8d178b6f6cc71c1dbb88e73fab0e9e6e054d8fdb
1 //
2 // System.Net.Mail.AlternateView.cs
3 //
4 // Author:
5 // John Luke (john.luke@gmail.com)
6 //
7 // Copyright (C) John Luke, 2005
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if NET_2_0
33 using System.IO;
34 using System.Net.Mime;
35 using System.Text;
37 namespace System.Net.Mail {
38 public class AlternateView : AttachmentBase
40 #region Fields
41 Uri baseUri;
42 LinkedResourceCollection linkedResources = new LinkedResourceCollection ();
44 #endregion // Fields
46 #region Constructors
48 public AlternateView (string fileName) : base (fileName)
50 if (fileName == null)
51 throw new ArgumentNullException ();
54 public AlternateView (string fileName, ContentType contentType) : base (fileName, contentType)
56 if (fileName == null)
57 throw new ArgumentNullException ();
60 public AlternateView (string fileName, string mediaType) : base (fileName, mediaType)
62 if (fileName == null)
63 throw new ArgumentNullException ();
66 public AlternateView (Stream contentStream) : base (contentStream)
70 public AlternateView (Stream contentStream, string mediaType) : base (contentStream, mediaType)
74 public AlternateView (Stream contentStream, ContentType contentType) : base (contentStream, contentType)
78 #endregion // Constructors
80 #region Properties
82 #endregion // Properties
84 public Uri BaseUri {
85 get { return baseUri; }
86 set { baseUri = value; }
89 public LinkedResourceCollection LinkedResources {
90 get { return linkedResources; }
93 #region Methods
95 public static AlternateView CreateAlternateViewFromString (string content)
97 if (content == null)
98 throw new ArgumentNullException ();
99 MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (content));
100 AlternateView av = new AlternateView (ms);
101 av.TransferEncoding = TransferEncoding.QuotedPrintable;
102 return av;
105 public static AlternateView CreateAlternateViewFromString (string content, ContentType contentType)
107 if (content == null)
108 throw new ArgumentNullException ("content");
109 Encoding enc = contentType.CharSet != null ? Encoding.GetEncoding (contentType.CharSet) : Encoding.UTF8;
110 MemoryStream ms = new MemoryStream (enc.GetBytes (content));
111 AlternateView av = new AlternateView (ms, contentType);
112 av.TransferEncoding = TransferEncoding.QuotedPrintable;
113 return av;
116 public static AlternateView CreateAlternateViewFromString (string content, Encoding encoding, string mediaType)
118 if (content == null)
119 throw new ArgumentNullException ("content");
120 if (encoding == null)
121 encoding = Encoding.UTF8;
122 MemoryStream ms = new MemoryStream (encoding.GetBytes (content));
123 ContentType ct = new ContentType ();
124 ct.MediaType = mediaType;
125 ct.CharSet = encoding.HeaderName;
126 AlternateView av = new AlternateView (ms, ct);
127 av.TransferEncoding = TransferEncoding.QuotedPrintable;
128 return av;
131 protected override void Dispose (bool disposing)
133 if (disposing)
134 foreach (LinkedResource lr in linkedResources)
135 lr.Dispose ();
136 base.Dispose (disposing);
139 #endregion // Methods
143 #endif // NET_2_0