Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / TypeNameHelper.cs / 1305376 / TypeNameHelper.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation { using System; using System.Globalization; using System.Text; using System.Text.RegularExpressions; internal static class TypeNameHelper { // note: does not work for nested type when fullName is false public static string GetDisplayName(Type type, bool fullName) { if (type == null) { return string.Empty; } if (type.IsGenericParameter) { return type.Name; } if (!type.IsGenericType && !type.IsArray) { if (fullName) { return type.FullName; } else { return type.Name; } } // replace `2 withRegex regex = new Regex("`[0-9]+"); GenericsMatchEvaluator evaluator = new GenericsMatchEvaluator(type.GetGenericArguments(), fullName); // Remove [[fullName1, ..., fullNameX]] string name; if (fullName) { name = type.FullName; } else { name = type.Name; } int start = name.IndexOf("[[", StringComparison.Ordinal); int end = name.LastIndexOf("]]", StringComparison.Ordinal); if (start > 0 && end > 0) { name = name.Substring(0, start) + name.Substring(end + 2); } return regex.Replace(name, evaluator.Evaluate); } class GenericsMatchEvaluator { Type[] generics = null; int index; bool fullName; public GenericsMatchEvaluator(Type[] generics, bool fullName) { this.generics = generics; this.index = 0; this.fullName = fullName; } public string Evaluate(Match match) { int numberOfParameters = int.Parse(match.Value.Substring(1), CultureInfo.InvariantCulture); StringBuilder sb = new StringBuilder(); // matched "`N" is replaced by " " sb.Append("<"); for (int i = 0; i < numberOfParameters; i++) { if (i > 0) { sb.Append(", "); } sb.Append(TypeNameHelper.GetDisplayName(this.generics[this.index++], fullName)); } sb.Append(">"); return sb.ToString(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation { using System; using System.Globalization; using System.Text; using System.Text.RegularExpressions; internal static class TypeNameHelper { // note: does not work for nested type when fullName is false public static string GetDisplayName(Type type, bool fullName) { if (type == null) { return string.Empty; } if (type.IsGenericParameter) { return type.Name; } if (!type.IsGenericType && !type.IsArray) { if (fullName) { return type.FullName; } else { return type.Name; } } // replace `2 with Regex regex = new Regex("`[0-9]+"); GenericsMatchEvaluator evaluator = new GenericsMatchEvaluator(type.GetGenericArguments(), fullName); // Remove [[fullName1, ..., fullNameX]] string name; if (fullName) { name = type.FullName; } else { name = type.Name; } int start = name.IndexOf("[[", StringComparison.Ordinal); int end = name.LastIndexOf("]]", StringComparison.Ordinal); if (start > 0 && end > 0) { name = name.Substring(0, start) + name.Substring(end + 2); } return regex.Replace(name, evaluator.Evaluate); } class GenericsMatchEvaluator { Type[] generics = null; int index; bool fullName; public GenericsMatchEvaluator(Type[] generics, bool fullName) { this.generics = generics; this.index = 0; this.fullName = fullName; } public string Evaluate(Match match) { int numberOfParameters = int.Parse(match.Value.Substring(1), CultureInfo.InvariantCulture); StringBuilder sb = new StringBuilder(); // matched "`N" is replaced by " " sb.Append("<"); for (int i = 0; i < numberOfParameters; i++) { if (i > 0) { sb.Append(", "); } sb.Append(TypeNameHelper.GetDisplayName(this.generics[this.index++], fullName)); } sb.Append(">"); return sb.ToString(); } } } } // 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
- ImageFormat.cs
- DataGridParentRows.cs
- XmlSchemaSearchPattern.cs
- KnownTypesHelper.cs
- AutoSizeToolBoxItem.cs
- LoginCancelEventArgs.cs
- TextDecorationCollection.cs
- Trace.cs
- ProgressBar.cs
- TypeDescriptionProvider.cs
- FastEncoder.cs
- XmlDataCollection.cs
- COM2IDispatchConverter.cs
- SqlRowUpdatingEvent.cs
- UdpRetransmissionSettings.cs
- AnimationLayer.cs
- MemberBinding.cs
- ObjectDataSourceStatusEventArgs.cs
- PageThemeParser.cs
- AncestorChangedEventArgs.cs
- XmlMtomReader.cs
- TypeNameParser.cs
- WebPartDescriptionCollection.cs
- EventSinkHelperWriter.cs
- LazyTextWriterCreator.cs
- SqlServices.cs
- _OverlappedAsyncResult.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- RuleCache.cs
- CodeDOMProvider.cs
- BroadcastEventHelper.cs
- ParseNumbers.cs
- ThumbAutomationPeer.cs
- BatchServiceHost.cs
- DataGridViewHitTestInfo.cs
- AssociatedControlConverter.cs
- HttpCookiesSection.cs
- TypeInfo.cs
- GACIdentityPermission.cs
- FileController.cs
- DataGridViewRowsAddedEventArgs.cs
- LinqTreeNodeEvaluator.cs
- StyleSheetRefUrlEditor.cs
- XmlSchemaComplexType.cs
- GraphicsContext.cs
- ServiceOperation.cs
- XmlSchemaProviderAttribute.cs
- TablePatternIdentifiers.cs
- ProfilePropertySettings.cs
- PackageRelationshipCollection.cs
- ThreadPool.cs
- DataGridViewCellCancelEventArgs.cs
- WizardStepBase.cs
- DesigntimeLicenseContextSerializer.cs
- FileUpload.cs
- KerberosSecurityTokenProvider.cs
- KnownTypes.cs
- DataBoundControl.cs
- listitem.cs
- ImportCatalogPart.cs
- WebPartDisplayModeCollection.cs
- ComEventsSink.cs
- Compiler.cs
- WasNotInstalledException.cs
- Mapping.cs
- ChtmlTextWriter.cs
- CatalogPartCollection.cs
- XPathPatternBuilder.cs
- CompareInfo.cs
- KeyValueSerializer.cs
- SerializerProvider.cs
- XmlNullResolver.cs
- Int32KeyFrameCollection.cs
- UIElementIsland.cs
- ErrorProvider.cs
- RadialGradientBrush.cs
- OleDbStruct.cs
- UInt16.cs
- BufferedWebEventProvider.cs
- TemplateField.cs
- IPAddress.cs
- BaseValidator.cs
- TemplateBindingExtension.cs
- BamlResourceContent.cs
- ToolboxItemAttribute.cs
- PrintController.cs
- JsonCollectionDataContract.cs
- Point3DCollectionConverter.cs
- ScriptReference.cs
- SettingsBase.cs
- Hex.cs
- SqlClientPermission.cs
- ManagedCodeMarkers.cs
- TaiwanCalendar.cs
- ZipIOLocalFileBlock.cs
- ArcSegment.cs
- TabItem.cs
- ConfigurationValidatorAttribute.cs
- Thumb.cs
- HtmlLink.cs