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
- MsmqChannelListenerBase.cs
- DoubleUtil.cs
- RowCache.cs
- FormsIdentity.cs
- Trace.cs
- TypeInfo.cs
- HwndStylusInputProvider.cs
- CompilerErrorCollection.cs
- TextMessageEncodingElement.cs
- PenThread.cs
- HierarchicalDataBoundControl.cs
- RootDesignerSerializerAttribute.cs
- TextDecorationLocationValidation.cs
- EncodingStreamWrapper.cs
- DataGridCaption.cs
- Part.cs
- PropertyStore.cs
- VariableQuery.cs
- arc.cs
- UnknownWrapper.cs
- StringBlob.cs
- ManagementQuery.cs
- PerformanceCounterPermissionEntry.cs
- StrongName.cs
- SoapCodeExporter.cs
- HWStack.cs
- ScriptMethodAttribute.cs
- DynamicPropertyHolder.cs
- SourceFileInfo.cs
- Application.cs
- ScaleTransform3D.cs
- GridViewSelectEventArgs.cs
- FontConverter.cs
- AudienceUriMode.cs
- DataSourceXmlSubItemAttribute.cs
- List.cs
- CachedBitmap.cs
- StopStoryboard.cs
- SHA1.cs
- FormViewCommandEventArgs.cs
- QuaternionAnimationUsingKeyFrames.cs
- ImageClickEventArgs.cs
- ByteRangeDownloader.cs
- ContainerControl.cs
- MetabaseSettingsIis7.cs
- BeginStoryboard.cs
- BackStopAuthenticationModule.cs
- MessageAction.cs
- RectAnimationBase.cs
- GetReadStreamResult.cs
- MessageQueueKey.cs
- Membership.cs
- xmlsaver.cs
- PlatformCulture.cs
- DataProviderNameConverter.cs
- EntityStoreSchemaGenerator.cs
- XmlSchemaAll.cs
- Timer.cs
- PlainXmlWriter.cs
- MediaScriptCommandRoutedEventArgs.cs
- SqlWebEventProvider.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- PathFigure.cs
- List.cs
- PerformanceCounterPermissionEntryCollection.cs
- MarkerProperties.cs
- ThemeInfoAttribute.cs
- RuleConditionDialog.cs
- KerberosReceiverSecurityToken.cs
- XhtmlMobileTextWriter.cs
- SslStream.cs
- ProcessHost.cs
- ServiceProviders.cs
- XmlCodeExporter.cs
- Configuration.cs
- XmlSchemaSequence.cs
- PageCatalogPart.cs
- PolyQuadraticBezierSegment.cs
- EntityDataSourceContextCreatedEventArgs.cs
- HtmlDocument.cs
- SmiSettersStream.cs
- ViewManager.cs
- XmlNodeComparer.cs
- Preprocessor.cs
- PageMediaSize.cs
- CryptoApi.cs
- FormViewCommandEventArgs.cs
- AttributeData.cs
- InkSerializer.cs
- ServerIdentity.cs
- SqlCacheDependencyDatabase.cs
- ConfigXmlSignificantWhitespace.cs
- LineSegment.cs
- TypeConvertions.cs
- CodeAccessSecurityEngine.cs
- CalendarTable.cs
- HtmlContainerControl.cs
- PlatformNotSupportedException.cs
- InkCanvasAutomationPeer.cs