Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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. //------------------------------------------------------------------------------ //[To be supplied.] ///// 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.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HyperLinkStyle.cs
- SplineKeyFrames.cs
- CompilerTypeWithParams.cs
- ToolStripDesignerAvailabilityAttribute.cs
- AdapterUtil.cs
- TcpPortSharing.cs
- HelpKeywordAttribute.cs
- FilteredDataSetHelper.cs
- SchemaCompiler.cs
- KeyTimeConverter.cs
- SqlDependencyUtils.cs
- processwaithandle.cs
- WebRequest.cs
- TextBoxView.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- IdentifierCollection.cs
- DataGridParentRows.cs
- SqlConnectionStringBuilder.cs
- __Filters.cs
- TextElementAutomationPeer.cs
- MimeAnyImporter.cs
- RawStylusInputReport.cs
- ImageSourceConverter.cs
- DesignerOptionService.cs
- MediaContext.cs
- Guid.cs
- XmlSerializationReader.cs
- UserControl.cs
- oledbconnectionstring.cs
- ValidationSummary.cs
- CmsUtils.cs
- LineVisual.cs
- XmlNamespaceDeclarationsAttribute.cs
- DataRecordInfo.cs
- ShapeTypeface.cs
- NonBatchDirectoryCompiler.cs
- EmptyReadOnlyDictionaryInternal.cs
- OverloadGroupAttribute.cs
- SecondaryViewProvider.cs
- WebFaultException.cs
- SingleAnimationBase.cs
- MaterialGroup.cs
- SafeNativeMethods.cs
- AdministrationHelpers.cs
- TableItemProviderWrapper.cs
- AuthorizationContext.cs
- SrgsText.cs
- KernelTypeValidation.cs
- TemplateKeyConverter.cs
- SerializationFieldInfo.cs
- DrawingContextDrawingContextWalker.cs
- HttpCapabilitiesEvaluator.cs
- IteratorAsyncResult.cs
- InfocardInteractiveChannelInitializer.cs
- TypeValidationEventArgs.cs
- EpmTargetTree.cs
- EmptyReadOnlyDictionaryInternal.cs
- AdPostCacheSubstitution.cs
- BCryptNative.cs
- PeerTransportListenAddressValidatorAttribute.cs
- UserThread.cs
- StreamInfo.cs
- XmlHierarchicalEnumerable.cs
- FixedTextPointer.cs
- MissingFieldException.cs
- CurrencyManager.cs
- AutomationEvent.cs
- TemplateBaseAction.cs
- TextOutput.cs
- ComPlusContractBehavior.cs
- HtmlSelect.cs
- CardSpaceShim.cs
- EditorAttributeInfo.cs
- FileChangesMonitor.cs
- FrugalList.cs
- HttpMethodAttribute.cs
- LogReserveAndAppendState.cs
- ElementUtil.cs
- RtType.cs
- PageMediaSize.cs
- SoapMessage.cs
- FamilyMapCollection.cs
- FormParameter.cs
- GatewayIPAddressInformationCollection.cs
- _SSPISessionCache.cs
- CodeMethodInvokeExpression.cs
- PersistenceTypeAttribute.cs
- AdRotatorDesigner.cs
- EncryptedKey.cs
- ManualResetEventSlim.cs
- InternalTransaction.cs
- ToolBarDesigner.cs
- C14NUtil.cs
- ListenerSessionConnection.cs
- StringAnimationBase.cs
- AsnEncodedData.cs
- hresults.cs
- ParenExpr.cs
- HuffCodec.cs
- FilteredAttributeCollection.cs