Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- ResourcesGenerator.cs
- PassportPrincipal.cs
- AutomationPropertyInfo.cs
- X509RawDataKeyIdentifierClause.cs
- CompiledAction.cs
- MobileUITypeEditor.cs
- MetadataReference.cs
- TransformerInfoCollection.cs
- PathFigureCollection.cs
- TypeSystem.cs
- Visual.cs
- BitmapDecoder.cs
- RtfNavigator.cs
- ModelItemDictionaryImpl.cs
- RecordBuilder.cs
- EvidenceTypeDescriptor.cs
- AuthenticationService.cs
- CompModHelpers.cs
- CodeArrayCreateExpression.cs
- ToolStripDropDownClosingEventArgs.cs
- XamlBrushSerializer.cs
- XhtmlBasicControlAdapter.cs
- ShapingWorkspace.cs
- BrowserCapabilitiesCodeGenerator.cs
- InputEventArgs.cs
- MultiSelectRootGridEntry.cs
- InputLangChangeEvent.cs
- TranslateTransform3D.cs
- XsltArgumentList.cs
- SuppressMessageAttribute.cs
- BooleanStorage.cs
- FileDetails.cs
- TypeExtension.cs
- WindowsStatic.cs
- Overlapped.cs
- BaseParaClient.cs
- DesignerProperties.cs
- PersonalizationProvider.cs
- DefaultDialogButtons.cs
- CommonXSendMessage.cs
- RangeContentEnumerator.cs
- ScaleTransform.cs
- securestring.cs
- WebPartDisplayModeCollection.cs
- Vector.cs
- _NestedSingleAsyncResult.cs
- ElementsClipboardData.cs
- DataControlReference.cs
- ImageCreator.cs
- IsolatedStorageFilePermission.cs
- WizardPanel.cs
- XmlSchemaGroupRef.cs
- TableHeaderCell.cs
- BrushMappingModeValidation.cs
- ListBase.cs
- DefaultBinder.cs
- Condition.cs
- PkcsUtils.cs
- SHA512Managed.cs
- NamedElement.cs
- ReferencedAssembly.cs
- MobileControlBuilder.cs
- SymmetricAlgorithm.cs
- PingOptions.cs
- SecurityException.cs
- TextTreeInsertElementUndoUnit.cs
- WhitespaceRule.cs
- SymbolType.cs
- AliasedSlot.cs
- sqlcontext.cs
- FormsAuthenticationConfiguration.cs
- Metafile.cs
- WebMethodAttribute.cs
- InputBinding.cs
- ThreadExceptionDialog.cs
- ClientBase.cs
- WebBrowserDocumentCompletedEventHandler.cs
- GlobalEventManager.cs
- mediapermission.cs
- EventMappingSettingsCollection.cs
- DrawTreeNodeEventArgs.cs
- SettingsBindableAttribute.cs
- ToolStripDropDownClosedEventArgs.cs
- StandardToolWindows.cs
- GridViewCommandEventArgs.cs
- XPathNodeList.cs
- InternalBufferOverflowException.cs
- Viewport3DVisual.cs
- DTCTransactionManager.cs
- DBCommandBuilder.cs
- AutomationAttributeInfo.cs
- DropDownButton.cs
- ValidationRuleCollection.cs
- MonthCalendar.cs
- IItemContainerGenerator.cs
- DBSchemaTable.cs
- DataGridBoolColumn.cs
- processwaithandle.cs
- EngineSite.cs
- AdvancedBindingPropertyDescriptor.cs