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
- SystemDiagnosticsSection.cs
- ListViewDeleteEventArgs.cs
- TraceProvider.cs
- ConfigurationManager.cs
- PageClientProxyGenerator.cs
- ConfigXmlComment.cs
- Overlapped.cs
- MgmtConfigurationRecord.cs
- xsdvalidator.cs
- ViewSimplifier.cs
- Validator.cs
- SimpleHandlerFactory.cs
- WebBrowserContainer.cs
- InternalBufferManager.cs
- WebConfigurationFileMap.cs
- SessionParameter.cs
- Polygon.cs
- Cursor.cs
- SafeLibraryHandle.cs
- ToolZone.cs
- VariableDesigner.xaml.cs
- TemplateBindingExpression.cs
- ProtocolsConfigurationHandler.cs
- TextEndOfLine.cs
- HostVisual.cs
- ViewValidator.cs
- BinaryExpression.cs
- FamilyMap.cs
- TextBox.cs
- HtmlControlDesigner.cs
- Policy.cs
- TextTreeNode.cs
- CompareValidator.cs
- AlphabeticalEnumConverter.cs
- DSASignatureDeformatter.cs
- ListViewPagedDataSource.cs
- CommandDevice.cs
- PrintController.cs
- XsdBuildProvider.cs
- TextParagraphView.cs
- documentsequencetextview.cs
- NullRuntimeConfig.cs
- IdentityReference.cs
- GenericArgumentsUpdater.cs
- WindowsStatic.cs
- StandardOleMarshalObject.cs
- ConfigurationStrings.cs
- ExpandableObjectConverter.cs
- AuthenticationSection.cs
- CodeDomSerializationProvider.cs
- ConnectionStringEditor.cs
- HtmlTitle.cs
- NativeBuffer.cs
- VisualBrush.cs
- SQLSingleStorage.cs
- ExecutionTracker.cs
- LoginName.cs
- MailAddressCollection.cs
- AxHost.cs
- InvokeBase.cs
- ObjectReaderCompiler.cs
- CodeDelegateInvokeExpression.cs
- FilterException.cs
- EditorBrowsableAttribute.cs
- HandlerFactoryWrapper.cs
- UnsafeNativeMethodsCLR.cs
- DataRowChangeEvent.cs
- KeyboardNavigation.cs
- SmtpMail.cs
- ISCIIEncoding.cs
- DbFunctionCommandTree.cs
- SystemEvents.cs
- LayoutExceptionEventArgs.cs
- TextDecorationCollection.cs
- PrintEvent.cs
- XmlElementAttribute.cs
- PrintDocument.cs
- AttributeProviderAttribute.cs
- XmlSerializableReader.cs
- CssTextWriter.cs
- FontDifferentiator.cs
- FormCollection.cs
- MultiByteCodec.cs
- ModelPropertyCollectionImpl.cs
- WebEncodingValidatorAttribute.cs
- TripleDESCryptoServiceProvider.cs
- SaveFileDialogDesigner.cs
- Assign.cs
- ParseHttpDate.cs
- TraceHwndHost.cs
- DependencyObjectValidator.cs
- StringBuilder.cs
- PolygonHotSpot.cs
- DiscardableAttribute.cs
- CommandBinding.cs
- XmlSchemaSimpleContent.cs
- SpnEndpointIdentity.cs
- CharKeyFrameCollection.cs
- DrawingCollection.cs
- TextProperties.cs