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
- InlineCollection.cs
- ButtonPopupAdapter.cs
- GeneralTransform3DTo2D.cs
- DependencyObjectProvider.cs
- KeyGesture.cs
- ToolStripPanelRow.cs
- ObjectIDGenerator.cs
- IdentityNotMappedException.cs
- xsdvalidator.cs
- ControlAdapter.cs
- GridViewDeleteEventArgs.cs
- CodeAccessPermission.cs
- PersonalizationProviderCollection.cs
- ApplicationBuildProvider.cs
- RenamedEventArgs.cs
- DurableInstanceProvider.cs
- MimeFormatExtensions.cs
- EntityKey.cs
- JumpList.cs
- AuthenticationService.cs
- TailCallAnalyzer.cs
- base64Transforms.cs
- DescriptionCreator.cs
- HuffModule.cs
- SiteMapNodeItem.cs
- ConnectionManagementElementCollection.cs
- UInt64.cs
- MenuItem.cs
- WinEventWrap.cs
- TextEditorLists.cs
- FtpRequestCacheValidator.cs
- Size3D.cs
- SelectionItemProviderWrapper.cs
- SecurityValidationBehavior.cs
- NameNode.cs
- DeriveBytes.cs
- NavigationFailedEventArgs.cs
- BaseTemplateParser.cs
- ListViewItemSelectionChangedEvent.cs
- WpfSharedBamlSchemaContext.cs
- HttpListenerTimeoutManager.cs
- ActivityTrace.cs
- ViewBox.cs
- DataGridAutoFormatDialog.cs
- Int32EqualityComparer.cs
- RegexMatchCollection.cs
- TimersDescriptionAttribute.cs
- DocumentReference.cs
- BaseParaClient.cs
- infer.cs
- OSFeature.cs
- DataSourceComponent.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- RequestQueryParser.cs
- DataViewSettingCollection.cs
- COM2ColorConverter.cs
- ContractMapping.cs
- StringCollection.cs
- ListViewDeletedEventArgs.cs
- DateTimeFormat.cs
- OutputCacheProfileCollection.cs
- SecurityHelper.cs
- ArrayList.cs
- _MultipleConnectAsync.cs
- InfoCardRSACryptoProvider.cs
- TreeNodeConverter.cs
- safemediahandle.cs
- Screen.cs
- FixedBufferAttribute.cs
- KeyFrames.cs
- ObjectItemNoOpAssemblyLoader.cs
- ExtendedPropertyCollection.cs
- SafeIUnknown.cs
- TextBoxView.cs
- AnnotationElement.cs
- Invariant.cs
- ILGenerator.cs
- MenuBindingsEditorForm.cs
- TypeUtil.cs
- LineServices.cs
- FileStream.cs
- SQLInt64Storage.cs
- DescendentsWalker.cs
- ThreadStateException.cs
- XXXOnTypeBuilderInstantiation.cs
- SignedInfo.cs
- Point3DCollection.cs
- ActivationServices.cs
- XmlAnyElementAttributes.cs
- AncestorChangedEventArgs.cs
- UxThemeWrapper.cs
- CompiledIdentityConstraint.cs
- XmlUnspecifiedAttribute.cs
- WorkflowInspectionServices.cs
- WebPartCollection.cs
- exports.cs
- CollectionViewGroupRoot.cs
- InvokeMemberBinder.cs
- XmlnsDictionary.cs
- UniqueEventHelper.cs