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
- ObjectDataProvider.cs
- ExpandedWrapper.cs
- StateBag.cs
- CompilationSection.cs
- wmiutil.cs
- GroupQuery.cs
- ReadWriteObjectLock.cs
- EntityReference.cs
- Application.cs
- LogWriteRestartAreaState.cs
- ControlBindingsCollection.cs
- RegisteredScript.cs
- DynamicMethod.cs
- GridViewColumn.cs
- DocumentReferenceCollection.cs
- DateTimeFormatInfo.cs
- TdsValueSetter.cs
- BookmarkCallbackWrapper.cs
- ConfigurationProperty.cs
- PerfCounters.cs
- Translator.cs
- _AutoWebProxyScriptWrapper.cs
- TemplateNameScope.cs
- ObjectStateFormatter.cs
- DataStreamFromComStream.cs
- RTLAwareMessageBox.cs
- CodeGenHelper.cs
- VoiceSynthesis.cs
- tibetanshape.cs
- DetailsViewPagerRow.cs
- ConsumerConnectionPointCollection.cs
- CustomError.cs
- SqlDataSourceSelectingEventArgs.cs
- ScaleTransform3D.cs
- UInt64Storage.cs
- AssociatedControlConverter.cs
- UrlPropertyAttribute.cs
- CodeAttributeDeclarationCollection.cs
- RegexTree.cs
- RowBinding.cs
- DataGridClipboardHelper.cs
- DragEventArgs.cs
- XmlWrappingReader.cs
- ProgressBarHighlightConverter.cs
- InvokeMethod.cs
- ConditionBrowserDialog.cs
- SkipStoryboardToFill.cs
- Int16AnimationUsingKeyFrames.cs
- TargetInvocationException.cs
- BamlBinaryWriter.cs
- WindowProviderWrapper.cs
- OptimalTextSource.cs
- PipelineModuleStepContainer.cs
- HttpConfigurationSystem.cs
- OutKeywords.cs
- OleDbStruct.cs
- DateTimePickerDesigner.cs
- SqlMethods.cs
- DrawingGroup.cs
- RangeBaseAutomationPeer.cs
- Rotation3DKeyFrameCollection.cs
- SBCSCodePageEncoding.cs
- HashCodeCombiner.cs
- SMSvcHost.cs
- QilXmlWriter.cs
- XmlIterators.cs
- CodePageEncoding.cs
- ValidatingCollection.cs
- SqlUDTStorage.cs
- FixedDocument.cs
- NetSectionGroup.cs
- ConnectionAcceptor.cs
- CookielessHelper.cs
- storepermissionattribute.cs
- ControllableStoryboardAction.cs
- MailAddress.cs
- TitleStyle.cs
- BinaryObjectReader.cs
- DrawingImage.cs
- ProcessInfo.cs
- WindowsFont.cs
- MarshalDirectiveException.cs
- StaticSiteMapProvider.cs
- StorageEndPropertyMapping.cs
- OutputCacheModule.cs
- EqualityComparer.cs
- TabletCollection.cs
- PrintControllerWithStatusDialog.cs
- EventListener.cs
- XmlSecureResolver.cs
- UnsafeNativeMethodsMilCoreApi.cs
- Sequence.cs
- SafeRightsManagementPubHandle.cs
- VirtualizingPanel.cs
- Set.cs
- DataGridViewColumnCollection.cs
- GridItem.cs
- SafeNativeMethods.cs
- ImageListImage.cs
- Point3DAnimationUsingKeyFrames.cs