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
- AppSettingsReader.cs
- WebPartCatalogCloseVerb.cs
- LiteralLink.cs
- ViewService.cs
- AtomicFile.cs
- XmlQueryType.cs
- ImportCatalogPart.cs
- TransactionBridge.cs
- CodeRemoveEventStatement.cs
- HtmlElement.cs
- ConnectionManagementSection.cs
- RenderData.cs
- Site.cs
- QuestionEventArgs.cs
- LinkLabelLinkClickedEvent.cs
- SmiTypedGetterSetter.cs
- TickBar.cs
- Propagator.cs
- TreeBuilder.cs
- PerfService.cs
- EntityDesignerUtils.cs
- HtmlInputCheckBox.cs
- WebPartCollection.cs
- TemplateApplicationHelper.cs
- CursorConverter.cs
- AdRotator.cs
- ValueTable.cs
- SemaphoreSecurity.cs
- RsaEndpointIdentity.cs
- FileUtil.cs
- SubclassTypeValidator.cs
- PeerEndPoint.cs
- RuntimeHelpers.cs
- CodeBlockBuilder.cs
- IPHostEntry.cs
- UriTemplateVariablePathSegment.cs
- SqlCommand.cs
- NativeWindow.cs
- XamlInt32CollectionSerializer.cs
- ConvertBinder.cs
- PathFigureCollection.cs
- RowUpdatingEventArgs.cs
- QuaternionAnimation.cs
- SystemColors.cs
- EventWaitHandleSecurity.cs
- TemplateBindingExtension.cs
- DataMember.cs
- DrawingGroupDrawingContext.cs
- GridViewUpdatedEventArgs.cs
- EventLogEntry.cs
- FlowDocumentPageViewerAutomationPeer.cs
- PtsPage.cs
- ColorTranslator.cs
- ListMarkerSourceInfo.cs
- BaseAddressElement.cs
- DispatchChannelSink.cs
- CqlWriter.cs
- DeflateStream.cs
- XmlSerializerVersionAttribute.cs
- SoapClientMessage.cs
- Rule.cs
- ProcessHostServerConfig.cs
- ProtocolProfile.cs
- ParserContext.cs
- Rect3DValueSerializer.cs
- ProfilePropertySettings.cs
- StackBuilderSink.cs
- SmiSettersStream.cs
- XmlExtensionFunction.cs
- DataGridViewColumn.cs
- DrawListViewItemEventArgs.cs
- HttpConfigurationContext.cs
- MaterialGroup.cs
- BindingWorker.cs
- TypeLoader.cs
- RegionData.cs
- BitmapEncoder.cs
- StyleModeStack.cs
- ResourceKey.cs
- InvalidEnumArgumentException.cs
- ExtendedPropertyDescriptor.cs
- ListBindableAttribute.cs
- ListManagerBindingsCollection.cs
- DocComment.cs
- SvcMapFileSerializer.cs
- WorkflowViewStateService.cs
- TemplateParser.cs
- SymbolEqualComparer.cs
- PropertyValueChangedEvent.cs
- ResourceManagerWrapper.cs
- DataGridViewSortCompareEventArgs.cs
- PriorityItem.cs
- PageAsyncTaskManager.cs
- BindingList.cs
- CustomAttribute.cs
- DragCompletedEventArgs.cs
- Stack.cs
- XmlEncodedRawTextWriter.cs
- MonikerProxyAttribute.cs
- Storyboard.cs