Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ValueConversionAttribute.cs
- ContentFileHelper.cs
- UInt16Converter.cs
- DataContractJsonSerializer.cs
- TextEditorCopyPaste.cs
- EpmSyndicationContentSerializer.cs
- EmptyReadOnlyDictionaryInternal.cs
- AutomationPatternInfo.cs
- SmiEventStream.cs
- MemberRelationshipService.cs
- UrlPropertyAttribute.cs
- SecurityElement.cs
- LinkedList.cs
- NavigationWindowAutomationPeer.cs
- UnknownBitmapDecoder.cs
- DictionaryEntry.cs
- TTSEngineProxy.cs
- DurableTimerExtension.cs
- DependsOnAttribute.cs
- StringCollection.cs
- _ShellExpression.cs
- DecoderBestFitFallback.cs
- VarInfo.cs
- AtomMaterializer.cs
- CommonBehaviorsSection.cs
- MultilineStringConverter.cs
- ContentElement.cs
- LayoutEvent.cs
- SymbolEqualComparer.cs
- CacheHelper.cs
- DbgCompiler.cs
- _SslState.cs
- Rotation3DAnimationBase.cs
- TextDocumentView.cs
- ChangePassword.cs
- SizeChangedInfo.cs
- PropertyRecord.cs
- AutomationPropertyInfo.cs
- OleDbReferenceCollection.cs
- DocumentViewer.cs
- DataGridViewCellParsingEventArgs.cs
- AttachedPropertyBrowsableAttribute.cs
- EntityDataSourceDesigner.cs
- HTMLTextWriter.cs
- NativeDirectoryServicesQueryAPIs.cs
- TableItemPattern.cs
- XmlHierarchicalEnumerable.cs
- basenumberconverter.cs
- BamlRecordHelper.cs
- Image.cs
- OdbcStatementHandle.cs
- BaseDataListComponentEditor.cs
- ObjectDataSourceView.cs
- ConfigViewGenerator.cs
- SubMenuStyleCollection.cs
- GridViewRowPresenterBase.cs
- DataRowCollection.cs
- ItemCollection.cs
- MsmqIntegrationReceiveParameters.cs
- CompressionTracing.cs
- _NestedMultipleAsyncResult.cs
- ReverseComparer.cs
- SerialPort.cs
- FrugalMap.cs
- InvalidProgramException.cs
- DefaultValidator.cs
- RawKeyboardInputReport.cs
- PropertyChangedEventArgs.cs
- StateBag.cs
- RuntimeResourceSet.cs
- XsltException.cs
- CodeDefaultValueExpression.cs
- WebPartDisplayModeCollection.cs
- XmlUtf8RawTextWriter.cs
- ConfigPathUtility.cs
- SchemaDeclBase.cs
- LogSwitch.cs
- Privilege.cs
- KeysConverter.cs
- WindowsStatusBar.cs
- PageVisual.cs
- ColorBlend.cs
- OleStrCAMarshaler.cs
- PromptStyle.cs
- BindableTemplateBuilder.cs
- SplineKeyFrames.cs
- HostedHttpContext.cs
- PerformanceCounterPermissionEntryCollection.cs
- AutoCompleteStringCollection.cs
- SafeFileMapViewHandle.cs
- OdbcParameterCollection.cs
- SimpleHandlerFactory.cs
- Rotation3DAnimationBase.cs
- HttpProcessUtility.cs
- ProxyFragment.cs
- AutomationEvent.cs
- SecurityContext.cs
- XmlEnumAttribute.cs
- EntityDataSourceWrapper.cs
- FixedSOMPage.cs