Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Activities / System / ServiceModel / XamlIntegration / ServiceXNameTypeConverter.cs / 1305376 / ServiceXNameTypeConverter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.XamlIntegration { using System.ComponentModel; using System.Globalization; using System.Runtime; using System.Xml.Linq; public class ServiceXNameTypeConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return XNameTypeConverterHelper.CanConvertFrom(sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string stringValue = value as string; if (!string.IsNullOrEmpty(stringValue)) { if (!IsQualifiedName(stringValue)) { // We want the name to remain unqualified; we don't want XNameTypeConverter to add the default namespace return XName.Get(stringValue); } } return XNameTypeConverterHelper.ConvertFrom(context, value) ?? base.ConvertFrom(context, culture, value); } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return XNameTypeConverterHelper.CanConvertTo(destinationType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { XName name = value as XName; if (destinationType == typeof(string) && name != null) { if (name.Namespace == XNamespace.None) { // return unqualified name return name.LocalName; } else { string result = (string)(XNameTypeConverterHelper.ConvertTo(context, value, destinationType) ?? base.ConvertTo(context, culture, value, destinationType)); if (IsQualifiedName(result)) { return result; } else { // The name is in the default XAML namespace, so we need to fully-qualify it, // or we'll interpret it as unqualified in ConvertFrom // Also need to escape the {} so it doesn't get interpreted as MarkupExtension return name.ToString().Replace("{","{{").Replace("}","}}"); } } } else { return XNameTypeConverterHelper.ConvertTo(context, value, destinationType) ?? base.ConvertTo(context, culture, value, destinationType); } } bool IsQualifiedName(string name) { return (name.IndexOf(':') >= 1) || (name.Length > 0 && name[0] == '{'); } } } // 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
- _IPv6Address.cs
- ActivationServices.cs
- BinaryCommonClasses.cs
- BinaryOperationBinder.cs
- SetIterators.cs
- BaseComponentEditor.cs
- NonSerializedAttribute.cs
- LinkClickEvent.cs
- DbXmlEnabledProviderManifest.cs
- HttpChannelHelpers.cs
- ReadOnlyDataSource.cs
- IndentedTextWriter.cs
- ConnectionStringSettingsCollection.cs
- GroupBoxDesigner.cs
- HtmlTitle.cs
- Expression.cs
- ScalarRestriction.cs
- HashCodeCombiner.cs
- DashStyle.cs
- DataExpression.cs
- ListItemCollection.cs
- ApplicationServiceManager.cs
- Authorization.cs
- DocumentViewer.cs
- InternalConfigEventArgs.cs
- StackSpiller.Bindings.cs
- Visitor.cs
- ComplexObject.cs
- ZipFileInfoCollection.cs
- ProtocolsConfigurationEntry.cs
- PeerInputChannel.cs
- BrowserCapabilitiesFactory.cs
- TextControl.cs
- ByteRangeDownloader.cs
- CompositionAdorner.cs
- Underline.cs
- CellQuery.cs
- WindowsListViewGroupHelper.cs
- COM2IProvidePropertyBuilderHandler.cs
- FrameworkElementFactory.cs
- GroupBox.cs
- LinkButton.cs
- IgnoreSectionHandler.cs
- SqlCacheDependencySection.cs
- ConvertersCollection.cs
- XmlAnyAttributeAttribute.cs
- SimpleTypeResolver.cs
- BaseCodeDomTreeGenerator.cs
- Font.cs
- IntellisenseTextBox.designer.cs
- BrowserCapabilitiesFactoryBase.cs
- HwndKeyboardInputProvider.cs
- UrlPropertyAttribute.cs
- TableLayoutStyle.cs
- ConfigurationPropertyAttribute.cs
- QuaternionKeyFrameCollection.cs
- FieldBuilder.cs
- JsonServiceDocumentSerializer.cs
- DomainUpDown.cs
- SymbolMethod.cs
- M3DUtil.cs
- CounterCreationDataCollection.cs
- TypeViewSchema.cs
- SqlBooleanizer.cs
- WebPartConnectionsDisconnectVerb.cs
- Screen.cs
- SourceFilter.cs
- EntityConnection.cs
- MethodRental.cs
- FrameworkRichTextComposition.cs
- PointAnimationClockResource.cs
- ZipIOModeEnforcingStream.cs
- InProcStateClientManager.cs
- ToolStripSystemRenderer.cs
- ScopeElementCollection.cs
- WorkflowDesigner.cs
- TextEditorTables.cs
- WindowsPen.cs
- SafeRightsManagementEnvironmentHandle.cs
- PreloadedPackages.cs
- FieldAccessException.cs
- OwnerDrawPropertyBag.cs
- CompilerGlobalScopeAttribute.cs
- _StreamFramer.cs
- PropertyGridCommands.cs
- SmtpFailedRecipientsException.cs
- SelectedDatesCollection.cs
- StringFunctions.cs
- RealizationDrawingContextWalker.cs
- PagePropertiesChangingEventArgs.cs
- XamlDesignerSerializationManager.cs
- DiscoveryServerProtocol.cs
- XmlSchema.cs
- ISCIIEncoding.cs
- PeerTransportCredentialType.cs
- ThrowHelper.cs
- PropertyGroupDescription.cs
- CollectionExtensions.cs
- IntSecurity.cs
- DataGridGeneralPage.cs