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
- HtmlElementCollection.cs
- WindowsPrincipal.cs
- ListDictionaryInternal.cs
- XmlSchemaCollection.cs
- FontStretchConverter.cs
- CreateUserErrorEventArgs.cs
- PublishLicense.cs
- DataGridrowEditEndingEventArgs.cs
- AnnotationMap.cs
- ImmutablePropertyDescriptorGridEntry.cs
- JpegBitmapEncoder.cs
- FieldBuilder.cs
- DBSqlParserColumnCollection.cs
- DefaultClaimSet.cs
- ActiveXHelper.cs
- EntityEntry.cs
- ScrollBar.cs
- SplashScreenNativeMethods.cs
- GPRECT.cs
- CookieProtection.cs
- DocumentViewerAutomationPeer.cs
- ChildTable.cs
- TypedTableHandler.cs
- IisTraceListener.cs
- BinaryNode.cs
- EventLogger.cs
- WebAdminConfigurationHelper.cs
- MonthCalendarDesigner.cs
- AnimatedTypeHelpers.cs
- SingleAnimation.cs
- StylusCaptureWithinProperty.cs
- SmiRecordBuffer.cs
- ContravarianceAdapter.cs
- DocComment.cs
- RangeValueProviderWrapper.cs
- ClientSettings.cs
- WebPartCollection.cs
- WindowsGraphicsCacheManager.cs
- IOException.cs
- XmlCharType.cs
- BoolLiteral.cs
- UpWmlPageAdapter.cs
- DataGridTable.cs
- Int32CAMarshaler.cs
- CellPartitioner.cs
- AccessViolationException.cs
- ViewBase.cs
- Win32Native.cs
- ValueConversionAttribute.cs
- HttpWebRequest.cs
- DbConnectionClosed.cs
- DataListDesigner.cs
- PrintingPermission.cs
- MetadataItemCollectionFactory.cs
- ProjectedSlot.cs
- ErrorsHelper.cs
- XmlNamedNodeMap.cs
- RSAOAEPKeyExchangeFormatter.cs
- ReadOnlyDataSourceView.cs
- SchemaMapping.cs
- RtfControlWordInfo.cs
- ActivityDesignerResources.cs
- CapacityStreamGeometryContext.cs
- input.cs
- OracleSqlParser.cs
- FixedStringLookup.cs
- ColorAnimationUsingKeyFrames.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- IndexedGlyphRun.cs
- WebPartVerb.cs
- EntityDataSourceDataSelection.cs
- UpdatePanel.cs
- DataRelation.cs
- RuleElement.cs
- PageCodeDomTreeGenerator.cs
- Pipe.cs
- ShapingEngine.cs
- ProcessingInstructionAction.cs
- NamedPermissionSet.cs
- _HelperAsyncResults.cs
- ValueTable.cs
- PersianCalendar.cs
- Intellisense.cs
- GenericWebPart.cs
- CodeDelegateInvokeExpression.cs
- Console.cs
- UserPreference.cs
- DataGridViewCellFormattingEventArgs.cs
- Inline.cs
- odbcmetadatacollectionnames.cs
- ClientSettingsSection.cs
- SqlDuplicator.cs
- EmbeddedMailObjectsCollection.cs
- InputLanguageCollection.cs
- Atom10FormatterFactory.cs
- Bezier.cs
- WindowsEditBox.cs
- WindowsGraphics.cs
- BitConverter.cs
- InputScopeManager.cs