Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / Net / Mail / HeaderCollection.cs / 3 / HeaderCollection.cs
using System; using System.Collections.Specialized; using System.Net.Mail; using System.Globalization; namespace System.Net.Mime { ////// Summary description for HeaderCollection. /// internal class HeaderCollection: NameValueCollection { MimeBasePart part = null; // default constructor // intentionally override the default comparer in the derived base class internal HeaderCollection() : base(StringComparer.OrdinalIgnoreCase) { } public override void Remove(string name) { if(Logging.On)Logging.PrintInfo(Logging.Web, this, "Remove", name); if (name == null) throw new ArgumentNullException("name"); if (name == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"name"), "name"); MailHeaderID id = MailHeaderInfo.GetID(name); if (id == MailHeaderID.ContentType && part != null) { part.ContentType = null; } else if (id == MailHeaderID.ContentDisposition && part is MimePart) { ((MimePart)part).ContentDisposition = null; } base.Remove(name); } public override string Get(string name) { if(Logging.On)Logging.PrintInfo(Logging.Web, this, "Get", name); if (name == null) throw new ArgumentNullException("name"); if (name == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"name"), "name"); MailHeaderID id = MailHeaderInfo.GetID(name); if (id == MailHeaderID.ContentType && part != null) { part.ContentType.PersistIfNeeded(this,false); } else if (id == MailHeaderID.ContentDisposition && part is MimePart) { ((MimePart)part).ContentDisposition.PersistIfNeeded(this, false); } return base.Get(name); } public override string[] GetValues(string name) { if(Logging.On)Logging.PrintInfo(Logging.Web, this, "Get", name); if (name == null) throw new ArgumentNullException("name"); if (name == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"name"), "name"); MailHeaderID id = MailHeaderInfo.GetID(name); if (id == MailHeaderID.ContentType && part != null) { part.ContentType.PersistIfNeeded(this,false); } else if (id == MailHeaderID.ContentDisposition && part is MimePart) { ((MimePart)part).ContentDisposition.PersistIfNeeded(this, false); } return base.GetValues(name); } internal void InternalRemove(string name){ base.Remove(name); } internal void InternalSet(string name, string value) { base.Set(name, value); } public override void Set(string name, string value) { if(Logging.On)Logging.PrintInfo(Logging.Web, this, "Set", name.ToString() + "=" + value.ToString()); if (name == null) throw new ArgumentNullException("name"); if (value == null) throw new ArgumentNullException("value"); if (name == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"name"), "name"); if (value == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"value"), "name"); if (!MimeBasePart.IsAscii(name,false)) { throw new FormatException(SR.GetString(SR.InvalidHeaderName)); } if (!MimeBasePart.IsAnsi(value,false)) { throw new FormatException(SR.GetString(SR.InvalidHeaderValue)); } // normalize the case of well known headers name = MailHeaderInfo.NormalizeCase(name); MailHeaderID id = MailHeaderInfo.GetID(name); if (id == MailHeaderID.ContentType && part != null) { part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this); } else if (id == MailHeaderID.ContentDisposition && part is MimePart) { ((MimePart)part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this); } else { base.Set(name, value); } } public override void Add(string name, string value) { if(Logging.On)Logging.PrintInfo(Logging.Web, this, "Add", name.ToString() + "=" + value.ToString()); if (name == null) throw new ArgumentNullException("name"); if (value == null) throw new ArgumentNullException("value"); if (name == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"name"), "name"); if (value == string.Empty) throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"value"), "name"); MailBnfHelper.ValidateHeaderName(name); if (!MimeBasePart.IsAnsi(value,false)) { throw new FormatException(SR.GetString(SR.InvalidHeaderValue)); } // normalize the case of well known headers name = MailHeaderInfo.NormalizeCase(name); MailHeaderID id = MailHeaderInfo.GetID(name); if(id == MailHeaderID.ContentType && part != null) { part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this); } else if (id == MailHeaderID.ContentDisposition && part is MimePart) { ((MimePart)part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this); } else { if (MailHeaderInfo.IsSingleton(name)) { base.Set(name, value); } else { base.Add(name, value); } } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Avt.cs
- FlowLayoutPanel.cs
- Addressing.cs
- FixedTextBuilder.cs
- TreeWalkHelper.cs
- UnsafeNetInfoNativeMethods.cs
- BitmapImage.cs
- CreateRefExpr.cs
- BatchParser.cs
- TargetException.cs
- SqlProfileProvider.cs
- CellLabel.cs
- DefinitionBase.cs
- HtmlInputHidden.cs
- DataGridTextBoxColumn.cs
- QuadraticBezierSegment.cs
- ZipIOLocalFileHeader.cs
- Int32CollectionValueSerializer.cs
- WebPartCatalogAddVerb.cs
- FocusTracker.cs
- GridPatternIdentifiers.cs
- BitmapInitialize.cs
- CancellationHandler.cs
- ZipArchive.cs
- ServiceBusyException.cs
- FileLoadException.cs
- RemotingConfigParser.cs
- TableLayoutSettings.cs
- SoapInteropTypes.cs
- BindingExpression.cs
- UrlRoutingHandler.cs
- XPathArrayIterator.cs
- NullableLongSumAggregationOperator.cs
- QilScopedVisitor.cs
- VisualStyleTypesAndProperties.cs
- PerspectiveCamera.cs
- CollectionsUtil.cs
- XXXInfos.cs
- XPathNodePointer.cs
- ImageBrush.cs
- BindStream.cs
- odbcmetadatacollectionnames.cs
- ISessionStateStore.cs
- OrderedHashRepartitionEnumerator.cs
- DataTransferEventArgs.cs
- SchemaMapping.cs
- ExpressionBinding.cs
- CodeDOMUtility.cs
- CombinedGeometry.cs
- BuildProvider.cs
- CompilationUtil.cs
- SpellerStatusTable.cs
- Message.cs
- LambdaCompiler.Binary.cs
- WSSecurityXXX2005.cs
- externdll.cs
- DataTemplate.cs
- HighlightVisual.cs
- ListViewAutomationPeer.cs
- PageWrapper.cs
- ClusterSafeNativeMethods.cs
- EventBindingService.cs
- HttpCookie.cs
- JsonServiceDocumentSerializer.cs
- AmbientEnvironment.cs
- TabItem.cs
- SpellerHighlightLayer.cs
- IndexerHelper.cs
- EventMap.cs
- NonSerializedAttribute.cs
- TextCompositionEventArgs.cs
- FixedHyperLink.cs
- WebServiceParameterData.cs
- ModelProperty.cs
- Win32SafeHandles.cs
- mda.cs
- BufferBuilder.cs
- ButtonRenderer.cs
- AnnotationComponentManager.cs
- userdatakeys.cs
- ColorTransform.cs
- NullRuntimeConfig.cs
- MetadataUtilsSmi.cs
- Misc.cs
- AssemblyName.cs
- OdbcFactory.cs
- ImpersonationContext.cs
- GridViewSelectEventArgs.cs
- InfiniteIntConverter.cs
- AssociationSetMetadata.cs
- FileVersionInfo.cs
- MsmqTransportSecurity.cs
- Evidence.cs
- CodeDirectionExpression.cs
- ListViewGroupItemCollection.cs
- RIPEMD160.cs
- Command.cs
- PropertyMetadata.cs
- SafeArrayRankMismatchException.cs
- InternalEnumValidatorAttribute.cs