Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / _UriTypeConverter.cs / 1305376 / _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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebConfigurationManager.cs
- documentsequencetextcontainer.cs
- TableLayoutCellPaintEventArgs.cs
- HtmlEncodedRawTextWriter.cs
- FacetEnabledSchemaElement.cs
- LambdaCompiler.Address.cs
- RegexTree.cs
- DetailsViewDeletedEventArgs.cs
- HandlerFactoryCache.cs
- recordstatescratchpad.cs
- TdsParserSessionPool.cs
- DataBoundControlHelper.cs
- ImageAttributes.cs
- Subtree.cs
- ResourceSetExpression.cs
- ToolStripSeparatorRenderEventArgs.cs
- GridViewColumnHeaderAutomationPeer.cs
- TdsValueSetter.cs
- InternalsVisibleToAttribute.cs
- MaskedTextProvider.cs
- CurrentChangingEventArgs.cs
- HWStack.cs
- WindowsTooltip.cs
- Publisher.cs
- StreamSecurityUpgradeProvider.cs
- XPathNodeIterator.cs
- EntityContainerEmitter.cs
- ReadOnlyDictionary.cs
- ReferencedCollectionType.cs
- StylusPlugin.cs
- Merger.cs
- WorkBatch.cs
- StringArrayConverter.cs
- WebPartMinimizeVerb.cs
- XmlDigitalSignatureProcessor.cs
- BaseTemplateBuildProvider.cs
- ValidatedMobileControlConverter.cs
- PersistenceTask.cs
- DataBoundLiteralControl.cs
- SHA512.cs
- BaseParser.cs
- QuaternionRotation3D.cs
- DataSourceHelper.cs
- ZipIORawDataFileBlock.cs
- BooleanProjectedSlot.cs
- WebServiceTypeData.cs
- LateBoundBitmapDecoder.cs
- LayoutTable.cs
- ByteKeyFrameCollection.cs
- WebPartManagerDesigner.cs
- TcpConnectionPoolSettingsElement.cs
- PointAnimationUsingKeyFrames.cs
- PolicyManager.cs
- HtmlShimManager.cs
- AudioStateChangedEventArgs.cs
- RSAProtectedConfigurationProvider.cs
- RoutingExtension.cs
- CryptoHelper.cs
- OciLobLocator.cs
- DataGridSortingEventArgs.cs
- LoginCancelEventArgs.cs
- Parallel.cs
- DecoderReplacementFallback.cs
- EventLogRecord.cs
- IsolatedStorageException.cs
- BlurEffect.cs
- XmlHierarchyData.cs
- CatalogPartDesigner.cs
- XamlReaderHelper.cs
- UpdateExpressionVisitor.cs
- TypeLoadException.cs
- Bits.cs
- BaseCollection.cs
- IsolatedStorageFilePermission.cs
- WindowsGraphics2.cs
- HtmlProps.cs
- XmlWriterTraceListener.cs
- ServiceDescriptions.cs
- PositiveTimeSpanValidator.cs
- AsymmetricKeyExchangeDeformatter.cs
- CodeDomDesignerLoader.cs
- MaskInputRejectedEventArgs.cs
- FileClassifier.cs
- SplineQuaternionKeyFrame.cs
- PassportPrincipal.cs
- AttachmentCollection.cs
- HttpListenerResponse.cs
- SchemaInfo.cs
- IndependentAnimationStorage.cs
- IncomingWebRequestContext.cs
- URLMembershipCondition.cs
- InstalledFontCollection.cs
- PersonalizationStateInfoCollection.cs
- TextRange.cs
- SiteMapDataSourceView.cs
- log.cs
- ModelItem.cs
- ApplicationServiceManager.cs
- ProcessInputEventArgs.cs
- PageSetupDialog.cs