Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / TypeToStringValueConverter.cs / 1305376 / TypeToStringValueConverter.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Diagnostics; using System.Globalization; using System.Windows.Data; using System.Runtime; class TypeToStringValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Fx.Assert(targetType.Equals(typeof(string)), "TypeToStringValueConverter cannot convert a type to type " + targetType.FullName); string target = null; if (value != null) { Fx.Assert(value is Type, string.Format(CultureInfo.InvariantCulture, "TypeToStringValueConverter cannot convert from type {0} to string", value.GetType().FullName)); Type editedType = (Type)value; //handle primitive types if (editedType.IsPrimitive || editedType.IsValueType || editedType == typeof(string) || editedType == typeof(object)) { target = editedType.Name; } //and other ones else { target = editedType.FullName; } } return target; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { Fx.Assert(targetType.Equals(typeof(Type)), "TypeToStringValueConverter cannot convert string back to type " + targetType.FullName); Type target = null; string stringValue = value as string; if (!string.IsNullOrEmpty(stringValue)) { // try to get the type from the type name target = Type.GetType(stringValue, false, true); //handle primitive types if (null == target) { stringValue = string.Format(CultureInfo.InvariantCulture, "System.{0}", stringValue); target = Type.GetType(stringValue, false, true); } if (null == target) { return Binding.DoNothing; } } return target; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Diagnostics; using System.Globalization; using System.Windows.Data; using System.Runtime; class TypeToStringValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Fx.Assert(targetType.Equals(typeof(string)), "TypeToStringValueConverter cannot convert a type to type " + targetType.FullName); string target = null; if (value != null) { Fx.Assert(value is Type, string.Format(CultureInfo.InvariantCulture, "TypeToStringValueConverter cannot convert from type {0} to string", value.GetType().FullName)); Type editedType = (Type)value; //handle primitive types if (editedType.IsPrimitive || editedType.IsValueType || editedType == typeof(string) || editedType == typeof(object)) { target = editedType.Name; } //and other ones else { target = editedType.FullName; } } return target; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { Fx.Assert(targetType.Equals(typeof(Type)), "TypeToStringValueConverter cannot convert string back to type " + targetType.FullName); Type target = null; string stringValue = value as string; if (!string.IsNullOrEmpty(stringValue)) { // try to get the type from the type name target = Type.GetType(stringValue, false, true); //handle primitive types if (null == target) { stringValue = string.Format(CultureInfo.InvariantCulture, "System.{0}", stringValue); target = Type.GetType(stringValue, false, true); } if (null == target) { return Binding.DoNothing; } } return target; } } } // 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
- ToolboxItemFilterAttribute.cs
- control.ime.cs
- HttpConfigurationSystem.cs
- TextLine.cs
- SimpleBitVector32.cs
- ObjectAssociationEndMapping.cs
- AspNetSynchronizationContext.cs
- AttributeEmitter.cs
- SchemaTableColumn.cs
- ListControlBuilder.cs
- Lease.cs
- InkPresenterAutomationPeer.cs
- BufferBuilder.cs
- MetabaseSettingsIis7.cs
- KnowledgeBase.cs
- CurrentChangingEventArgs.cs
- ToolStripOverflowButton.cs
- GridViewSelectEventArgs.cs
- TagMapCollection.cs
- HostedImpersonationContext.cs
- FileLogRecordHeader.cs
- DocumentsTrace.cs
- SQLStringStorage.cs
- InternalRelationshipCollection.cs
- SmtpNtlmAuthenticationModule.cs
- DiscreteKeyFrames.cs
- DecoderFallback.cs
- SQlBooleanStorage.cs
- ParseChildrenAsPropertiesAttribute.cs
- SendMailErrorEventArgs.cs
- SkewTransform.cs
- PnrpPeerResolverElement.cs
- EventSinkHelperWriter.cs
- WindowsScroll.cs
- TextServicesCompartmentContext.cs
- StateMachineAction.cs
- CryptoApi.cs
- CreateUserWizardStep.cs
- HtmlTableCellCollection.cs
- MediaSystem.cs
- MaskedTextProvider.cs
- HyperLinkStyle.cs
- Soap12ProtocolImporter.cs
- DataGridDetailsPresenterAutomationPeer.cs
- And.cs
- EmbeddedObject.cs
- WindowInteractionStateTracker.cs
- AttachedAnnotation.cs
- DecimalStorage.cs
- ObjectDataSourceMethodEventArgs.cs
- SettingsBase.cs
- VirtualizingStackPanel.cs
- EntityDataSourceView.cs
- DockPanel.cs
- CommonDialog.cs
- TransactionContextValidator.cs
- ClientConvert.cs
- WinEventHandler.cs
- ArraySubsetEnumerator.cs
- ComponentCommands.cs
- CorrelationRequestContext.cs
- DesignTimeTemplateParser.cs
- SafeFileMappingHandle.cs
- listitem.cs
- WindowsListViewGroup.cs
- FixedSOMPage.cs
- Application.cs
- BamlMapTable.cs
- ColorPalette.cs
- CollectionDataContractAttribute.cs
- DataGridViewCell.cs
- BackgroundFormatInfo.cs
- DisplayInformation.cs
- PixelFormat.cs
- Transactions.cs
- ConfigXmlAttribute.cs
- RIPEMD160.cs
- _AutoWebProxyScriptWrapper.cs
- Collection.cs
- ParameterElementCollection.cs
- Configuration.cs
- Matrix.cs
- MdiWindowListItemConverter.cs
- ListenerElementsCollection.cs
- ThreadAttributes.cs
- DefaultWorkflowTransactionService.cs
- SystemColors.cs
- KeyValuePairs.cs
- XmlBinaryReader.cs
- _BasicClient.cs
- ComponentDispatcherThread.cs
- InkCanvas.cs
- HMACSHA1.cs
- Overlapped.cs
- BaseResourcesBuildProvider.cs
- oledbmetadatacolumnnames.cs
- AssemblyNameProxy.cs
- StorageBasedPackageProperties.cs
- CustomAttributeSerializer.cs
- DataSourceControl.cs