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
- Point4D.cs
- WebPartDisplayMode.cs
- XmlFormatExtensionAttribute.cs
- BrowserCapabilitiesCodeGenerator.cs
- ObjectView.cs
- TypeConverterValueSerializer.cs
- Tool.cs
- UInt64Converter.cs
- SoapHeaderAttribute.cs
- PowerModeChangedEventArgs.cs
- XmlConvert.cs
- HScrollProperties.cs
- SchemaEntity.cs
- WindowManager.cs
- CollectionsUtil.cs
- BrowserDefinitionCollection.cs
- ReadOnlyAttribute.cs
- InnerItemCollectionView.cs
- RadioButtonAutomationPeer.cs
- ZipIOCentralDirectoryBlock.cs
- Matrix3D.cs
- PrePostDescendentsWalker.cs
- SendOperation.cs
- RequestQueryProcessor.cs
- X509ServiceCertificateAuthentication.cs
- SQLSingle.cs
- BitmapEffectInputData.cs
- TreeNodeEventArgs.cs
- UIElement.cs
- StringConverter.cs
- AuthorizationRuleCollection.cs
- StringAnimationBase.cs
- RectangleConverter.cs
- HTMLTagNameToTypeMapper.cs
- PageStatePersister.cs
- NativeMethodsCLR.cs
- SerialErrors.cs
- MouseEvent.cs
- CodeAttributeDeclarationCollection.cs
- PrimitiveXmlSerializers.cs
- TreeViewCancelEvent.cs
- InstanceStore.cs
- SemaphoreSecurity.cs
- Executor.cs
- FilteredAttributeCollection.cs
- LinqDataSourceDeleteEventArgs.cs
- SymbolEqualComparer.cs
- ApplicationCommands.cs
- AttributeQuery.cs
- RecognitionResult.cs
- PersonalizableTypeEntry.cs
- GridProviderWrapper.cs
- IdleTimeoutMonitor.cs
- ValidationRuleCollection.cs
- OdbcReferenceCollection.cs
- login.cs
- PointCollectionValueSerializer.cs
- XmlDocument.cs
- DataSetSchema.cs
- BridgeDataRecord.cs
- ApplicationException.cs
- SqlNamer.cs
- BitmapImage.cs
- Point.cs
- MailSettingsSection.cs
- ExpressionQuoter.cs
- BuildProvider.cs
- DataRecordInternal.cs
- BamlTreeMap.cs
- RecognizerBase.cs
- Relationship.cs
- XmlAtomicValue.cs
- ParameterEditorUserControl.cs
- safex509handles.cs
- WebResourceAttribute.cs
- HandlerFactoryWrapper.cs
- EncodingTable.cs
- TextMetrics.cs
- CollectionConverter.cs
- WebServiceEnumData.cs
- InvalidOleVariantTypeException.cs
- FixedSOMFixedBlock.cs
- AlgoModule.cs
- ContainerControlDesigner.cs
- StringCollection.cs
- ModelFunctionTypeElement.cs
- NetTcpBinding.cs
- FontFamilyConverter.cs
- TrustSection.cs
- TemplatedWizardStep.cs
- UnsafeNativeMethods.cs
- ServiceDescriptionImporter.cs
- Stack.cs
- ToolStripSettings.cs
- ItemContainerGenerator.cs
- UserControl.cs
- Main.cs
- DashStyles.cs
- OleDbMetaDataFactory.cs
- indexingfiltermarshaler.cs