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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeCollectionPropertyEditor.cs
- DropSource.cs
- remotingproxy.cs
- AndCondition.cs
- StreamInfo.cs
- SubstitutionList.cs
- AsyncCompletedEventArgs.cs
- InplaceBitmapMetadataWriter.cs
- OpCopier.cs
- ShutDownListener.cs
- HttpListener.cs
- XDRSchema.cs
- XmlSchemaType.cs
- DesignerValidationSummaryAdapter.cs
- UnsafeNativeMethods.cs
- PerspectiveCamera.cs
- log.cs
- FileUtil.cs
- Drawing.cs
- SerialPort.cs
- wgx_commands.cs
- NestPullup.cs
- NetworkAddressChange.cs
- ClientRequest.cs
- Debug.cs
- Attributes.cs
- DataGridViewElement.cs
- DataQuery.cs
- Message.cs
- RelatedCurrencyManager.cs
- PointConverter.cs
- DataGridViewCellValidatingEventArgs.cs
- ComUdtElementCollection.cs
- ComplexTypeEmitter.cs
- Model3DGroup.cs
- BrushMappingModeValidation.cs
- MissingMethodException.cs
- ConfigurationValue.cs
- BindingGroup.cs
- EntityDataSourceWrapper.cs
- FixedTextContainer.cs
- HttpCookieCollection.cs
- SafeBitVector32.cs
- DbConnectionClosed.cs
- HttpRequestCacheValidator.cs
- LineGeometry.cs
- RelationshipFixer.cs
- PrincipalPermission.cs
- ConfigXmlWhitespace.cs
- SrgsElementList.cs
- MemberHolder.cs
- ObjectQueryProvider.cs
- ErrorActivity.cs
- HeaderCollection.cs
- ElementHost.cs
- MethodToken.cs
- PropertyReferenceExtension.cs
- Assert.cs
- ColorMatrix.cs
- DataGridSortingEventArgs.cs
- RequestTimeoutManager.cs
- PageBreakRecord.cs
- QilLoop.cs
- EventLogStatus.cs
- CheckoutException.cs
- ReadOnlyTernaryTree.cs
- Message.cs
- StringUtil.cs
- BuildManager.cs
- MemberAssignmentAnalysis.cs
- DocumentViewerBase.cs
- TextRangeBase.cs
- ComAdminWrapper.cs
- XsdBuildProvider.cs
- TypedAsyncResult.cs
- EditableTreeList.cs
- Menu.cs
- storagemappingitemcollection.viewdictionary.cs
- ValueHandle.cs
- UnionQueryOperator.cs
- GregorianCalendar.cs
- XmlDataCollection.cs
- PreviewKeyDownEventArgs.cs
- RuleSetDialog.cs
- ContextMarshalException.cs
- SegmentInfo.cs
- SQLDecimalStorage.cs
- MetabaseReader.cs
- WCFServiceClientProxyGenerator.cs
- Base64Decoder.cs
- XhtmlBasicPageAdapter.cs
- TextTreePropertyUndoUnit.cs
- XmlWriter.cs
- ContextQuery.cs
- AutomationElementCollection.cs
- GridView.cs
- DataDocumentXPathNavigator.cs
- DataControlCommands.cs
- XmlSchemaProviderAttribute.cs
- XmlnsPrefixAttribute.cs