Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / System / Windows / Markup / RuntimeIdentifierPropertyAttribute.cs / 1 / RuntimeIdentifierPropertyAttribute.cs
//---------------------------------------------------------------------------- // // File: RuntimeNamePropertyAttribute.cs // // Description: // This attribute is placed on a class to identify the property that will // function as an Name for the given class // // History: // 1/26/05: fmunoz Created // // Copyright (C) 2005 by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Globalization; #if PBTCOMPILER namespace MS.Internal.Markup #else using MS.Internal.WindowsBase; // FriendAccessAllowed namespace System.Windows.Markup #endif { #if !PBTCOMPILER ////// This attribute is placed on a class to identify the property that will /// function as an Name for the given class /// [AttributeUsage(AttributeTargets.Class)] public sealed class RuntimeNamePropertyAttribute: Attribute { ///public RuntimeNamePropertyAttribute(string name) { _name = name; } /// /// The Name of the property in the class that will contain the ID of /// the class, this property needs to be of type string and have /// both get and set access /// public string Name { get { return _name; } } private string _name = null; } #endif ////// The string used in RuntimeNameProperty is expected to follow certain /// rules. IsValidIdentifierName checks the given string against the rules. /// NameValidationCallback extends to all object types and is in the right /// format to be used as a DependencyProperty ValidateValueCallback /// internal static class NameValidationHelper { // When a name string comes in programatically, validate it against the // same rules used by the XAML parser. In XAML scenarios this is // technically redundant since the parser has already checked it against // the same rules, but the parser is able to give a better error message // when it happens. #if !PBTCOMPILER [FriendAccessAllowed] // Built into Base, used by Core and Framework. internal static bool NameValidationCallback(object candidateName) { string name = candidateName as string; if( name != null ) { // Non-null string, ask the XAML validation code for blessing. return IsValidIdentifierName(name); } else if( candidateName == null ) { // Null string is allowed return true; } else { // candiateName is not a string object. return false; } } #endif ////// Validates the name to follow Naming guidelines /// /// string to validate #if !PBTCOMPILER [FriendAccessAllowed] // Built into Base, used by Core and Framework. #endif internal static bool IsValidIdentifierName(string name) { // Grammar: //::= ( | )* // ::= [{Lu}{Ll}{Lt}{Lo}{Nl}('_')] // ::= [{Mn}{Mc}{Lm}{Nd}] UnicodeCategory uc; for (int i = 0; i < name.Length; i++) { uc = Char.GetUnicodeCategory(name[i]); bool idStart = (uc == UnicodeCategory.UppercaseLetter || // (Lu) uc == UnicodeCategory.LowercaseLetter || // (Ll) uc == UnicodeCategory.TitlecaseLetter || // (Lt) uc == UnicodeCategory.OtherLetter || // (Lo) uc == UnicodeCategory.LetterNumber || // (Nl) name[i] == '_'); bool idExtend = (uc == UnicodeCategory.NonSpacingMark || // (Mn) uc == UnicodeCategory.SpacingCombiningMark || // (Mc) uc == UnicodeCategory.ModifierLetter || // (Lm) uc == UnicodeCategory.DecimalDigitNumber); // (Nd) if (i == 0) { if (!idStart) { return false; } } else if (!(idStart || idExtend)) { return false; } } return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // File: RuntimeNamePropertyAttribute.cs // // Description: // This attribute is placed on a class to identify the property that will // function as an Name for the given class // // History: // 1/26/05: fmunoz Created // // Copyright (C) 2005 by Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Globalization; #if PBTCOMPILER namespace MS.Internal.Markup #else using MS.Internal.WindowsBase; // FriendAccessAllowed namespace System.Windows.Markup #endif { #if !PBTCOMPILER /// /// This attribute is placed on a class to identify the property that will /// function as an Name for the given class /// [AttributeUsage(AttributeTargets.Class)] public sealed class RuntimeNamePropertyAttribute: Attribute { ///public RuntimeNamePropertyAttribute(string name) { _name = name; } /// /// The Name of the property in the class that will contain the ID of /// the class, this property needs to be of type string and have /// both get and set access /// public string Name { get { return _name; } } private string _name = null; } #endif ////// The string used in RuntimeNameProperty is expected to follow certain /// rules. IsValidIdentifierName checks the given string against the rules. /// NameValidationCallback extends to all object types and is in the right /// format to be used as a DependencyProperty ValidateValueCallback /// internal static class NameValidationHelper { // When a name string comes in programatically, validate it against the // same rules used by the XAML parser. In XAML scenarios this is // technically redundant since the parser has already checked it against // the same rules, but the parser is able to give a better error message // when it happens. #if !PBTCOMPILER [FriendAccessAllowed] // Built into Base, used by Core and Framework. internal static bool NameValidationCallback(object candidateName) { string name = candidateName as string; if( name != null ) { // Non-null string, ask the XAML validation code for blessing. return IsValidIdentifierName(name); } else if( candidateName == null ) { // Null string is allowed return true; } else { // candiateName is not a string object. return false; } } #endif ////// Validates the name to follow Naming guidelines /// /// string to validate #if !PBTCOMPILER [FriendAccessAllowed] // Built into Base, used by Core and Framework. #endif internal static bool IsValidIdentifierName(string name) { // Grammar: //::= ( | )* // ::= [{Lu}{Ll}{Lt}{Lo}{Nl}('_')] // ::= [{Mn}{Mc}{Lm}{Nd}] UnicodeCategory uc; for (int i = 0; i < name.Length; i++) { uc = Char.GetUnicodeCategory(name[i]); bool idStart = (uc == UnicodeCategory.UppercaseLetter || // (Lu) uc == UnicodeCategory.LowercaseLetter || // (Ll) uc == UnicodeCategory.TitlecaseLetter || // (Lt) uc == UnicodeCategory.OtherLetter || // (Lo) uc == UnicodeCategory.LetterNumber || // (Nl) name[i] == '_'); bool idExtend = (uc == UnicodeCategory.NonSpacingMark || // (Mn) uc == UnicodeCategory.SpacingCombiningMark || // (Mc) uc == UnicodeCategory.ModifierLetter || // (Lm) uc == UnicodeCategory.DecimalDigitNumber); // (Nd) if (i == 0) { if (!idStart) { return false; } } else if (!(idStart || idExtend)) { return false; } } return true; } } } // 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
- ArglessEventHandlerProxy.cs
- AspProxy.cs
- ConfigUtil.cs
- TableLayoutPanelResizeGlyph.cs
- TemplateColumn.cs
- LabelLiteral.cs
- HitTestFilterBehavior.cs
- PersonalizationProvider.cs
- EmptyCollection.cs
- _BaseOverlappedAsyncResult.cs
- DesignerTextBoxAdapter.cs
- Stroke.cs
- RadioButtonFlatAdapter.cs
- WSHttpSecurity.cs
- DoubleAnimationUsingPath.cs
- TrustLevel.cs
- AppDomainUnloadedException.cs
- SqlDependency.cs
- QilStrConcatenator.cs
- PermissionSetEnumerator.cs
- SqlClientMetaDataCollectionNames.cs
- SafeProcessHandle.cs
- ServiceDescriptionImporter.cs
- DESCryptoServiceProvider.cs
- OdbcInfoMessageEvent.cs
- MatcherBuilder.cs
- CultureInfoConverter.cs
- HtmlTableCell.cs
- PartialCachingAttribute.cs
- ToolStripStatusLabel.cs
- FormParameter.cs
- OdbcHandle.cs
- XmlBinaryReader.cs
- SrgsElement.cs
- FormViewCommandEventArgs.cs
- StringFunctions.cs
- Encoder.cs
- XmlIlGenerator.cs
- BridgeDataRecord.cs
- RegistryPermission.cs
- HttpListenerException.cs
- ChangeTracker.cs
- PrivateFontCollection.cs
- IPHostEntry.cs
- FlatButtonAppearance.cs
- ListParaClient.cs
- TreeViewTemplateSelector.cs
- XmlTextAttribute.cs
- TablePatternIdentifiers.cs
- InvalidCommandTreeException.cs
- DataAdapter.cs
- DefaultValueTypeConverter.cs
- OleDbCommandBuilder.cs
- Message.cs
- CommandHelper.cs
- SQLDouble.cs
- Timer.cs
- WindowsUpDown.cs
- BoundColumn.cs
- XmlLinkedNode.cs
- Aggregates.cs
- BitmapCodecInfoInternal.cs
- LoginNameDesigner.cs
- ThreadSafeMessageFilterTable.cs
- XmlSerializerFactory.cs
- StateWorkerRequest.cs
- ModifierKeysConverter.cs
- WebPartMenuStyle.cs
- ValidationContext.cs
- FixedSOMContainer.cs
- XamlGridLengthSerializer.cs
- SqlParameter.cs
- ManagementScope.cs
- WebPartRestoreVerb.cs
- JoinQueryOperator.cs
- ForAllOperator.cs
- DrawingImage.cs
- FormViewUpdatedEventArgs.cs
- EntityClassGenerator.cs
- BufferedGraphicsManager.cs
- ToolboxBitmapAttribute.cs
- RemotingConfigParser.cs
- ScriptBehaviorDescriptor.cs
- EventDescriptorCollection.cs
- SecureEnvironment.cs
- WindowCollection.cs
- ProjectionCamera.cs
- ComNativeDescriptor.cs
- VideoDrawing.cs
- Array.cs
- SubpageParagraph.cs
- WindowsScrollBarBits.cs
- AdapterSwitches.cs
- Table.cs
- UnSafeCharBuffer.cs
- wgx_exports.cs
- EDesignUtil.cs
- Section.cs
- AccessDataSource.cs
- Socket.cs