Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Configuration / System / Configuration / StringAttributeCollection.cs / 1 / StringAttributeCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;
namespace System.Configuration {
public sealed class CommaDelimitedStringCollection : StringCollection {
private bool _Modified;
private bool _ReadOnly;
private string _OriginalString;
//
// Constructor
//
public CommaDelimitedStringCollection() {
_ReadOnly = false;
_Modified = false;
_OriginalString = ToString();
}
internal void FromString(string list) {
char[] _delimiters = { ',' };
if (list != null) {
string[] items = list.Split(_delimiters);
foreach (string item in items) {
string trimmedItem = item.Trim();
if (trimmedItem.Length != 0) {
Add(item.Trim());
}
}
}
_OriginalString = ToString();
_ReadOnly = false;
_Modified = false;
}
public override string ToString() {
string returnString = null;
if (Count > 0) {
StringBuilder sb = new StringBuilder();
foreach (string str in this) {
ThrowIfContainsDelimiter(str); // Since the add methods are not virtual they could still add bad data
// by casting the collection to a string collection. This check will catch
// it before serialization, late is better than never.
sb.Append(str.Trim());
sb.Append(',');
}
returnString = sb.ToString();
if (returnString.Length > 0) {
returnString = returnString.Substring(0, returnString.Length - 1);
}
if (returnString.Length == 0) {
returnString = null;
}
}
return returnString;
}
private void ThrowIfReadOnly() {
if (IsReadOnly == true) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
}
}
private void ThrowIfContainsDelimiter(string value) {
if (value.Contains(",")) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_value_cannot_contain,","));
}
}
public void SetReadOnly() {
_ReadOnly = true;
}
public bool IsModified {
get {
return _Modified || (ToString() != _OriginalString);
}
}
public new bool IsReadOnly {
get {
return _ReadOnly;
}
}
//
// Accessors
//
public new string this[int index] {
get {
return (string)base[index];
}
set {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base[index] = value.Trim();
}
}
//
// Methods
//
public new void Add(string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Add(value.Trim());
}
public new void AddRange(string[] range) {
ThrowIfReadOnly();
_Modified = true;
foreach (string str in range) {
ThrowIfContainsDelimiter(str);
base.Add(str.Trim());
}
}
public new void Clear() {
ThrowIfReadOnly();
_Modified = true;
base.Clear();
}
public new void Insert(int index, string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Insert(index, value.Trim());
}
public new void Remove(string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Remove(value.Trim());
}
// Clone
//
// Clone the object, to get back and object that we can modify
// without changing the original object
//
public CommaDelimitedStringCollection Clone() {
CommaDelimitedStringCollection copy;
copy = new CommaDelimitedStringCollection();
// Copy all values
foreach (string str in this) {
copy.Add(str);
}
// Copy Attributes
copy._Modified = false;
copy._ReadOnly = _ReadOnly;
copy._OriginalString = _OriginalString;
return copy;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;
namespace System.Configuration {
public sealed class CommaDelimitedStringCollection : StringCollection {
private bool _Modified;
private bool _ReadOnly;
private string _OriginalString;
//
// Constructor
//
public CommaDelimitedStringCollection() {
_ReadOnly = false;
_Modified = false;
_OriginalString = ToString();
}
internal void FromString(string list) {
char[] _delimiters = { ',' };
if (list != null) {
string[] items = list.Split(_delimiters);
foreach (string item in items) {
string trimmedItem = item.Trim();
if (trimmedItem.Length != 0) {
Add(item.Trim());
}
}
}
_OriginalString = ToString();
_ReadOnly = false;
_Modified = false;
}
public override string ToString() {
string returnString = null;
if (Count > 0) {
StringBuilder sb = new StringBuilder();
foreach (string str in this) {
ThrowIfContainsDelimiter(str); // Since the add methods are not virtual they could still add bad data
// by casting the collection to a string collection. This check will catch
// it before serialization, late is better than never.
sb.Append(str.Trim());
sb.Append(',');
}
returnString = sb.ToString();
if (returnString.Length > 0) {
returnString = returnString.Substring(0, returnString.Length - 1);
}
if (returnString.Length == 0) {
returnString = null;
}
}
return returnString;
}
private void ThrowIfReadOnly() {
if (IsReadOnly == true) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
}
}
private void ThrowIfContainsDelimiter(string value) {
if (value.Contains(",")) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_value_cannot_contain,","));
}
}
public void SetReadOnly() {
_ReadOnly = true;
}
public bool IsModified {
get {
return _Modified || (ToString() != _OriginalString);
}
}
public new bool IsReadOnly {
get {
return _ReadOnly;
}
}
//
// Accessors
//
public new string this[int index] {
get {
return (string)base[index];
}
set {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base[index] = value.Trim();
}
}
//
// Methods
//
public new void Add(string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Add(value.Trim());
}
public new void AddRange(string[] range) {
ThrowIfReadOnly();
_Modified = true;
foreach (string str in range) {
ThrowIfContainsDelimiter(str);
base.Add(str.Trim());
}
}
public new void Clear() {
ThrowIfReadOnly();
_Modified = true;
base.Clear();
}
public new void Insert(int index, string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Insert(index, value.Trim());
}
public new void Remove(string value) {
ThrowIfReadOnly();
ThrowIfContainsDelimiter(value);
_Modified = true;
base.Remove(value.Trim());
}
// Clone
//
// Clone the object, to get back and object that we can modify
// without changing the original object
//
public CommaDelimitedStringCollection Clone() {
CommaDelimitedStringCollection copy;
copy = new CommaDelimitedStringCollection();
// Copy all values
foreach (string str in this) {
copy.Add(str);
}
// Copy Attributes
copy._Modified = false;
copy._ReadOnly = _ReadOnly;
copy._OriginalString = _OriginalString;
return copy;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OracleParameterBinding.cs
- StrongNameMembershipCondition.cs
- EncryptedHeaderXml.cs
- RegexTree.cs
- TextOutput.cs
- DiagnosticStrings.cs
- AtomContentProperty.cs
- ArgIterator.cs
- RenderDataDrawingContext.cs
- KeyPressEvent.cs
- FrameworkTextComposition.cs
- SiteMapPath.cs
- DirtyTextRange.cs
- SiteMapNodeItem.cs
- _UriSyntax.cs
- KoreanCalendar.cs
- WizardStepBase.cs
- GcHandle.cs
- DataColumnCollection.cs
- RequestBringIntoViewEventArgs.cs
- MouseEventArgs.cs
- ClientProxyGenerator.cs
- WhitespaceRuleLookup.cs
- KeyProperty.cs
- IisTraceListener.cs
- GridSplitterAutomationPeer.cs
- UnknownWrapper.cs
- CombinedGeometry.cs
- HttpResponseHeader.cs
- ToolTipService.cs
- JournalEntryListConverter.cs
- RightsManagementEncryptionTransform.cs
- SerializerProvider.cs
- VisualBasic.cs
- ReflectionUtil.cs
- OutOfMemoryException.cs
- TemplateField.cs
- ActionNotSupportedException.cs
- ActivityWithResultWrapper.cs
- WorkerRequest.cs
- ReturnValue.cs
- MarshalByRefObject.cs
- PropertyDescriptorCollection.cs
- Enumerable.cs
- LinkDescriptor.cs
- FormatException.cs
- ElementNotAvailableException.cs
- SqlTriggerContext.cs
- MailWebEventProvider.cs
- CodeTypeDelegate.cs
- PointF.cs
- LateBoundBitmapDecoder.cs
- ComAdminInterfaces.cs
- CompiledXpathExpr.cs
- DateTimeSerializationSection.cs
- EncryptedData.cs
- XMLSchema.cs
- Choices.cs
- FileSecurity.cs
- PageSettings.cs
- TextBoxBase.cs
- HtmlGenericControl.cs
- XmlWriterSettings.cs
- DtdParser.cs
- Invariant.cs
- DefaultBindingPropertyAttribute.cs
- DataControlReferenceCollection.cs
- SoapReflectionImporter.cs
- PlaceHolder.cs
- FilteredDataSetHelper.cs
- MoveSizeWinEventHandler.cs
- OutputCacheProfileCollection.cs
- SystemKeyConverter.cs
- EntityDataSourceValidationException.cs
- WindowsGraphics2.cs
- WindowsComboBox.cs
- ACE.cs
- CheckBoxRenderer.cs
- QuaternionAnimationUsingKeyFrames.cs
- XmlWhitespace.cs
- CopyOnWriteList.cs
- ImageSource.cs
- HttpFileCollection.cs
- CmsInterop.cs
- EncodingInfo.cs
- UnmanagedMarshal.cs
- PathFigureCollection.cs
- SafeTimerHandle.cs
- ToolBarButton.cs
- TextAutomationPeer.cs
- PermissionSetEnumerator.cs
- DataTableCollection.cs
- CustomSignedXml.cs
- Int64Storage.cs
- RoleGroupCollection.cs
- ShaperBuffers.cs
- objectquery_tresulttype.cs
- ExpressionWriter.cs
- RelationshipManager.cs
- WmfPlaceableFileHeader.cs