Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TableItemStyle.cs
- ListItemParagraph.cs
- TypeConverter.cs
- CompatibleComparer.cs
- EnumMemberAttribute.cs
- Soap.cs
- FacetValueContainer.cs
- WebPartPersonalization.cs
- ConfigurationException.cs
- ByteRangeDownloader.cs
- TokenBasedSet.cs
- WebPartCatalogCloseVerb.cs
- ToolboxItemWrapper.cs
- CodeAssignStatement.cs
- ImmutableObjectAttribute.cs
- LogEntryHeaderSerializer.cs
- nulltextnavigator.cs
- CheckBoxAutomationPeer.cs
- TraceData.cs
- Expr.cs
- MobileControlPersister.cs
- Size3D.cs
- Help.cs
- ZipIOLocalFileDataDescriptor.cs
- Form.cs
- BinaryExpression.cs
- XmlDocumentSerializer.cs
- RelatedEnd.cs
- IRCollection.cs
- DataStreamFromComStream.cs
- ExtentJoinTreeNode.cs
- Positioning.cs
- FilteredDataSetHelper.cs
- HScrollBar.cs
- WebPartDescriptionCollection.cs
- PageFunction.cs
- InstalledFontCollection.cs
- WebConfigurationFileMap.cs
- TreeNodeStyle.cs
- BitmapScalingModeValidation.cs
- CacheOutputQuery.cs
- CreateUserErrorEventArgs.cs
- XmlReaderDelegator.cs
- LowerCaseStringConverter.cs
- JsonServiceDocumentSerializer.cs
- InputManager.cs
- TableTextElementCollectionInternal.cs
- SerializationObjectManager.cs
- DataSourceSelectArguments.cs
- BitmapEditor.cs
- XamlReaderHelper.cs
- GridLength.cs
- COAUTHINFO.cs
- IODescriptionAttribute.cs
- PathParser.cs
- SvcMapFile.cs
- TagElement.cs
- Accessible.cs
- DesignerVerbCollection.cs
- QueueProcessor.cs
- NetworkStream.cs
- Hex.cs
- AbsoluteQuery.cs
- ComponentRenameEvent.cs
- ServiceModelExtensionElement.cs
- CompilerScope.Storage.cs
- CodeObjectCreateExpression.cs
- LockCookie.cs
- CertificateReferenceElement.cs
- CompilerError.cs
- ObjectViewFactory.cs
- TypeUsageBuilder.cs
- PackageDigitalSignatureManager.cs
- httpserverutility.cs
- OrderByExpression.cs
- Int16AnimationBase.cs
- StylusPointPropertyInfoDefaults.cs
- ButtonField.cs
- RowParagraph.cs
- Int16KeyFrameCollection.cs
- OracleRowUpdatedEventArgs.cs
- ObjectDataSourceSelectingEventArgs.cs
- TraceXPathNavigator.cs
- Animatable.cs
- ArrayHelper.cs
- DigitalSignature.cs
- ThemeInfoAttribute.cs
- SchemaComplexType.cs
- validation.cs
- ListComponentEditor.cs
- SharedDp.cs
- Span.cs
- TextEmbeddedObject.cs
- Matrix.cs
- CqlLexer.cs
- HeaderedContentControl.cs
- XLinq.cs
- TypeToken.cs
- SharedUtils.cs
- XPathMessageContext.cs