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
- RolePrincipal.cs
- OracleNumber.cs
- FunctionDetailsReader.cs
- RelationshipDetailsRow.cs
- BaseCollection.cs
- Line.cs
- CapabilitiesRule.cs
- Win32Native.cs
- XmlCodeExporter.cs
- DataGridCell.cs
- Soap11ServerProtocol.cs
- ContextMarshalException.cs
- ScalarType.cs
- DataBindingHandlerAttribute.cs
- OperationAbortedException.cs
- List.cs
- StsCommunicationException.cs
- WebPartExportVerb.cs
- TrackingServices.cs
- DataGridViewEditingControlShowingEventArgs.cs
- PageParserFilter.cs
- PeerName.cs
- VScrollBar.cs
- SmiEventStream.cs
- DocumentViewerBase.cs
- WindowsStatusBar.cs
- CheckPair.cs
- FrameworkTemplate.cs
- HtmlButton.cs
- ISCIIEncoding.cs
- HwndSubclass.cs
- DomNameTable.cs
- _TransmitFileOverlappedAsyncResult.cs
- HtmlTitle.cs
- Control.cs
- ActivityExecutionContextCollection.cs
- StackBuilderSink.cs
- Enum.cs
- DataGridViewColumnConverter.cs
- QueryAsyncResult.cs
- QilFactory.cs
- XmlDataSourceView.cs
- DataRelationPropertyDescriptor.cs
- StylusPointCollection.cs
- ApplicationSecurityManager.cs
- MatrixCamera.cs
- Missing.cs
- IncomingWebRequestContext.cs
- CqlQuery.cs
- XmlSubtreeReader.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- EntityClientCacheEntry.cs
- UsernameTokenFactoryCredential.cs
- MsmqIntegrationSecurity.cs
- BamlTreeMap.cs
- FormatterServices.cs
- Transactions.cs
- AdornerLayer.cs
- Solver.cs
- HttpErrorTraceRecord.cs
- SafeMILHandleMemoryPressure.cs
- XMLSyntaxException.cs
- ClusterRegistryConfigurationProvider.cs
- RadioButtonList.cs
- GC.cs
- DocumentSchemaValidator.cs
- SmtpNtlmAuthenticationModule.cs
- Assembly.cs
- CodeIterationStatement.cs
- PathSegmentCollection.cs
- HGlobalSafeHandle.cs
- QilFunction.cs
- ObjectStateFormatter.cs
- SecurityResources.cs
- InertiaRotationBehavior.cs
- GridViewPageEventArgs.cs
- ModelChangedEventArgsImpl.cs
- SpecialFolderEnumConverter.cs
- DetailsViewUpdateEventArgs.cs
- OptimisticConcurrencyException.cs
- NavigatorInput.cs
- GeometryHitTestResult.cs
- ModulesEntry.cs
- ContentPosition.cs
- Ipv6Element.cs
- EmptyEnumerator.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- IdentityHolder.cs
- RouteCollection.cs
- ColorPalette.cs
- WebHeaderCollection.cs
- CalendarTable.cs
- DataGridViewRowPrePaintEventArgs.cs
- CodeNamespaceImportCollection.cs
- BaseDataList.cs
- ScriptControl.cs
- MultipleViewPatternIdentifiers.cs
- IBuiltInEvidence.cs
- BitConverter.cs
- SmtpNegotiateAuthenticationModule.cs