Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Base / System / Windows / Markup / RuntimeIdentifierPropertyAttribute.cs / 2 / 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: [....] 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
- MultipleViewPattern.cs
- DataViewSetting.cs
- TokenBasedSetEnumerator.cs
- HtmlInputCheckBox.cs
- FeatureSupport.cs
- AutomationTextAttribute.cs
- ModelToObjectValueConverter.cs
- DebugInfoGenerator.cs
- FilterEventArgs.cs
- UidManager.cs
- TypeToStringValueConverter.cs
- HttpHeaderCollection.cs
- WindowsTitleBar.cs
- StylusPointCollection.cs
- InfoCardAsymmetricCrypto.cs
- TemplateParser.cs
- PTConverter.cs
- Image.cs
- TemplateComponentConnector.cs
- SchemaNotation.cs
- MultiBindingExpression.cs
- SystemResourceHost.cs
- DbParameterHelper.cs
- CodeTypeReferenceExpression.cs
- JoinElimination.cs
- UserInitiatedRoutedEventPermission.cs
- HMACSHA1.cs
- RequiredAttributeAttribute.cs
- DiffuseMaterial.cs
- AnimationClock.cs
- StagingAreaInputItem.cs
- SpellerHighlightLayer.cs
- ConfigsHelper.cs
- IPAddress.cs
- Activity.cs
- KeyTime.cs
- ToolStripSeparatorRenderEventArgs.cs
- ExtentCqlBlock.cs
- MessageContractMemberAttribute.cs
- OracleCommandSet.cs
- _FtpControlStream.cs
- OptimizerPatterns.cs
- ReadOnlyDataSourceView.cs
- WorkerRequest.cs
- SQLGuid.cs
- LeafCellTreeNode.cs
- MimeXmlReflector.cs
- ServiceRouteHandler.cs
- DataGridComponentEditor.cs
- SqlDataAdapter.cs
- DataGridItemCollection.cs
- XpsDocument.cs
- PropertyBuilder.cs
- BuilderInfo.cs
- SpecularMaterial.cs
- ImageAttributes.cs
- WebPartCatalogCloseVerb.cs
- TemplateBamlRecordReader.cs
- ListViewUpdatedEventArgs.cs
- CultureTableRecord.cs
- EmptyControlCollection.cs
- VectorValueSerializer.cs
- DataGridColumnCollection.cs
- NativeCompoundFileAPIs.cs
- FormViewPageEventArgs.cs
- BaseInfoTable.cs
- AppDomainUnloadedException.cs
- FakeModelItemImpl.cs
- NativeMethods.cs
- BlobPersonalizationState.cs
- CalendarTable.cs
- DataSourceControlBuilder.cs
- PackagePartCollection.cs
- DiagnosticsConfigurationHandler.cs
- ServiceOperation.cs
- Point3DConverter.cs
- TaskHelper.cs
- TypeEnumerableViewSchema.cs
- TextContainerHelper.cs
- _HTTPDateParse.cs
- BufferedWebEventProvider.cs
- GenericUriParser.cs
- GeneralTransform.cs
- DelegatingConfigHost.cs
- ValidationPropertyAttribute.cs
- TransformerConfigurationWizardBase.cs
- RoutedCommand.cs
- TemplatePropertyEntry.cs
- ICollection.cs
- TrackingDataItemValue.cs
- BezierSegment.cs
- XomlCompilerParameters.cs
- NetworkAddressChange.cs
- Point.cs
- DeleteHelper.cs
- DataGridItemEventArgs.cs
- DesignerObject.cs
- ScalarOps.cs
- AssociationSetMetadata.cs
- PassportAuthenticationModule.cs