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
- ClientUtils.cs
- BuiltInExpr.cs
- VectorAnimationUsingKeyFrames.cs
- TextDecorationUnitValidation.cs
- Pen.cs
- PathFigureCollection.cs
- RoutedEventConverter.cs
- ComponentDispatcherThread.cs
- BigIntegerStorage.cs
- AutomationPatternInfo.cs
- PnrpPermission.cs
- SortQuery.cs
- Events.cs
- LassoHelper.cs
- RotateTransform3D.cs
- ToolStripComboBox.cs
- PageBorderless.cs
- SoapFault.cs
- DataGridViewTextBoxCell.cs
- Vector3DCollection.cs
- MobileErrorInfo.cs
- D3DImage.cs
- FileLogRecord.cs
- ValuePattern.cs
- COM2ExtendedUITypeEditor.cs
- IntSecurity.cs
- XmlIncludeAttribute.cs
- DBSqlParserColumnCollection.cs
- OwnerDrawPropertyBag.cs
- DbInsertCommandTree.cs
- ConfigurationManagerHelper.cs
- QueryCacheManager.cs
- RadioButtonStandardAdapter.cs
- CustomAttributeFormatException.cs
- ImplicitInputBrush.cs
- ProgressPage.cs
- Semaphore.cs
- TextServicesDisplayAttributePropertyRanges.cs
- PenContexts.cs
- PropertyBuilder.cs
- wmiprovider.cs
- TimeZone.cs
- DataPagerFieldCommandEventArgs.cs
- SystemInfo.cs
- DotExpr.cs
- LogPolicy.cs
- PointLightBase.cs
- EventLogEntry.cs
- Win32PrintDialog.cs
- XmlSerializationGeneratedCode.cs
- ChildTable.cs
- RepeaterItemCollection.cs
- AppDomainFactory.cs
- FileRegion.cs
- WebScriptServiceHost.cs
- DateTimeFormatInfoScanner.cs
- FirstQueryOperator.cs
- QueryCacheKey.cs
- ComponentDispatcherThread.cs
- odbcmetadatacolumnnames.cs
- SemanticTag.cs
- Vector3DCollection.cs
- InlineCollection.cs
- DetailsViewRow.cs
- NetworkAddressChange.cs
- Zone.cs
- Stylesheet.cs
- _BufferOffsetSize.cs
- AssociationTypeEmitter.cs
- ProxyWebPartConnectionCollection.cs
- RolePrincipal.cs
- BaseCollection.cs
- AttributeConverter.cs
- TextDecorations.cs
- RuleDefinitions.cs
- GeneratedCodeAttribute.cs
- BufferedGenericXmlSecurityToken.cs
- LogRecordSequence.cs
- ViewKeyConstraint.cs
- _ScatterGatherBuffers.cs
- complextypematerializer.cs
- TextRunProperties.cs
- ArithmeticLiteral.cs
- StringAnimationUsingKeyFrames.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- TypeResolvingOptions.cs
- AsymmetricSignatureDeformatter.cs
- StyleModeStack.cs
- BaseInfoTable.cs
- ListBox.cs
- ValuePatternIdentifiers.cs
- TimeSpanMinutesConverter.cs
- TraceUtility.cs
- Bitmap.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- Registry.cs
- MouseOverProperty.cs
- TraceHandler.cs
- SegmentInfo.cs
- EntityContainerAssociationSet.cs