Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / _UriTypeConverter.cs / 1 / _UriTypeConverter.cs
/*++ Copyright (c) 2003 Microsoft Corporation Module Name: _UriTypeConverter.cs Abstract: A default TypeConverter implementation for the System.Uri type Revision History: --*/ namespace System { using System.Globalization; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; // // A limited conversion is implemented such as to and from string // A conversion to InstanceDescriptor is also provided for design time support. // public class UriTypeConverter: TypeConverter { private UriKind m_UriKind; public UriTypeConverter() : this(UriKind.RelativeOrAbsolute) { } internal UriTypeConverter(UriKind uriKind) { m_UriKind = uriKind; } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == null) throw new ArgumentNullException("sourceType"); if (sourceType == typeof(string)) return true; if (typeof(Uri).IsAssignableFrom(sourceType)) return true; return base.CanConvertFrom(context, sourceType); } // public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; if (destinationType == typeof(string)) return true; if (destinationType == typeof(Uri)) return true; return base.CanConvertTo(context, destinationType); } // public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string uriString = value as string; if (uriString != null) return new Uri(uriString, m_UriKind); Uri uri = value as Uri; if (uri != null) return new Uri(uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind); return base.ConvertFrom(context, culture, value); } // public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { Uri uri = value as Uri; if (uri != null && destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(Uri).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[]{typeof(string), typeof(UriKind)}, null); return new InstanceDescriptor(ci, new object[] { uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind }); } if (uri != null && destinationType == typeof(string)) return uri.OriginalString; if (uri != null && destinationType == typeof(Uri)) return new Uri(uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind); return base.ConvertTo(context, culture, value, destinationType); } // public override bool IsValid(ITypeDescriptorContext context, object value) { string str = value as string; Uri temp; if (str != null) return Uri.TryCreate(str, m_UriKind, out temp); return value is Uri; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /*++ Copyright (c) 2003 Microsoft Corporation Module Name: _UriTypeConverter.cs Abstract: A default TypeConverter implementation for the System.Uri type Revision History: --*/ namespace System { using System.Globalization; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; // // A limited conversion is implemented such as to and from string // A conversion to InstanceDescriptor is also provided for design time support. // public class UriTypeConverter: TypeConverter { private UriKind m_UriKind; public UriTypeConverter() : this(UriKind.RelativeOrAbsolute) { } internal UriTypeConverter(UriKind uriKind) { m_UriKind = uriKind; } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == null) throw new ArgumentNullException("sourceType"); if (sourceType == typeof(string)) return true; if (typeof(Uri).IsAssignableFrom(sourceType)) return true; return base.CanConvertFrom(context, sourceType); } // public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) return true; if (destinationType == typeof(string)) return true; if (destinationType == typeof(Uri)) return true; return base.CanConvertTo(context, destinationType); } // public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string uriString = value as string; if (uriString != null) return new Uri(uriString, m_UriKind); Uri uri = value as Uri; if (uri != null) return new Uri(uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind); return base.ConvertFrom(context, culture, value); } // public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { Uri uri = value as Uri; if (uri != null && destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(Uri).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[]{typeof(string), typeof(UriKind)}, null); return new InstanceDescriptor(ci, new object[] { uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind }); } if (uri != null && destinationType == typeof(string)) return uri.OriginalString; if (uri != null && destinationType == typeof(Uri)) return new Uri(uri.OriginalString, m_UriKind == UriKind.RelativeOrAbsolute ? uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative : m_UriKind); return base.ConvertTo(context, culture, value, destinationType); } // public override bool IsValid(ITypeDescriptorContext context, object value) { string str = value as string; Uri temp; if (str != null) return Uri.TryCreate(str, m_UriKind, out temp); return value is Uri; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XsdDateTime.cs
- BufferBuilder.cs
- RecordsAffectedEventArgs.cs
- sqlpipe.cs
- CacheEntry.cs
- XmlSerializationReader.cs
- UnitControl.cs
- WeakHashtable.cs
- BaseDataList.cs
- QuaternionRotation3D.cs
- SmiEventSink.cs
- ListCollectionView.cs
- KeyValuePairs.cs
- AutoGeneratedField.cs
- WorkflowQueueInfo.cs
- DynamicMetaObject.cs
- ClientBuildManager.cs
- XmlSchemaSimpleType.cs
- SQLInt32.cs
- WebConfigurationHost.cs
- FusionWrap.cs
- IconEditor.cs
- CodeVariableDeclarationStatement.cs
- EventArgs.cs
- ColumnResizeUndoUnit.cs
- MultiTrigger.cs
- HttpCacheParams.cs
- HeaderedContentControl.cs
- InputScopeNameConverter.cs
- _Events.cs
- MenuItemAutomationPeer.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- LeaseManager.cs
- GeneralTransform2DTo3D.cs
- XamlFxTrace.cs
- WebBrowserEvent.cs
- TextParagraphView.cs
- IImplicitResourceProvider.cs
- XmlStreamNodeWriter.cs
- OdbcFactory.cs
- OAVariantLib.cs
- ComponentSerializationService.cs
- MyContact.cs
- FontNameEditor.cs
- EnumBuilder.cs
- MouseEventArgs.cs
- ListBoxItemAutomationPeer.cs
- ThemeableAttribute.cs
- Imaging.cs
- PointLight.cs
- BoundingRectTracker.cs
- Semaphore.cs
- IntSecurity.cs
- PrintControllerWithStatusDialog.cs
- IfAction.cs
- ComNativeDescriptor.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- oledbmetadatacollectionnames.cs
- MimeMultiPart.cs
- PassportAuthenticationModule.cs
- DoubleLinkListEnumerator.cs
- HttpProfileBase.cs
- mda.cs
- BooleanAnimationUsingKeyFrames.cs
- CookieParameter.cs
- EntityType.cs
- COM2TypeInfoProcessor.cs
- __ConsoleStream.cs
- MessageQueuePermission.cs
- ICspAsymmetricAlgorithm.cs
- OracleConnection.cs
- versioninfo.cs
- SQLDecimalStorage.cs
- TextLine.cs
- DigitShape.cs
- FacetChecker.cs
- RuntimeIdentifierPropertyAttribute.cs
- EventRoute.cs
- DataGridRowHeader.cs
- ZipPackage.cs
- TailPinnedEventArgs.cs
- ErrorFormatter.cs
- RepeaterItemEventArgs.cs
- UnsafeNativeMethodsTablet.cs
- WorkflowView.cs
- CryptoApi.cs
- XmlBufferReader.cs
- PerformanceCounter.cs
- Win32Exception.cs
- GroupQuery.cs
- BlockCollection.cs
- HttpCachePolicyElement.cs
- SQLGuid.cs
- FileFormatException.cs
- PropertyDescriptorCollection.cs
- xdrvalidator.cs
- PartEditor.cs
- ServiceHostingEnvironment.cs
- Adorner.cs
- ApplicationCommands.cs