Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LogWriteRestartAreaState.cs
- ProxyGenerationError.cs
- ComboBox.cs
- CalendarAutoFormat.cs
- GeometryHitTestParameters.cs
- EmptyControlCollection.cs
- WindowsToolbarAsMenu.cs
- Point3DAnimationBase.cs
- HandlerFactoryWrapper.cs
- RemotingSurrogateSelector.cs
- MasterPage.cs
- DataGridViewButtonColumn.cs
- AssemblyAssociatedContentFileAttribute.cs
- HtmlElementEventArgs.cs
- Substitution.cs
- DesignerToolboxInfo.cs
- SignedXmlDebugLog.cs
- CodeExporter.cs
- CompensatableSequenceActivity.cs
- HttpHeaderCollection.cs
- ResourcesGenerator.cs
- Run.cs
- DefaultPropertyAttribute.cs
- Relationship.cs
- XmlWrappingReader.cs
- FileAuthorizationModule.cs
- Convert.cs
- And.cs
- ObjectCloneHelper.cs
- UInt16Converter.cs
- VerificationException.cs
- ExpressionVisitorHelpers.cs
- RawStylusInputCustomData.cs
- ServiceContractViewControl.Designer.cs
- InputElement.cs
- OrthographicCamera.cs
- HttpModulesInstallComponent.cs
- XsltQilFactory.cs
- AstTree.cs
- StateItem.cs
- TextAction.cs
- DataServiceException.cs
- CacheForPrimitiveTypes.cs
- Query.cs
- KeyEventArgs.cs
- UserNameSecurityTokenAuthenticator.cs
- GlobalEventManager.cs
- RMEnrollmentPage3.cs
- DataBinder.cs
- HealthMonitoringSection.cs
- DeobfuscatingStream.cs
- MemoryMappedViewAccessor.cs
- CustomBindingCollectionElement.cs
- Helper.cs
- Point.cs
- WebMethodAttribute.cs
- DeferredSelectedIndexReference.cs
- TextBoxLine.cs
- Switch.cs
- BrowserTree.cs
- ProgressChangedEventArgs.cs
- ByteAnimationUsingKeyFrames.cs
- ScriptManagerProxy.cs
- SystemGatewayIPAddressInformation.cs
- BaseTransportHeaders.cs
- NetSectionGroup.cs
- WeakEventManager.cs
- CompleteWizardStep.cs
- Version.cs
- AncillaryOps.cs
- AppDomainShutdownMonitor.cs
- HandlerBase.cs
- Button.cs
- GeneralTransform3DGroup.cs
- XmlNodeWriter.cs
- EdmToObjectNamespaceMap.cs
- MSHTMLHost.cs
- ObjectFullSpanRewriter.cs
- FixedSOMPageConstructor.cs
- SystemUnicastIPAddressInformation.cs
- FormViewUpdatedEventArgs.cs
- MethodBody.cs
- FixedSOMTextRun.cs
- WebEventTraceProvider.cs
- TypeForwardedToAttribute.cs
- GridEntryCollection.cs
- BoundConstants.cs
- Activator.cs
- DataConnectionHelper.cs
- ControlHelper.cs
- DataSourceCacheDurationConverter.cs
- SoapFormatExtensions.cs
- Utilities.cs
- RC2CryptoServiceProvider.cs
- NavigationPropertyAccessor.cs
- SerialErrors.cs
- DataSourceControlBuilder.cs
- CustomTrackingRecord.cs
- PaperSource.cs
- NestPullup.cs