Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / ComponentModel / GuidConverter.cs / 1305376 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConfigXmlElement.cs
- ConstructorNeedsTagAttribute.cs
- ReturnEventArgs.cs
- Literal.cs
- ASCIIEncoding.cs
- TemplateInstanceAttribute.cs
- EncryptedData.cs
- FileLoadException.cs
- ProcessInfo.cs
- TdsRecordBufferSetter.cs
- _FtpControlStream.cs
- ValidationSummaryDesigner.cs
- TraceEventCache.cs
- MessageBox.cs
- ReverseInheritProperty.cs
- OracleSqlParser.cs
- ErrorTableItemStyle.cs
- PointLight.cs
- ResourcePart.cs
- COAUTHIDENTITY.cs
- unitconverter.cs
- LinqToSqlWrapper.cs
- SchemaCollectionPreprocessor.cs
- PersonalizationProviderHelper.cs
- DummyDataSource.cs
- Line.cs
- TemplateComponentConnector.cs
- ToolCreatedEventArgs.cs
- FunctionQuery.cs
- DecryptedHeader.cs
- Context.cs
- TextEffect.cs
- StringFreezingAttribute.cs
- RuntimeConfigLKG.cs
- FontFamily.cs
- WebControl.cs
- DeferredElementTreeState.cs
- CredentialCache.cs
- XmlReaderSettings.cs
- Font.cs
- MessageQueueEnumerator.cs
- PlaceHolder.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- RichTextBoxAutomationPeer.cs
- Crc32.cs
- CompilerErrorCollection.cs
- ButtonField.cs
- GridViewEditEventArgs.cs
- MetadataCollection.cs
- MediaCommands.cs
- BuildProviderAppliesToAttribute.cs
- SchemaTableColumn.cs
- _ConnectionGroup.cs
- httpstaticobjectscollection.cs
- ObjectDisposedException.cs
- EntityDataSourceState.cs
- XPathNodeHelper.cs
- WebPartConnectionsConfigureVerb.cs
- SchemaConstraints.cs
- PropertiesTab.cs
- TypedReference.cs
- TableLayoutRowStyleCollection.cs
- SafeNativeMemoryHandle.cs
- TabPageDesigner.cs
- MenuBase.cs
- CLRBindingWorker.cs
- ButtonFlatAdapter.cs
- EntityRecordInfo.cs
- AppSecurityManager.cs
- Timeline.cs
- InlineObject.cs
- IsolationInterop.cs
- ActivityPreviewDesigner.cs
- SQlBooleanStorage.cs
- SoapFault.cs
- EventPrivateKey.cs
- HtmlControlPersistable.cs
- ManifestBasedResourceGroveler.cs
- PageScaling.cs
- DeflateStreamAsyncResult.cs
- Highlights.cs
- DataServiceContext.cs
- OdbcConnectionFactory.cs
- EntityContainer.cs
- OleDbFactory.cs
- DataGridViewMethods.cs
- WebPartConnection.cs
- WindowsAuthenticationEventArgs.cs
- _AuthenticationState.cs
- DoubleLinkList.cs
- FilteredReadOnlyMetadataCollection.cs
- RewritingSimplifier.cs
- TextCharacters.cs
- SecurityTokenTypes.cs
- CodeTypeOfExpression.cs
- ThreadPool.cs
- HuffCodec.cs
- ArglessEventHandlerProxy.cs
- DropShadowEffect.cs
- ListViewItemSelectionChangedEvent.cs