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
- GridEntryCollection.cs
- SchemaConstraints.cs
- XslNumber.cs
- CustomErrorsSection.cs
- ConstraintConverter.cs
- WebPartEventArgs.cs
- LockRecursionException.cs
- TransformProviderWrapper.cs
- XPathPatternParser.cs
- EventMetadata.cs
- DataGridViewLinkCell.cs
- _CommandStream.cs
- CrossAppDomainChannel.cs
- PaintValueEventArgs.cs
- __Filters.cs
- StatusBarItemAutomationPeer.cs
- LinqDataSourceSelectEventArgs.cs
- AmbientValueAttribute.cs
- TypedTableBaseExtensions.cs
- FontInfo.cs
- FixedHyperLink.cs
- _PooledStream.cs
- SimpleTypeResolver.cs
- XmlDocumentViewSchema.cs
- VideoDrawing.cs
- XPathDocumentNavigator.cs
- IdleTimeoutMonitor.cs
- HttpDictionary.cs
- Visual3D.cs
- StringBlob.cs
- securitymgrsite.cs
- COM2PictureConverter.cs
- GeneratedCodeAttribute.cs
- PathFigure.cs
- IndexedString.cs
- SubstitutionList.cs
- VirtualPathUtility.cs
- SqlUnionizer.cs
- ChangeConflicts.cs
- COM2EnumConverter.cs
- ThreadAbortException.cs
- SHA1CryptoServiceProvider.cs
- HwndSourceKeyboardInputSite.cs
- FacetEnabledSchemaElement.cs
- MsmqIntegrationBinding.cs
- AutoGeneratedFieldProperties.cs
- FixedHyperLink.cs
- Timer.cs
- LateBoundBitmapDecoder.cs
- SecurityRuntime.cs
- DeclarationUpdate.cs
- RangeValuePattern.cs
- BrowserTree.cs
- XmlSignatureManifest.cs
- CurrencyManager.cs
- AnnotationService.cs
- X509Certificate2.cs
- SuppressMergeCheckAttribute.cs
- LambdaCompiler.Address.cs
- DataGridItemEventArgs.cs
- Privilege.cs
- ExeConfigurationFileMap.cs
- IImplicitResourceProvider.cs
- TrackingServices.cs
- ISFTagAndGuidCache.cs
- EntityClientCacheEntry.cs
- SqlDataSourceCommandEventArgs.cs
- XMLSyntaxException.cs
- WebHttpBehavior.cs
- WebRequestModuleElementCollection.cs
- AvTraceDetails.cs
- SspiWrapper.cs
- Pts.cs
- FontNameConverter.cs
- CodeDirectiveCollection.cs
- Viewport2DVisual3D.cs
- ACL.cs
- InputChannel.cs
- ObjRef.cs
- IgnoreFileBuildProvider.cs
- ContextProperty.cs
- PassportAuthenticationEventArgs.cs
- GridViewSelectEventArgs.cs
- WebRequest.cs
- DataTrigger.cs
- XPathSelfQuery.cs
- ConfigUtil.cs
- Attachment.cs
- Point3D.cs
- SafeNativeMethodsCLR.cs
- TraceContextEventArgs.cs
- XmlSignatureProperties.cs
- WindowHideOrCloseTracker.cs
- ToolStripArrowRenderEventArgs.cs
- FileLevelControlBuilderAttribute.cs
- SqlServices.cs
- SqlException.cs
- PathFigureCollection.cs
- XsltContext.cs
- ProcessModelInfo.cs