Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / TypeHelper.cs / 1305376 / TypeHelper.cs
using System; using System.Collections.Generic; using System.Text; namespace System.Linq { internal static class TypeHelper { internal static bool IsEnumerableType(Type enumerableType) { return FindGenericType(typeof(IEnumerable<>), enumerableType) != null; } internal static bool IsKindOfGeneric(Type type, Type definition) { return FindGenericType(definition, type) != null; } internal static Type GetElementType(Type enumerableType) { Type ienumType = FindGenericType(typeof(IEnumerable<>), enumerableType); if (ienumType != null) return ienumType.GetGenericArguments()[0]; return enumerableType; } internal static Type FindGenericType(Type definition, Type type) { while (type != null && type != typeof(object)) { if (type.IsGenericType && type.GetGenericTypeDefinition() == definition) return type; if (definition.IsInterface) { foreach(Type itype in type.GetInterfaces()) { Type found = FindGenericType(definition, itype); if (found != null) return found; } } type = type.BaseType; } return null; } internal static bool IsNullableType(Type type) { return type != null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } internal static Type GetNonNullableType(Type type) { if (IsNullableType(type)) { return type.GetGenericArguments()[0]; } return type; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Text; namespace System.Linq { internal static class TypeHelper { internal static bool IsEnumerableType(Type enumerableType) { return FindGenericType(typeof(IEnumerable<>), enumerableType) != null; } internal static bool IsKindOfGeneric(Type type, Type definition) { return FindGenericType(definition, type) != null; } internal static Type GetElementType(Type enumerableType) { Type ienumType = FindGenericType(typeof(IEnumerable<>), enumerableType); if (ienumType != null) return ienumType.GetGenericArguments()[0]; return enumerableType; } internal static Type FindGenericType(Type definition, Type type) { while (type != null && type != typeof(object)) { if (type.IsGenericType && type.GetGenericTypeDefinition() == definition) return type; if (definition.IsInterface) { foreach(Type itype in type.GetInterfaces()) { Type found = FindGenericType(definition, itype); if (found != null) return found; } } type = type.BaseType; } return null; } internal static bool IsNullableType(Type type) { return type != null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } internal static Type GetNonNullableType(Type type) { if (IsNullableType(type)) { return type.GetGenericArguments()[0]; } return type; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GetPageCompletedEventArgs.cs
- LogicalCallContext.cs
- HuffModule.cs
- RewritingSimplifier.cs
- DataError.cs
- CustomPopupPlacement.cs
- SqlNodeAnnotations.cs
- SmtpTransport.cs
- AudioFormatConverter.cs
- RenderTargetBitmap.cs
- ItemsControlAutomationPeer.cs
- Token.cs
- SymbolDocumentInfo.cs
- TrustManager.cs
- IncrementalReadDecoders.cs
- EventLogEntry.cs
- ProcessHostMapPath.cs
- WindowsMenu.cs
- FloaterParaClient.cs
- DynamicValidatorEventArgs.cs
- GridViewColumnCollection.cs
- XmlTextReader.cs
- SmtpLoginAuthenticationModule.cs
- LayoutEngine.cs
- XhtmlBasicValidationSummaryAdapter.cs
- RegexNode.cs
- DataServiceQueryOfT.cs
- FlowDocumentPageViewerAutomationPeer.cs
- ObjectStateManager.cs
- Baml2006ReaderSettings.cs
- StringExpressionSet.cs
- OutputCacheSettings.cs
- DoubleLinkList.cs
- QuaternionAnimation.cs
- XmlSchemaSimpleType.cs
- MessagingDescriptionAttribute.cs
- SQLDoubleStorage.cs
- MappableObjectManager.cs
- IMembershipProvider.cs
- DataGridViewRowPostPaintEventArgs.cs
- ColumnHeaderConverter.cs
- TextTreeUndo.cs
- _Events.cs
- TextElement.cs
- TransportChannelFactory.cs
- ClosableStream.cs
- ClientUtils.cs
- Transform.cs
- ParserExtension.cs
- XmlCharacterData.cs
- RawContentTypeMapper.cs
- PrintDialog.cs
- SubpageParagraph.cs
- ViewSimplifier.cs
- PlanCompilerUtil.cs
- Single.cs
- VisualStyleElement.cs
- NumericExpr.cs
- VisualStyleTypesAndProperties.cs
- MembershipPasswordException.cs
- WebCategoryAttribute.cs
- DirectoryInfo.cs
- SynchronousChannel.cs
- EncoderParameter.cs
- DefaultValueMapping.cs
- Setter.cs
- CacheMemory.cs
- Frame.cs
- _PooledStream.cs
- ModuleBuilderData.cs
- assemblycache.cs
- FontStyle.cs
- SessionStateContainer.cs
- IBuiltInEvidence.cs
- GAC.cs
- GridViewPageEventArgs.cs
- EllipticalNodeOperations.cs
- SpAudioStreamWrapper.cs
- DataColumnPropertyDescriptor.cs
- BaseParser.cs
- ValidatingReaderNodeData.cs
- HyperLink.cs
- MessageContractImporter.cs
- UrlMappingCollection.cs
- BitmapEffectInput.cs
- HitTestResult.cs
- CollectionsUtil.cs
- SiteMapHierarchicalDataSourceView.cs
- WhitespaceSignificantCollectionAttribute.cs
- DesignerCommandSet.cs
- MetaDataInfo.cs
- DataSvcMapFile.cs
- IntSecurity.cs
- JoinCqlBlock.cs
- SortQuery.cs
- EntityObject.cs
- StringInfo.cs
- GeometryCollection.cs
- DataSourceIDConverter.cs
- Aggregates.cs