Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / HeaderCollection.cs / 1305376 / 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); } //set an existing header's value internal void InternalSet(string name, string value) { base.Set(name, value); } //add a new header and set its value internal void InternalAdd(string name, string value) { if (MailHeaderInfo.IsSingleton(name)) { base.Set(name, value); } else { base.Add(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)); } // 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); // 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 { InternalAdd(name, value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AuthorizationBehavior.cs
- XmlSubtreeReader.cs
- ImageBrush.cs
- WinFormsSecurity.cs
- EventArgs.cs
- GeometryHitTestParameters.cs
- TextLine.cs
- CodeDOMUtility.cs
- EditingMode.cs
- Memoizer.cs
- XmlSchemaSubstitutionGroup.cs
- NullableBoolConverter.cs
- PrinterResolution.cs
- InternalBufferOverflowException.cs
- ExpressionBinding.cs
- entitydatasourceentitysetnameconverter.cs
- WebPartCancelEventArgs.cs
- XamlToRtfWriter.cs
- X509Certificate2.cs
- ToolStripEditorManager.cs
- DefaultBinder.cs
- ComAdminInterfaces.cs
- SecondaryIndexDefinition.cs
- ContextStaticAttribute.cs
- InternalTypeHelper.cs
- NonPrimarySelectionGlyph.cs
- EventDescriptor.cs
- QilScopedVisitor.cs
- OracleLob.cs
- ReceiveActivityValidator.cs
- SignedXml.cs
- COM2ComponentEditor.cs
- HebrewNumber.cs
- StylusDownEventArgs.cs
- CellTreeNodeVisitors.cs
- Rotation3DAnimationUsingKeyFrames.cs
- PasswordTextNavigator.cs
- Random.cs
- IdentityValidationException.cs
- UIElementAutomationPeer.cs
- BaseComponentEditor.cs
- EventHandlerList.cs
- AssemblyNameProxy.cs
- DesignerSerializationOptionsAttribute.cs
- AnnotationElement.cs
- WhitespaceRuleReader.cs
- SqlProfileProvider.cs
- ConfigXmlWhitespace.cs
- ComPersistableTypeElementCollection.cs
- DataControlCommands.cs
- DataTableMappingCollection.cs
- Slider.cs
- SmtpFailedRecipientsException.cs
- ContentHostHelper.cs
- GcHandle.cs
- LineInfo.cs
- DataGridViewControlCollection.cs
- MonitoringDescriptionAttribute.cs
- PropertySourceInfo.cs
- EntityModelSchemaGenerator.cs
- HttpProfileGroupBase.cs
- CmsInterop.cs
- XmlSchemaException.cs
- ISFTagAndGuidCache.cs
- ActivitySurrogate.cs
- ConfigurationException.cs
- TextDecorationUnitValidation.cs
- ConditionChanges.cs
- DBBindings.cs
- LinqToSqlWrapper.cs
- DataGridViewControlCollection.cs
- RefType.cs
- UserControlAutomationPeer.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- SqlUdtInfo.cs
- ReaderOutput.cs
- WindowsFont.cs
- TableParagraph.cs
- TextDpi.cs
- SamlDoNotCacheCondition.cs
- XmlEncodedRawTextWriter.cs
- GrammarBuilder.cs
- SoapServerMethod.cs
- HandleCollector.cs
- DataGridViewRowPrePaintEventArgs.cs
- TextTreeExtractElementUndoUnit.cs
- TableDetailsRow.cs
- RestHandlerFactory.cs
- ActivitiesCollection.cs
- DynamicRendererThreadManager.cs
- HideDisabledControlAdapter.cs
- XmlUtil.cs
- InheritanceRules.cs
- DiscreteKeyFrames.cs
- FormViewModeEventArgs.cs
- ModelTreeEnumerator.cs
- GcSettings.cs
- Localizer.cs
- NonPrimarySelectionGlyph.cs
- EmbeddedMailObjectCollectionEditor.cs