Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CompMod / System / ComponentModel / GuidConverter.cs / 1 / GuidConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class GuidConverter : TypeConverter { ///Provides a /// type converter to convert globally unique identifier objects to and from various /// other representations. ////// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this /// converter can convert an object in the given source type to a globally unique identifier object /// using the context. ////// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = ((string)value).Trim(); return new Guid(text); } return base.ConvertFrom(context, culture, value); } ///Converts /// the given object to a globally unique identifier object. ////// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(InstanceDescriptor) && value is Guid) { ConstructorInfo ctor = typeof(Guid).GetConstructor(new Type[] {typeof(string)}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {value.ToString()}); } } return base.ConvertTo(context, culture, value, destinationType); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel { using Microsoft.Win32; using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Runtime.Serialization.Formatters; using System.Security.Permissions; ////// [HostProtection(SharedState = true)] public class GuidConverter : TypeConverter { ///Provides a /// type converter to convert globally unique identifier objects to and from various /// other representations. ////// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ///Gets a value indicating whether this /// converter can convert an object in the given source type to a globally unique identifier object /// using the context. ////// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = ((string)value).Trim(); return new Guid(text); } return base.ConvertFrom(context, culture, value); } ///Converts /// the given object to a globally unique identifier object. ////// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(InstanceDescriptor) && value is Guid) { ConstructorInfo ctor = typeof(Guid).GetConstructor(new Type[] {typeof(string)}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {value.ToString()}); } } return base.ConvertTo(context, culture, value, destinationType); } } } // 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
- CodeGotoStatement.cs
- AlphaSortedEnumConverter.cs
- OutputWindow.cs
- HostElement.cs
- xmlformatgeneratorstatics.cs
- SqlFunctionAttribute.cs
- Properties.cs
- SimpleWebHandlerParser.cs
- ToolStripOverflow.cs
- XmlSchemaAny.cs
- ListViewInsertEventArgs.cs
- SqlBulkCopyColumnMapping.cs
- DataGridViewComponentPropertyGridSite.cs
- HttpValueCollection.cs
- Utils.cs
- ConnectionsZone.cs
- CellRelation.cs
- ObjectSecurity.cs
- GridViewItemAutomationPeer.cs
- Permission.cs
- CompiledAction.cs
- AppearanceEditorPart.cs
- DynamicRenderer.cs
- X509AsymmetricSecurityKey.cs
- WebServiceClientProxyGenerator.cs
- OleDbReferenceCollection.cs
- SoapConverter.cs
- SQLBytes.cs
- HandleExceptionArgs.cs
- DetailsView.cs
- ListControlStringCollectionEditor.cs
- AnnotationMap.cs
- HwndSourceKeyboardInputSite.cs
- SoapObjectReader.cs
- StreamGeometry.cs
- DataGridCaption.cs
- LayoutUtils.cs
- SystemWebSectionGroup.cs
- DataGridViewColumnCollectionDialog.cs
- HttpHeaderCollection.cs
- BitmapEffectGroup.cs
- Parser.cs
- XmlDownloadManager.cs
- SatelliteContractVersionAttribute.cs
- XmlElementAttribute.cs
- ObjectSecurity.cs
- XmlSchemaInfo.cs
- X509ChainElement.cs
- TextLine.cs
- TextPenaltyModule.cs
- ValidateNames.cs
- ObjectRef.cs
- keycontainerpermission.cs
- FamilyTypefaceCollection.cs
- SharedPersonalizationStateInfo.cs
- GuidConverter.cs
- SqlDataRecord.cs
- SystemIPInterfaceProperties.cs
- DecoderNLS.cs
- ProfileManager.cs
- X509UI.cs
- TimestampInformation.cs
- OdbcConnectionPoolProviderInfo.cs
- OutputCacheModule.cs
- ExcCanonicalXml.cs
- XsdCachingReader.cs
- ChineseLunisolarCalendar.cs
- ChannelServices.cs
- UIElement3D.cs
- InternalConfigHost.cs
- TagMapInfo.cs
- RowUpdatingEventArgs.cs
- ToolStripDropDownClosingEventArgs.cs
- SqlSelectStatement.cs
- BindingWorker.cs
- PartBasedPackageProperties.cs
- BulletChrome.cs
- RegexCaptureCollection.cs
- ProvidersHelper.cs
- Simplifier.cs
- WindowsScrollBar.cs
- SqlUnionizer.cs
- Context.cs
- ReferentialConstraint.cs
- WebPartDisplayModeCancelEventArgs.cs
- Transaction.cs
- typedescriptorpermissionattribute.cs
- SiteMapHierarchicalDataSourceView.cs
- Message.cs
- OracleBinary.cs
- DecimalAnimationUsingKeyFrames.cs
- XmlTextAttribute.cs
- ListBoxAutomationPeer.cs
- TextTreeInsertElementUndoUnit.cs
- CompiledQueryCacheEntry.cs
- TranslateTransform.cs
- InplaceBitmapMetadataWriter.cs
- ExceptionUtil.cs
- ParameterCollection.cs
- DesignerVerb.cs