Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / XNameTypeConverter.cs / 1305376 / XNameTypeConverter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime; using System.Xaml; using System.Xml.Linq; internal static class XNameTypeConverterHelper { public static bool CanConvertFrom(Type sourceType) { return sourceType == typeof(string); } public static object ConvertFrom(ITypeDescriptorContext context, object value) { return XNameTypeConverterHelper.ConvertFromHelper(context, value); } public static bool CanConvertTo(Type destinationType) { return destinationType == typeof(string); } public static object ConvertTo(ITypeDescriptorContext context, object value, Type destinationType) { return XNameTypeConverterHelper.ConvertToHelper(context, value, destinationType); } internal static object ConvertFromHelper(ITypeDescriptorContext context, object value) { if (value == null) { return null; } String stringValue = value as String; if (stringValue == null) { return null; } stringValue = stringValue.Trim(); if (stringValue == String.Empty) { return null; } IXamlNamespaceResolver resolver = context.GetService(typeof(IXamlNamespaceResolver)) as IXamlNamespaceResolver; if (resolver == null) { return null; } if (stringValue[0] == '{') { return XName.Get(stringValue); } int indexOfColon = stringValue.IndexOf(':'); string prefix, localName; if (indexOfColon >= 0) { prefix = stringValue.Substring(0, indexOfColon); localName = stringValue.Substring(indexOfColon + 1); } else { prefix = string.Empty; localName = stringValue; } string ns = resolver.GetNamespace(prefix); if (ns == null) { throw Fx.Exception.AsError(new FormatException(SRCore.CouldNotResolveNamespacePrefix(prefix))); } return XName.Get(localName, ns); } internal static object ConvertToHelper(ITypeDescriptorContext context, object value, Type destinationType) { XName name = value as XName; if (destinationType == typeof(string) && name != null) { if (context != null) { var lookupPrefix = (INamespacePrefixLookup)context.GetService(typeof(INamespacePrefixLookup)); if (lookupPrefix != null) { string prefix = lookupPrefix.LookupPrefix(name.Namespace.NamespaceName); if (String.IsNullOrEmpty(prefix)) { // Default namespace is in scope // return name.LocalName; } else { return prefix + ":" + name.LocalName; } } } } return null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime; using System.Xaml; using System.Xml.Linq; internal static class XNameTypeConverterHelper { public static bool CanConvertFrom(Type sourceType) { return sourceType == typeof(string); } public static object ConvertFrom(ITypeDescriptorContext context, object value) { return XNameTypeConverterHelper.ConvertFromHelper(context, value); } public static bool CanConvertTo(Type destinationType) { return destinationType == typeof(string); } public static object ConvertTo(ITypeDescriptorContext context, object value, Type destinationType) { return XNameTypeConverterHelper.ConvertToHelper(context, value, destinationType); } internal static object ConvertFromHelper(ITypeDescriptorContext context, object value) { if (value == null) { return null; } String stringValue = value as String; if (stringValue == null) { return null; } stringValue = stringValue.Trim(); if (stringValue == String.Empty) { return null; } IXamlNamespaceResolver resolver = context.GetService(typeof(IXamlNamespaceResolver)) as IXamlNamespaceResolver; if (resolver == null) { return null; } if (stringValue[0] == '{') { return XName.Get(stringValue); } int indexOfColon = stringValue.IndexOf(':'); string prefix, localName; if (indexOfColon >= 0) { prefix = stringValue.Substring(0, indexOfColon); localName = stringValue.Substring(indexOfColon + 1); } else { prefix = string.Empty; localName = stringValue; } string ns = resolver.GetNamespace(prefix); if (ns == null) { throw Fx.Exception.AsError(new FormatException(SRCore.CouldNotResolveNamespacePrefix(prefix))); } return XName.Get(localName, ns); } internal static object ConvertToHelper(ITypeDescriptorContext context, object value, Type destinationType) { XName name = value as XName; if (destinationType == typeof(string) && name != null) { if (context != null) { var lookupPrefix = (INamespacePrefixLookup)context.GetService(typeof(INamespacePrefixLookup)); if (lookupPrefix != null) { string prefix = lookupPrefix.LookupPrefix(name.Namespace.NamespaceName); if (String.IsNullOrEmpty(prefix)) { // Default namespace is in scope // return name.LocalName; } else { return prefix + ":" + name.LocalName; } } } } return null; } } } // 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
- GlyphCache.cs
- DefaultTraceListener.cs
- AtlasWeb.Designer.cs
- WindowsFormsHost.cs
- DataControlFieldHeaderCell.cs
- WsdlBuildProvider.cs
- DateTimeValueSerializerContext.cs
- UnsafeNativeMethods.cs
- ToolStripSettings.cs
- SoundPlayerAction.cs
- XmlWriterTraceListener.cs
- HttpClientCertificate.cs
- _DynamicWinsockMethods.cs
- UnsafeNativeMethodsPenimc.cs
- TableLayoutStyleCollection.cs
- ColumnResult.cs
- ListViewTableCell.cs
- HandlerBase.cs
- PackageRelationship.cs
- ClosableStream.cs
- FieldAccessException.cs
- ErrorCodes.cs
- Base64Decoder.cs
- GenericsInstances.cs
- Types.cs
- DesignerValidationSummaryAdapter.cs
- IndexedString.cs
- SecurityUtils.cs
- DiagnosticTrace.cs
- Vector3DAnimation.cs
- HttpRequestTraceRecord.cs
- ListItem.cs
- Base64Stream.cs
- RoutingSection.cs
- SqlGatherProducedAliases.cs
- SafeThreadHandle.cs
- WebPartsPersonalizationAuthorization.cs
- StringOutput.cs
- CharacterHit.cs
- HtmlSelectionListAdapter.cs
- XmlDeclaration.cs
- ValueSerializerAttribute.cs
- RegexMatch.cs
- StrokeDescriptor.cs
- WebControlsSection.cs
- DataTemplateSelector.cs
- SecurityHelper.cs
- XPathDocumentNavigator.cs
- IdentifierCreationService.cs
- Speller.cs
- XmlDownloadManager.cs
- RecognizedWordUnit.cs
- MenuEventArgs.cs
- HttpContext.cs
- AddInEnvironment.cs
- SapiGrammar.cs
- SQLResource.cs
- BindingWorker.cs
- NameValueSectionHandler.cs
- BaseAsyncResult.cs
- MessageEnumerator.cs
- IntPtr.cs
- MetadataUtil.cs
- ViewLoader.cs
- GeneralTransform2DTo3DTo2D.cs
- ListBase.cs
- ObjRef.cs
- CounterSetInstanceCounterDataSet.cs
- RegexTree.cs
- SqlDelegatedTransaction.cs
- TypeBrowser.xaml.cs
- LinearGradientBrush.cs
- ProviderManager.cs
- DataSourceIDConverter.cs
- ClientTarget.cs
- DelegatedStream.cs
- StringConcat.cs
- RenderData.cs
- EntitySqlException.cs
- CompoundFileIOPermission.cs
- ToolStripContainer.cs
- UrlAuthFailedErrorFormatter.cs
- XPathNodeList.cs
- RepeatBehavior.cs
- XmlMapping.cs
- XmlDigitalSignatureProcessor.cs
- MetaType.cs
- RichTextBox.cs
- DataReceivedEventArgs.cs
- DateTimeSerializationSection.cs
- RotationValidation.cs
- ParallelEnumerable.cs
- WinEventQueueItem.cs
- SiteMap.cs
- ClientScriptManager.cs
- UnsafeNativeMethodsTablet.cs
- FileAuthorizationModule.cs
- X509Certificate2Collection.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- ToolStripSettings.cs