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
- Decoder.cs
- PropertiesTab.cs
- StringReader.cs
- BaseCAMarshaler.cs
- regiisutil.cs
- Dynamic.cs
- HttpPostClientProtocol.cs
- Dynamic.cs
- BinaryObjectInfo.cs
- RoutedUICommand.cs
- Slider.cs
- RotateTransform3D.cs
- ButtonChrome.cs
- DeploymentExceptionMapper.cs
- ServiceErrorHandler.cs
- SourceSwitch.cs
- DSASignatureFormatter.cs
- ActivationServices.cs
- FormClosedEvent.cs
- AsyncCompletedEventArgs.cs
- EnumDataContract.cs
- PtsHost.cs
- HtmlImageAdapter.cs
- DurableTimerExtension.cs
- EdmItemError.cs
- StylusPointProperty.cs
- DecimalConstantAttribute.cs
- StreamResourceInfo.cs
- DataGridViewSelectedColumnCollection.cs
- WebExceptionStatus.cs
- VisualBasicSettings.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- OperandQuery.cs
- XPathPatternParser.cs
- Debugger.cs
- XmlSchemaImport.cs
- Accessors.cs
- RuntimeConfig.cs
- SafeArrayRankMismatchException.cs
- ModuleElement.cs
- GlobalItem.cs
- PersonalizablePropertyEntry.cs
- DesignerContextDescriptor.cs
- WindowsFormsHelpers.cs
- CaseInsensitiveComparer.cs
- KeyGesture.cs
- HtmlButton.cs
- ObjectResult.cs
- OperationDescriptionCollection.cs
- ClientTarget.cs
- GridViewCancelEditEventArgs.cs
- Image.cs
- PageCatalogPart.cs
- ListViewCommandEventArgs.cs
- XslVisitor.cs
- ContextCorrelationInitializer.cs
- CharEnumerator.cs
- X509ClientCertificateAuthentication.cs
- UxThemeWrapper.cs
- AssemblyCache.cs
- Emitter.cs
- XXXOnTypeBuilderInstantiation.cs
- WindowsScroll.cs
- ConfigurationPropertyAttribute.cs
- ResourceDisplayNameAttribute.cs
- HotSpot.cs
- SafeSecurityHelper.cs
- Application.cs
- WindowsGraphics2.cs
- DBCSCodePageEncoding.cs
- GeneratedContractType.cs
- StorageScalarPropertyMapping.cs
- LinkGrep.cs
- RegexCompiler.cs
- AddInControllerImpl.cs
- SocketCache.cs
- PkcsUtils.cs
- XmlCharCheckingWriter.cs
- SizeConverter.cs
- EventMemberCodeDomSerializer.cs
- CharKeyFrameCollection.cs
- MetafileHeader.cs
- BitmapEffectDrawingContent.cs
- SqlAggregateChecker.cs
- TypeUsage.cs
- ReferencedType.cs
- WindowsToolbar.cs
- ButtonRenderer.cs
- CategoryAttribute.cs
- DefaultTextStore.cs
- graph.cs
- FunctionQuery.cs
- TaskFileService.cs
- Cursor.cs
- SqlCacheDependencyDatabase.cs
- dataprotectionpermission.cs
- Metafile.cs
- PickBranch.cs
- List.cs
- GcSettings.cs