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
- DataBindingExpressionBuilder.cs
- FrameworkElementAutomationPeer.cs
- UITypeEditor.cs
- GlobalAllocSafeHandle.cs
- RequestStatusBarUpdateEventArgs.cs
- EventManager.cs
- WorkflowRuntime.cs
- Context.cs
- SecurityAlgorithmSuite.cs
- SharedPerformanceCounter.cs
- Int32Storage.cs
- DbMetaDataColumnNames.cs
- PropertyChangingEventArgs.cs
- ListItem.cs
- CodeExporter.cs
- Vector3DCollectionValueSerializer.cs
- MulticastNotSupportedException.cs
- ComNativeDescriptor.cs
- HandlerWithFactory.cs
- UnSafeCharBuffer.cs
- CacheOutputQuery.cs
- PanelContainerDesigner.cs
- TriggerBase.cs
- LineMetrics.cs
- ErasingStroke.cs
- Version.cs
- PrinterSettings.cs
- DocumentPaginator.cs
- DesignTimeVisibleAttribute.cs
- Image.cs
- ClientSideQueueItem.cs
- DbParameterCollection.cs
- DataGridViewBindingCompleteEventArgs.cs
- CodeCommentStatementCollection.cs
- RenderTargetBitmap.cs
- SortDescriptionCollection.cs
- DownloadProgressEventArgs.cs
- XmlComplianceUtil.cs
- WorkflowViewManager.cs
- StaticSiteMapProvider.cs
- WindowClosedEventArgs.cs
- CompilerGlobalScopeAttribute.cs
- ToolBarButton.cs
- JoinTreeNode.cs
- SchemaType.cs
- DataSourceExpression.cs
- CaseInsensitiveComparer.cs
- NodeLabelEditEvent.cs
- HoistedLocals.cs
- SessionEndingCancelEventArgs.cs
- WebAdminConfigurationHelper.cs
- IntegerValidator.cs
- Timer.cs
- Token.cs
- TypeGenericEnumerableViewSchema.cs
- TextCollapsingProperties.cs
- SecurityUtils.cs
- LineInfo.cs
- ConversionContext.cs
- DataGridViewComboBoxEditingControl.cs
- PropertyValueUIItem.cs
- SqlDataRecord.cs
- GenericIdentity.cs
- TreeNodeBindingCollection.cs
- DataGridParentRows.cs
- ObfuscationAttribute.cs
- _NegoStream.cs
- TypeConstant.cs
- XmlKeywords.cs
- InvokeDelegate.cs
- EventWaitHandle.cs
- unsafenativemethodsother.cs
- DurableInstanceProvider.cs
- XmlMtomReader.cs
- followingsibling.cs
- PackWebRequestFactory.cs
- XsltException.cs
- HtmlImage.cs
- NavigationExpr.cs
- MessageFilterException.cs
- ReferencedAssembly.cs
- CounterCreationData.cs
- OleDbFactory.cs
- MapPathBasedVirtualPathProvider.cs
- DataListCommandEventArgs.cs
- SetStoryboardSpeedRatio.cs
- GeneratedContractType.cs
- TreeViewHitTestInfo.cs
- HtmlPageAdapter.cs
- OleTxTransaction.cs
- XmlExceptionHelper.cs
- CommandLibraryHelper.cs
- StaticDataManager.cs
- AddInAttribute.cs
- LinkButton.cs
- GrammarBuilderBase.cs
- XamlSerializerUtil.cs
- TemplatePagerField.cs
- EpmCustomContentDeSerializer.cs
- OdbcConnectionHandle.cs