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
- ObjectDataSourceMethodEventArgs.cs
- ClientSettingsStore.cs
- NameValuePair.cs
- QuaternionValueSerializer.cs
- ClientTargetSection.cs
- EntityContainer.cs
- ContentTextAutomationPeer.cs
- TextContainerChangeEventArgs.cs
- ObjectQuery_EntitySqlExtensions.cs
- PublishLicense.cs
- Repeater.cs
- HostedNamedPipeTransportManager.cs
- ListBoxItemAutomationPeer.cs
- UpdateException.cs
- CapabilitiesPattern.cs
- CaseExpr.cs
- SetterBase.cs
- SoundPlayer.cs
- While.cs
- HttpContextBase.cs
- Aggregates.cs
- AttributeCollection.cs
- WebSysDefaultValueAttribute.cs
- AnnotationHelper.cs
- CfgSemanticTag.cs
- WindowsTokenRoleProvider.cs
- OleDbParameterCollection.cs
- ListBindingConverter.cs
- PasswordTextNavigator.cs
- ToolStripPanel.cs
- BooleanConverter.cs
- SignatureHelper.cs
- Permission.cs
- WindowsClaimSet.cs
- ColorContext.cs
- SR.cs
- MappingModelBuildProvider.cs
- DBSchemaTable.cs
- ReadOnlyCollectionBase.cs
- DnsPermission.cs
- ToolStripSplitButton.cs
- DataViewManager.cs
- SmtpMail.cs
- ChannelBase.cs
- SspiNegotiationTokenAuthenticatorState.cs
- TemplateControlCodeDomTreeGenerator.cs
- TimeSpan.cs
- MultiBindingExpression.cs
- ToolStripArrowRenderEventArgs.cs
- SecurityAlgorithmSuite.cs
- CommonGetThemePartSize.cs
- PlatformNotSupportedException.cs
- CollectionBuilder.cs
- FunctionParameter.cs
- ConfigurationManagerHelper.cs
- Walker.cs
- TrustManagerPromptUI.cs
- AttributedMetaModel.cs
- Encoder.cs
- FilterException.cs
- ProjectionRewriter.cs
- ClientOptions.cs
- configsystem.cs
- QuotedStringWriteStateInfo.cs
- CodeDefaultValueExpression.cs
- WebServiceData.cs
- AdministrationHelpers.cs
- BufferedWebEventProvider.cs
- XmlSchemaComplexContentRestriction.cs
- GridItemPattern.cs
- CLRBindingWorker.cs
- FileAuthorizationModule.cs
- DataRowChangeEvent.cs
- RowBinding.cs
- PrivacyNoticeBindingElement.cs
- FlagsAttribute.cs
- CatalogZone.cs
- DefaultHttpHandler.cs
- PeerNameResolver.cs
- SqlGatherConsumedAliases.cs
- DatagridviewDisplayedBandsData.cs
- XmlILModule.cs
- DataGridViewRowHeaderCell.cs
- mil_commands.cs
- DeviceContexts.cs
- ChannelFactoryBase.cs
- Compiler.cs
- SettingsPropertyCollection.cs
- AuthenticationSection.cs
- CacheEntry.cs
- MenuEventArgs.cs
- ExpressionNode.cs
- XmlProcessingInstruction.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- TrustLevelCollection.cs
- PasswordBoxAutomationPeer.cs
- KerberosReceiverSecurityToken.cs
- BitmapEffectDrawingContextWalker.cs
- XmlDocumentType.cs
- AttributeSetAction.cs