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
- Attributes.cs
- CachedFontFamily.cs
- PerformanceCounterCategory.cs
- ConfigXmlAttribute.cs
- ServicePointManager.cs
- DesignerDataTableBase.cs
- ProcessStartInfo.cs
- DocumentXmlWriter.cs
- HttpFileCollection.cs
- CodeObjectCreateExpression.cs
- RemotingAttributes.cs
- counter.cs
- ReturnType.cs
- SortFieldComparer.cs
- Point3DAnimationUsingKeyFrames.cs
- PermissionToken.cs
- RedirectionProxy.cs
- ImageList.cs
- ComponentConverter.cs
- AccessorTable.cs
- MenuBindingsEditor.cs
- SafeThemeHandle.cs
- IconBitmapDecoder.cs
- MemberMemberBinding.cs
- ApplicationProxyInternal.cs
- PluralizationServiceUtil.cs
- FormatConvertedBitmap.cs
- HijriCalendar.cs
- BaseCodePageEncoding.cs
- UIAgentRequest.cs
- ImportDesigner.xaml.cs
- StorageComplexPropertyMapping.cs
- MimeFormatExtensions.cs
- InternalConfirm.cs
- MultiByteCodec.cs
- FusionWrap.cs
- Win32Exception.cs
- HtmlTable.cs
- MasterPageBuildProvider.cs
- TcpChannelHelper.cs
- SessionParameter.cs
- ExtensionFile.cs
- UriTemplateDispatchFormatter.cs
- MobileControlsSectionHandler.cs
- RegexMatch.cs
- BlurEffect.cs
- GeneralTransform3DCollection.cs
- Choices.cs
- MsmqIntegrationMessagePool.cs
- ToolStrip.cs
- DataGridViewDataConnection.cs
- SimpleFieldTemplateUserControl.cs
- SocketInformation.cs
- CompositeActivityDesigner.cs
- followingquery.cs
- Types.cs
- HttpRequest.cs
- MemoryRecordBuffer.cs
- MonitorWrapper.cs
- HtmlMeta.cs
- XmlParserContext.cs
- Journaling.cs
- WorkflowService.cs
- JavaScriptString.cs
- IndexedEnumerable.cs
- DataGridViewTopRowAccessibleObject.cs
- EncryptedPackageFilter.cs
- WaitForChangedResult.cs
- CryptoConfig.cs
- UserControlAutomationPeer.cs
- Unit.cs
- InstalledFontCollection.cs
- PrintEvent.cs
- SeverityFilter.cs
- HostingMessageProperty.cs
- ScriptControlDescriptor.cs
- MultipleViewPattern.cs
- SystemException.cs
- GridProviderWrapper.cs
- Repeater.cs
- DataMisalignedException.cs
- IPAddress.cs
- RenderingEventArgs.cs
- ISAPIRuntime.cs
- InvalidAsynchronousStateException.cs
- FontCacheLogic.cs
- WebRequestModuleElementCollection.cs
- InvalidPipelineStoreException.cs
- HitTestDrawingContextWalker.cs
- SerializationBinder.cs
- TypeInitializationException.cs
- __ComObject.cs
- CaseStatement.cs
- BinaryObjectWriter.cs
- WhitespaceSignificantCollectionAttribute.cs
- XmlMembersMapping.cs
- TileModeValidation.cs
- TemplateComponentConnector.cs
- SerializationSectionGroup.cs
- OleCmdHelper.cs