Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ChannelPool.cs
- ContextActivityUtils.cs
- Matrix.cs
- SymbolDocumentGenerator.cs
- IndexedString.cs
- VisualStyleElement.cs
- TypeBinaryExpression.cs
- AmbientEnvironment.cs
- HostedImpersonationContext.cs
- SafeHandles.cs
- Endpoint.cs
- ExpressionParser.cs
- ColumnWidthChangedEvent.cs
- ApplicationCommands.cs
- DecimalAnimation.cs
- Thread.cs
- xmlglyphRunInfo.cs
- Rect3D.cs
- PrintPageEvent.cs
- XPathNavigatorReader.cs
- UTF32Encoding.cs
- DefaultBindingPropertyAttribute.cs
- CodeIdentifiers.cs
- ResXResourceSet.cs
- ToolboxItemCollection.cs
- LiteralControl.cs
- SoapElementAttribute.cs
- KernelTypeValidation.cs
- CopyEncoder.cs
- CodeCompileUnit.cs
- GroupDescription.cs
- DependencyPropertyValueSerializer.cs
- LoadWorkflowByKeyAsyncResult.cs
- ClientSettingsProvider.cs
- VersionedStreamOwner.cs
- WebScriptMetadataMessageEncodingBindingElement.cs
- MethodBody.cs
- ObjectAnimationUsingKeyFrames.cs
- SBCSCodePageEncoding.cs
- DocumentApplicationJournalEntryEventArgs.cs
- ToolStripPanelRow.cs
- StreamResourceInfo.cs
- DispatcherHooks.cs
- WinHttpWebProxyFinder.cs
- ToolStripLabel.cs
- ClientConfigPaths.cs
- PreservationFileWriter.cs
- ListViewDataItem.cs
- DataPagerCommandEventArgs.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- VisualStyleRenderer.cs
- SchemaImporterExtensionElement.cs
- MimeFormReflector.cs
- DebuggerAttributes.cs
- KeyManager.cs
- ToolStripSeparatorRenderEventArgs.cs
- BamlRecords.cs
- GenericWebPart.cs
- LostFocusEventManager.cs
- CmsInterop.cs
- DebugView.cs
- documentation.cs
- _AuthenticationState.cs
- SoapFault.cs
- DesignerSerializerAttribute.cs
- MethodBody.cs
- RelativeSource.cs
- DesignerAutoFormat.cs
- glyphs.cs
- HwndSource.cs
- XmlSchemaGroup.cs
- HtmlAnchor.cs
- DataListAutoFormat.cs
- PropertyPathConverter.cs
- CodeDirectionExpression.cs
- Dictionary.cs
- IconEditor.cs
- EastAsianLunisolarCalendar.cs
- TemplateControl.cs
- DatePickerDateValidationErrorEventArgs.cs
- MergablePropertyAttribute.cs
- WindowsGraphicsCacheManager.cs
- MetabaseServerConfig.cs
- WebEventCodes.cs
- _DisconnectOverlappedAsyncResult.cs
- XamlFxTrace.cs
- KeyBinding.cs
- LocatorGroup.cs
- BufferManager.cs
- MsmqIntegrationSecurity.cs
- PropertyGridEditorPart.cs
- HMACSHA256.cs
- TemplateComponentConnector.cs
- UnicodeEncoding.cs
- ThicknessKeyFrameCollection.cs
- TokenizerHelper.cs
- XmlSecureResolver.cs
- FixedSOMFixedBlock.cs
- ListViewItemEventArgs.cs
- ScopelessEnumAttribute.cs