Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / VBIdentifierName.cs / 1407647 / VBIdentifierName.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Windows; using Microsoft.VisualBasic; using System.CodeDom.Compiler; using System.Globalization; using System.ComponentModel; using System.Xaml; using System.Xml; internal class VBIdentifierName : DependencyObject { public static readonly DependencyProperty IdentifierNameProperty = DependencyProperty.Register("IdentifierName", typeof(string), typeof(VBIdentifierName), new UIPropertyMetadata(OnIdentifierNameChanged)); public static readonly DependencyProperty IsValidProperty = DependencyProperty.Register("IsValid", typeof(bool), typeof(VBIdentifierName)); public static readonly DependencyProperty ErrorMessageProperty = DependencyProperty.Register("ErrorMessage", typeof(string), typeof(VBIdentifierName)); static VBCodeProvider vbProvider; static XamlSchemaContext xamlContext = new XamlSchemaContext(); static XamlType xamlType = new XamlType(typeof(string), xamlContext); bool checkAgainstXaml; VBCodeProvider VBProvider { get { if (vbProvider == null) { vbProvider = CodeDomProvider.CreateProvider("VisualBasic") as VBCodeProvider; } return vbProvider; } } public string ErrorMessage { get { return (string)GetValue(ErrorMessageProperty); } set { SetValue(ErrorMessageProperty, value); } } public bool IsValid { get { return (bool)GetValue(IsValidProperty); } set { SetValue(IsValidProperty, value); } } public string IdentifierName { get { return (string)GetValue(IdentifierNameProperty); } set { SetValue(IdentifierNameProperty, value); } } public bool CheckAgainstXaml { get { return this.checkAgainstXaml; } } public VBIdentifierName() { this.checkAgainstXaml = false; } public VBIdentifierName(bool checkAgainstXaml) { this.checkAgainstXaml = checkAgainstXaml; } static void OnIdentifierNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ((VBIdentifierName)sender).OnIdentifierNameChanged(); } internal static bool IsValidXamlName(string name) { bool isValid = new XamlMember(name, xamlType, false).IsNameValid; if (isValid) { //Work around TFS bug #825815, in some cases, XamlMember.IsNameValid returns true but it's not valid Xml Name. try { XmlConvert.VerifyName(name); } catch (XmlException) { isValid = false; } } return isValid; } void OnIdentifierNameChanged() { string trimedName = this.IdentifierName; if (this.CheckAgainstXaml && !VBIdentifierName.IsValidXamlName(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidXamlMemberName, trimedName); } else if(!this.VBProvider.IsValidIdentifier(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidVisualBasicIdentifier, trimedName); } else if (trimedName.StartsWith("[", StringComparison.Ordinal) && trimedName.EndsWith("]", StringComparison.Ordinal)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidVisualBasicIdentifier, trimedName); } else { this.IsValid = true; this.ErrorMessage = string.Empty; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Windows; using Microsoft.VisualBasic; using System.CodeDom.Compiler; using System.Globalization; using System.ComponentModel; using System.Xaml; using System.Xml; internal class VBIdentifierName : DependencyObject { public static readonly DependencyProperty IdentifierNameProperty = DependencyProperty.Register("IdentifierName", typeof(string), typeof(VBIdentifierName), new UIPropertyMetadata(OnIdentifierNameChanged)); public static readonly DependencyProperty IsValidProperty = DependencyProperty.Register("IsValid", typeof(bool), typeof(VBIdentifierName)); public static readonly DependencyProperty ErrorMessageProperty = DependencyProperty.Register("ErrorMessage", typeof(string), typeof(VBIdentifierName)); static VBCodeProvider vbProvider; static XamlSchemaContext xamlContext = new XamlSchemaContext(); static XamlType xamlType = new XamlType(typeof(string), xamlContext); bool checkAgainstXaml; VBCodeProvider VBProvider { get { if (vbProvider == null) { vbProvider = CodeDomProvider.CreateProvider("VisualBasic") as VBCodeProvider; } return vbProvider; } } public string ErrorMessage { get { return (string)GetValue(ErrorMessageProperty); } set { SetValue(ErrorMessageProperty, value); } } public bool IsValid { get { return (bool)GetValue(IsValidProperty); } set { SetValue(IsValidProperty, value); } } public string IdentifierName { get { return (string)GetValue(IdentifierNameProperty); } set { SetValue(IdentifierNameProperty, value); } } public bool CheckAgainstXaml { get { return this.checkAgainstXaml; } } public VBIdentifierName() { this.checkAgainstXaml = false; } public VBIdentifierName(bool checkAgainstXaml) { this.checkAgainstXaml = checkAgainstXaml; } static void OnIdentifierNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ((VBIdentifierName)sender).OnIdentifierNameChanged(); } internal static bool IsValidXamlName(string name) { bool isValid = new XamlMember(name, xamlType, false).IsNameValid; if (isValid) { //Work around TFS bug #825815, in some cases, XamlMember.IsNameValid returns true but it's not valid Xml Name. try { XmlConvert.VerifyName(name); } catch (XmlException) { isValid = false; } } return isValid; } void OnIdentifierNameChanged() { string trimedName = this.IdentifierName; if (this.CheckAgainstXaml && !VBIdentifierName.IsValidXamlName(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidXamlMemberName, trimedName); } else if(!this.VBProvider.IsValidIdentifier(trimedName)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidVisualBasicIdentifier, trimedName); } else if (trimedName.StartsWith("[", StringComparison.Ordinal) && trimedName.EndsWith("]", StringComparison.Ordinal)) { this.IsValid = false; this.ErrorMessage = string.Format(CultureInfo.CurrentUICulture, SR.InvalidVisualBasicIdentifier, trimedName); } else { this.IsValid = true; this.ErrorMessage = string.Empty; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Light.cs
- DrawingCollection.cs
- XmlIterators.cs
- TerminateDesigner.cs
- ButtonDesigner.cs
- FormParameter.cs
- ButtonPopupAdapter.cs
- SequenceDesignerAccessibleObject.cs
- MediaElement.cs
- StringToken.cs
- ConfigPathUtility.cs
- GridViewUpdatedEventArgs.cs
- StackOverflowException.cs
- OperationCanceledException.cs
- ConfigurationSchemaErrors.cs
- Int64AnimationUsingKeyFrames.cs
- TableLayoutSettingsTypeConverter.cs
- ToolboxBitmapAttribute.cs
- IncrementalCompileAnalyzer.cs
- SqlUdtInfo.cs
- PostBackOptions.cs
- FieldBuilder.cs
- FormsAuthenticationCredentials.cs
- RuntimeConfigLKG.cs
- QueryOutputWriter.cs
- List.cs
- DataGridSortCommandEventArgs.cs
- DefaultParameterValueAttribute.cs
- HttpPostedFile.cs
- XmlSchemaSequence.cs
- PropertyRecord.cs
- DataGridViewCellStyleChangedEventArgs.cs
- DependencyPropertyConverter.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- MinMaxParagraphWidth.cs
- DuplexClientBase.cs
- _FtpDataStream.cs
- InvalidTimeZoneException.cs
- RijndaelManagedTransform.cs
- Application.cs
- DataReaderContainer.cs
- Ticks.cs
- PassportPrincipal.cs
- GridViewRowPresenterBase.cs
- RemoteWebConfigurationHostStream.cs
- HtmlInputButton.cs
- ManagementOperationWatcher.cs
- WorkingDirectoryEditor.cs
- MsmqHostedTransportConfiguration.cs
- ReliabilityContractAttribute.cs
- MessageBox.cs
- DataServiceQueryOfT.cs
- SafeEventLogWriteHandle.cs
- AssemblyAssociatedContentFileAttribute.cs
- CodeTypeReferenceSerializer.cs
- ContainerControl.cs
- RequestQueryParser.cs
- RealProxy.cs
- HtmlControlPersistable.cs
- Size3DConverter.cs
- EmulateRecognizeCompletedEventArgs.cs
- SelectedGridItemChangedEvent.cs
- PreProcessInputEventArgs.cs
- UnknownBitmapDecoder.cs
- XmlSchemaImporter.cs
- NotSupportedException.cs
- WebDisplayNameAttribute.cs
- MultiView.cs
- basenumberconverter.cs
- SynchronizationHandlesCodeDomSerializer.cs
- TargetException.cs
- PopupRootAutomationPeer.cs
- WindowInteractionStateTracker.cs
- SystemWebSectionGroup.cs
- Rss20ItemFormatter.cs
- XmlWrappingWriter.cs
- XmlAttributes.cs
- WeakRefEnumerator.cs
- JsonClassDataContract.cs
- LoginViewDesigner.cs
- TextServicesProperty.cs
- TriggerBase.cs
- ObjectListCommandEventArgs.cs
- SymbolEqualComparer.cs
- SmtpDigestAuthenticationModule.cs
- Adorner.cs
- WriteableOnDemandPackagePart.cs
- UnhandledExceptionEventArgs.cs
- LocatorManager.cs
- AdornerPresentationContext.cs
- PlanCompilerUtil.cs
- Authorization.cs
- XPathArrayIterator.cs
- DynamicActivityTypeDescriptor.cs
- NavigateEvent.cs
- ContentPropertyAttribute.cs
- _DomainName.cs
- NamespaceMapping.cs
- SplineKeyFrames.cs
- Literal.cs