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
- SystemTcpStatistics.cs
- XmlDataSource.cs
- SecureStringHasher.cs
- CalendarButton.cs
- PermissionAttributes.cs
- TypeConstant.cs
- SchemaImporter.cs
- ObjectDataSourceFilteringEventArgs.cs
- DbConnectionPoolOptions.cs
- DataControlFieldCollection.cs
- BeginStoryboard.cs
- wpf-etw.cs
- CurrencyManager.cs
- XsdDateTime.cs
- TextServicesPropertyRanges.cs
- ViewBase.cs
- PointAnimationBase.cs
- NamespaceDecl.cs
- WindowsFormsSectionHandler.cs
- Stylesheet.cs
- ExternalFile.cs
- TextContainer.cs
- CodeGenerator.cs
- DataSpaceManager.cs
- BinaryConverter.cs
- ObjectPropertyMapping.cs
- LineGeometry.cs
- SafeBitVector32.cs
- SizeAnimation.cs
- DuplicateWaitObjectException.cs
- IPipelineRuntime.cs
- CustomError.cs
- ScopelessEnumAttribute.cs
- DataGridViewColumnCollection.cs
- Error.cs
- ComplexType.cs
- ReadOnlyHierarchicalDataSource.cs
- Renderer.cs
- ServicePointManager.cs
- LogExtent.cs
- BitmapEffectDrawingContent.cs
- DataSourceNameHandler.cs
- ListViewItemSelectionChangedEvent.cs
- ContextItem.cs
- Base64Stream.cs
- RegistryKey.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- WorkflowQueueInfo.cs
- SqlDelegatedTransaction.cs
- SqlFactory.cs
- LinqDataSourceDeleteEventArgs.cs
- MonitoringDescriptionAttribute.cs
- ToolStripDesigner.cs
- EventLogPermission.cs
- ResetableIterator.cs
- MatrixIndependentAnimationStorage.cs
- IDispatchConstantAttribute.cs
- ErrorWebPart.cs
- ToolStripSplitButton.cs
- ContextMenu.cs
- GroupBoxRenderer.cs
- Crypto.cs
- TreeNodeStyleCollection.cs
- EventSinkHelperWriter.cs
- BitArray.cs
- VSWCFServiceContractGenerator.cs
- ClientCultureInfo.cs
- FlowLayoutSettings.cs
- X509Utils.cs
- TabItemAutomationPeer.cs
- SpecialNameAttribute.cs
- FunctionParameter.cs
- InvokeFunc.cs
- ItemType.cs
- ErrorFormatter.cs
- UnknownBitmapEncoder.cs
- ResourceFallbackManager.cs
- RowSpanVector.cs
- IntegrationExceptionEventArgs.cs
- SetUserPreferenceRequest.cs
- IntegrationExceptionEventArgs.cs
- DataTemplateKey.cs
- CodeTypeDeclaration.cs
- TemplateComponentConnector.cs
- NextPreviousPagerField.cs
- SamlAuthenticationClaimResource.cs
- CodeStatementCollection.cs
- BoolExpressionVisitors.cs
- XdrBuilder.cs
- AutomationProperties.cs
- SubMenuStyleCollection.cs
- WebPartConnectionsEventArgs.cs
- UnsignedPublishLicense.cs
- BaseCodeDomTreeGenerator.cs
- AsyncSerializedWorker.cs
- InvalidTimeZoneException.cs
- PropertyDescriptor.cs
- CommandField.cs
- SafeRightsManagementSessionHandle.cs
- SystemKeyConverter.cs