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
- XmlSerializer.cs
- BaseCollection.cs
- WarningException.cs
- CaseStatement.cs
- ColorAnimationBase.cs
- assemblycache.cs
- ZoneButton.cs
- ClientScriptManager.cs
- LinearQuaternionKeyFrame.cs
- PeerApplication.cs
- ConfigurationManagerHelper.cs
- Command.cs
- TextDecoration.cs
- CardSpacePolicyElement.cs
- TreeNodeBindingCollection.cs
- DateTimeParse.cs
- ImportedNamespaceContextItem.cs
- TriggerAction.cs
- EntityCommandCompilationException.cs
- CheckedPointers.cs
- MaterialGroup.cs
- MenuCommands.cs
- RadialGradientBrush.cs
- TextBox.cs
- AmbientValueAttribute.cs
- HtmlElementEventArgs.cs
- ResourceContainer.cs
- MetaDataInfo.cs
- RegularExpressionValidator.cs
- AutoFocusStyle.xaml.cs
- ToolStripItemRenderEventArgs.cs
- PolygonHotSpot.cs
- LongCountAggregationOperator.cs
- DBSchemaTable.cs
- FacetValues.cs
- SizeAnimationBase.cs
- PrivateFontCollection.cs
- ConfigurationManager.cs
- RawStylusActions.cs
- InputLangChangeEvent.cs
- ActivityAction.cs
- UIElementIsland.cs
- EntryPointNotFoundException.cs
- UInt16Converter.cs
- AssociationSet.cs
- XmlAggregates.cs
- ResourceSetExpression.cs
- KeyConstraint.cs
- MergeFilterQuery.cs
- EditorPartCollection.cs
- DatatypeImplementation.cs
- ListViewUpdatedEventArgs.cs
- DataColumn.cs
- RequestQueue.cs
- InkCanvasSelection.cs
- AuthenticationModuleElement.cs
- ObservableCollection.cs
- MetabaseServerConfig.cs
- UnauthorizedWebPart.cs
- KnownTypeHelper.cs
- XmlDesignerDataSourceView.cs
- ResourceReferenceKeyNotFoundException.cs
- OleDbStruct.cs
- XmlPreloadedResolver.cs
- RequiredFieldValidator.cs
- OleServicesContext.cs
- ReceiveErrorHandling.cs
- NativeMethods.cs
- CompoundFileDeflateTransform.cs
- ModuleElement.cs
- IntSecurity.cs
- DataRelationCollection.cs
- WorkflowInstanceQuery.cs
- Page.cs
- ChooseAction.cs
- Emitter.cs
- LabelAutomationPeer.cs
- CssStyleCollection.cs
- ObsoleteAttribute.cs
- BindingWorker.cs
- SqlBuffer.cs
- DiagnosticTraceRecords.cs
- FormViewModeEventArgs.cs
- OpenTypeCommon.cs
- TextChangedEventArgs.cs
- RayMeshGeometry3DHitTestResult.cs
- ADRoleFactory.cs
- Converter.cs
- SparseMemoryStream.cs
- StrokeSerializer.cs
- XmlDictionaryReaderQuotas.cs
- SqlUtil.cs
- EventKeyword.cs
- DataGridViewDataConnection.cs
- HtmlWindow.cs
- DbBuffer.cs
- SiteMapNodeCollection.cs
- HyperLinkColumn.cs
- Token.cs
- WebAdminConfigurationHelper.cs