Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Xml / System / Xml / Serialization / CodeIdentifiers.cs / 1 / CodeIdentifiers.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml.Serialization { using System; using System.Collections; using System.IO; using System.Globalization; class CaseInsensitiveKeyComparer : CaseInsensitiveComparer, IEqualityComparer{ public CaseInsensitiveKeyComparer() : base(CultureInfo.CurrentCulture) { } bool IEqualityComparer.Equals(Object x, Object y) { return (Compare(x, y) == 0); } int IEqualityComparer.GetHashCode(Object obj) { string s = obj as string; if (s == null) throw new ArgumentException(null, "obj"); return s.ToUpper(CultureInfo.CurrentCulture).GetHashCode(); } } ////// /// /// public class CodeIdentifiers { Hashtable identifiers; Hashtable reservedIdentifiers; ArrayList list; bool camelCase; public CodeIdentifiers() : this(true) { } public CodeIdentifiers(bool caseSensitive) { if (caseSensitive) { identifiers = new Hashtable(); reservedIdentifiers = new Hashtable(); } else { IEqualityComparer comparer = new CaseInsensitiveKeyComparer(); identifiers = new Hashtable(comparer); reservedIdentifiers = new Hashtable(comparer); } list = new ArrayList(); } ///[To be supplied.] ///public void Clear(){ identifiers.Clear(); list.Clear(); } /// /// /// public bool UseCamelCasing { get { return camelCase; } set { camelCase = value; } } ///[To be supplied.] ////// /// public string MakeRightCase(string identifier) { if (camelCase) return CodeIdentifier.MakeCamel(identifier); else return CodeIdentifier.MakePascal(identifier); } ///[To be supplied.] ////// /// public string MakeUnique(string identifier) { if (IsInUse(identifier)) { for (int i = 1; ; i++) { string newIdentifier = identifier + i.ToString(CultureInfo.InvariantCulture); if (!IsInUse(newIdentifier)) { identifier = newIdentifier; break; } } } // Check that we did not violate the identifier length after appending the suffix. if (identifier.Length > CodeIdentifier.MaxIdentifierLength) { return MakeUnique("Item"); } return identifier; } ///[To be supplied.] ////// /// public void AddReserved(string identifier) { reservedIdentifiers.Add(identifier, identifier); } ///[To be supplied.] ////// /// public void RemoveReserved(string identifier) { reservedIdentifiers.Remove(identifier); } ///[To be supplied.] ////// /// public string AddUnique(string identifier, object value) { identifier = MakeUnique(identifier); Add(identifier, value); return identifier; } ///[To be supplied.] ////// /// public bool IsInUse(string identifier) { return identifiers.Contains(identifier) || reservedIdentifiers.Contains(identifier); } ///[To be supplied.] ////// /// public void Add(string identifier, object value) { identifiers.Add(identifier, value); list.Add(value); } ///[To be supplied.] ////// /// public void Remove(string identifier) { list.Remove(identifiers[identifier]); identifiers.Remove(identifier); } ///[To be supplied.] ////// /// public object ToArray(Type type) { //Array array = Array.CreateInstance(type, identifiers.Values.Count); //identifiers.Values.CopyTo(array, 0); Array array = Array.CreateInstance(type, list.Count); list.CopyTo(array, 0); return array; } internal CodeIdentifiers Clone() { CodeIdentifiers newIdentifiers = new CodeIdentifiers(); newIdentifiers.identifiers = (Hashtable)this.identifiers.Clone(); newIdentifiers.reservedIdentifiers = (Hashtable)this.reservedIdentifiers.Clone(); newIdentifiers.list = (ArrayList)this.list.Clone(); newIdentifiers.camelCase = this.camelCase; return newIdentifiers; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PingOptions.cs
- JoinGraph.cs
- ExtendedPropertyDescriptor.cs
- ScrollChrome.cs
- SoapProtocolImporter.cs
- OracleLob.cs
- HostedTcpTransportManager.cs
- ContainerParaClient.cs
- Rotation3D.cs
- ClientScriptManagerWrapper.cs
- SerializationInfoEnumerator.cs
- IncrementalReadDecoders.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- CodeAttachEventStatement.cs
- DocumentXPathNavigator.cs
- SortableBindingList.cs
- InvokeMethod.cs
- Clock.cs
- HtmlForm.cs
- FormsAuthenticationModule.cs
- TextBoxRenderer.cs
- sqlnorm.cs
- CFGGrammar.cs
- FormsAuthenticationUser.cs
- ProfileSettings.cs
- ThreadLocal.cs
- RecordConverter.cs
- InstanceOwner.cs
- DbConnectionInternal.cs
- CodePropertyReferenceExpression.cs
- IOException.cs
- CellLabel.cs
- CodeMethodInvokeExpression.cs
- ConversionContext.cs
- MimeBasePart.cs
- Typeface.cs
- HtmlInputHidden.cs
- SignerInfo.cs
- MetricEntry.cs
- ListControl.cs
- TreeChangeInfo.cs
- Debugger.cs
- MsmqHostedTransportManager.cs
- IDictionary.cs
- CheckableControlBaseAdapter.cs
- formatstringdialog.cs
- TrustLevelCollection.cs
- Part.cs
- TargetException.cs
- Debug.cs
- RuntimeComponentFilter.cs
- LogicalExpressionTypeConverter.cs
- FormatException.cs
- entityreference_tresulttype.cs
- LinqDataSource.cs
- ClientType.cs
- Rect.cs
- TableChangeProcessor.cs
- BitmapMetadataEnumerator.cs
- SiteMapHierarchicalDataSourceView.cs
- Preprocessor.cs
- CalendarModeChangedEventArgs.cs
- ConfigurationLockCollection.cs
- CorrelationInitializer.cs
- TTSEngineProxy.cs
- EntityViewGenerator.cs
- SourceFileBuildProvider.cs
- FormattedTextSymbols.cs
- Roles.cs
- HostingEnvironmentSection.cs
- PathParser.cs
- CreatingCookieEventArgs.cs
- CheckStoreFileValidityRequest.cs
- __TransparentProxy.cs
- Task.cs
- SocketAddress.cs
- ParameterCollection.cs
- PrintPageEvent.cs
- SocketConnection.cs
- PixelFormats.cs
- SqlDataSourceTableQuery.cs
- Facet.cs
- SemanticBasicElement.cs
- RNGCryptoServiceProvider.cs
- DeviceSpecificDialogCachedState.cs
- OleDbPermission.cs
- SqlProvider.cs
- MessageQueueAccessControlEntry.cs
- ReflectionPermission.cs
- MeshGeometry3D.cs
- SoapCodeExporter.cs
- __ConsoleStream.cs
- RectAnimationClockResource.cs
- KeyEventArgs.cs
- HandlerMappingMemo.cs
- PageSetupDialog.cs
- XPathSelectionIterator.cs
- PersistenceTypeAttribute.cs
- StringDictionaryCodeDomSerializer.cs
- TableAutomationPeer.cs