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
- TraceInternal.cs
- DefaultProxySection.cs
- ReliabilityContractAttribute.cs
- QueuePathEditor.cs
- OdbcConnectionOpen.cs
- TraceXPathNavigator.cs
- RegexWorker.cs
- TextTreeDeleteContentUndoUnit.cs
- SmiXetterAccessMap.cs
- LineBreakRecord.cs
- PriorityItem.cs
- XmlTextAttribute.cs
- CacheHelper.cs
- EventEntry.cs
- ManagedIStream.cs
- EntityTransaction.cs
- LockedAssemblyCache.cs
- BoundingRectTracker.cs
- XPathCompiler.cs
- SharedPerformanceCounter.cs
- ModelPerspective.cs
- InvariantComparer.cs
- SynthesizerStateChangedEventArgs.cs
- ConfigurationManagerInternalFactory.cs
- ReflectTypeDescriptionProvider.cs
- ValidationSummary.cs
- PageCatalogPart.cs
- XmlValueConverter.cs
- BamlRecordWriter.cs
- ConnectionOrientedTransportChannelListener.cs
- SyndicationElementExtensionCollection.cs
- RoutedEventHandlerInfo.cs
- NavigateEvent.cs
- GPPOINTF.cs
- DispatcherFrame.cs
- PointConverter.cs
- ObjectContextServiceProvider.cs
- Gdiplus.cs
- KeyPullup.cs
- Bezier.cs
- HttpVersion.cs
- WebFaultException.cs
- RefType.cs
- DefaultHttpHandler.cs
- LinqDataSourceDisposeEventArgs.cs
- Itemizer.cs
- CategoryNameCollection.cs
- RevocationPoint.cs
- DataRecordInfo.cs
- RoamingStoreFileUtility.cs
- NamespaceList.cs
- Emitter.cs
- SliderAutomationPeer.cs
- HostedNamedPipeTransportManager.cs
- NegotiationTokenAuthenticatorStateCache.cs
- EntityDataSourceEntityTypeFilterItem.cs
- RenderDataDrawingContext.cs
- LeafCellTreeNode.cs
- InfoCardRSACryptoProvider.cs
- ColorInterpolationModeValidation.cs
- ReachDocumentReferenceSerializer.cs
- StringInfo.cs
- SqlUnionizer.cs
- RemotingSurrogateSelector.cs
- IFlowDocumentViewer.cs
- SamlSubjectStatement.cs
- EmbeddedMailObjectsCollection.cs
- DocumentSignatureManager.cs
- TemplateXamlTreeBuilder.cs
- EqualityComparer.cs
- ConstructorNeedsTagAttribute.cs
- If.cs
- EventHandlersDesigner.cs
- HwndSubclass.cs
- GetImportFileNameRequest.cs
- DataGridViewRowStateChangedEventArgs.cs
- MinMaxParagraphWidth.cs
- FontSizeConverter.cs
- ClientSettingsProvider.cs
- QuadraticBezierSegment.cs
- ConstructorBuilder.cs
- ExpandedProjectionNode.cs
- DecimalAnimation.cs
- SelectorAutomationPeer.cs
- XmlUtil.cs
- ObservableDictionary.cs
- CacheAxisQuery.cs
- DetailsViewPageEventArgs.cs
- FlowDocumentReaderAutomationPeer.cs
- ResourcesBuildProvider.cs
- ClientTargetSection.cs
- UnicastIPAddressInformationCollection.cs
- Psha1DerivedKeyGeneratorHelper.cs
- SQLInt64Storage.cs
- SecurityMessageProperty.cs
- HitTestFilterBehavior.cs
- HebrewCalendar.cs
- GridViewColumnCollectionChangedEventArgs.cs
- SafeRightsManagementHandle.cs
- RequestQueryParser.cs