Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / System / Windows / Markup / RuntimeIdentifierPropertyAttribute.cs / 1305600 / 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; using System.Runtime.CompilerServices; #if PBTCOMPILER namespace MS.Internal.Markup #elif WINDOWS_BASE using MS.Internal.WindowsBase; // FriendAccessAllowed namespace System.Windows.Markup #else namespace System.Windows.Markup #endif { #if !PBTCOMPILER && !TARGETTING35SP1 && !WINDOWS_BASE ////// This attribute is placed on a class to identify the property that will /// function as an Name for the given class /// [AttributeUsage(AttributeTargets.Class)] [TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")] 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 #if !SYSTEM_XAML ////// 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; } } #endif } // 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; using System.Runtime.CompilerServices; #if PBTCOMPILER namespace MS.Internal.Markup #elif WINDOWS_BASE using MS.Internal.WindowsBase; // FriendAccessAllowed namespace System.Windows.Markup #else namespace System.Windows.Markup #endif { #if !PBTCOMPILER && !TARGETTING35SP1 && !WINDOWS_BASE /// /// This attribute is placed on a class to identify the property that will /// function as an Name for the given class /// [AttributeUsage(AttributeTargets.Class)] [TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")] 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 #if !SYSTEM_XAML ////// 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; } } #endif } // 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
- MouseGestureValueSerializer.cs
- RowToFieldTransformer.cs
- ComponentResourceKey.cs
- RoutedCommand.cs
- WebServiceReceiveDesigner.cs
- SmtpMail.cs
- DisplayNameAttribute.cs
- WebPartConnectionsCancelEventArgs.cs
- ExecutionEngineException.cs
- ServicePoint.cs
- PenThreadPool.cs
- DeclarativeConditionsCollection.cs
- rsa.cs
- FrameworkElementAutomationPeer.cs
- QueryException.cs
- TemplatedWizardStep.cs
- SqlRecordBuffer.cs
- recordstatefactory.cs
- RegisteredDisposeScript.cs
- FileDialog_Vista_Interop.cs
- translator.cs
- AliasedSlot.cs
- WindowsComboBox.cs
- QueryOutputWriter.cs
- HttpCookie.cs
- WeakEventManager.cs
- Keyboard.cs
- EventProviderTraceListener.cs
- CodeDomConfigurationHandler.cs
- OleDbParameter.cs
- ValidatorCollection.cs
- FreezableDefaultValueFactory.cs
- NativeMethodsOther.cs
- ExceptionUtil.cs
- _KerberosClient.cs
- VersionedStreamOwner.cs
- CfgRule.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- BrushMappingModeValidation.cs
- ForwardPositionQuery.cs
- AncestorChangedEventArgs.cs
- EdmMember.cs
- _LoggingObject.cs
- AlgoModule.cs
- DataBindingCollection.cs
- UnsafeNativeMethods.cs
- _NegoState.cs
- WaitHandleCannotBeOpenedException.cs
- SqlProcedureAttribute.cs
- DataGridCellsPresenter.cs
- InstanceKeyView.cs
- UnmanagedMemoryAccessor.cs
- MapPathBasedVirtualPathProvider.cs
- ListViewItemCollectionEditor.cs
- WebReferenceOptions.cs
- CompositeFontInfo.cs
- BitmapEffectRenderDataResource.cs
- X509CertificateCollection.cs
- Pool.cs
- RulePatternOps.cs
- FileDialog_Vista_Interop.cs
- CacheChildrenQuery.cs
- Timer.cs
- SignedXmlDebugLog.cs
- FixedLineResult.cs
- GenericParameterDataContract.cs
- ChannelServices.cs
- Size3D.cs
- remotingproxy.cs
- DataRecord.cs
- SiteMapPath.cs
- BrowserInteropHelper.cs
- AddingNewEventArgs.cs
- ValidationEventArgs.cs
- ImageFormat.cs
- WebPartMinimizeVerb.cs
- MimeObjectFactory.cs
- VisualBasicSettingsHandler.cs
- ApplicationHost.cs
- RoutedCommand.cs
- CodeDelegateInvokeExpression.cs
- SQLConvert.cs
- FixedTextView.cs
- ScriptReferenceEventArgs.cs
- CodeSubDirectory.cs
- ManagedWndProcTracker.cs
- TrackingMemoryStream.cs
- DesignerActionTextItem.cs
- PropertyGeneratedEventArgs.cs
- SqlUDTStorage.cs
- InvokeWebServiceDesigner.cs
- ArgumentException.cs
- IFormattable.cs
- BaseProcessProtocolHandler.cs
- ObjectQuery.cs
- bidPrivateBase.cs
- DataListItemCollection.cs
- PhysicalFontFamily.cs
- ProxyElement.cs
- QilInvokeLateBound.cs