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
- SamlAssertion.cs
- TimeoutValidationAttribute.cs
- XmlSerializerAssemblyAttribute.cs
- ByteStorage.cs
- TaiwanCalendar.cs
- SessionEndingEventArgs.cs
- UnsafeNativeMethods.cs
- MarkupCompiler.cs
- ListViewTableRow.cs
- ListSortDescription.cs
- RightsManagementEncryptionTransform.cs
- TemplateControlParser.cs
- DrawingGroup.cs
- ExceptionHandlersDesigner.cs
- ArrangedElement.cs
- D3DImage.cs
- FontSourceCollection.cs
- EventLog.cs
- StateMachineWorkflow.cs
- XmlSchemaParticle.cs
- XpsViewerException.cs
- DocumentCollection.cs
- WindowHideOrCloseTracker.cs
- safex509handles.cs
- TextTrailingCharacterEllipsis.cs
- ConfigurationPermission.cs
- MouseDevice.cs
- Stroke.cs
- CompiledIdentityConstraint.cs
- ActivationArguments.cs
- DoubleLinkListEnumerator.cs
- CellNormalizer.cs
- TCEAdapterGenerator.cs
- Form.cs
- WebPartPersonalization.cs
- CipherData.cs
- ClusterRegistryConfigurationProvider.cs
- WebServiceResponse.cs
- TemplateBindingExpressionConverter.cs
- MouseActionConverter.cs
- AppDomainManager.cs
- DataBoundControlAdapter.cs
- ControlPaint.cs
- BinaryMessageFormatter.cs
- FileSecurity.cs
- UIElement3D.cs
- RuleProcessor.cs
- DataServiceException.cs
- CompilerCollection.cs
- AutomationPeer.cs
- RubberbandSelector.cs
- Process.cs
- DependentList.cs
- PointF.cs
- DrawingState.cs
- ToolZoneDesigner.cs
- TrackingCondition.cs
- ContractValidationHelper.cs
- ErrorProvider.cs
- CopyAction.cs
- GridView.cs
- handlecollector.cs
- SafeSecurityHandles.cs
- CodeBlockBuilder.cs
- FileIOPermission.cs
- PeerUnsafeNativeCryptMethods.cs
- GiveFeedbackEvent.cs
- ExecutedRoutedEventArgs.cs
- MetadataSource.cs
- Axis.cs
- GridViewUpdatedEventArgs.cs
- TreeViewBindingsEditorForm.cs
- SafeThemeHandle.cs
- AttachInfo.cs
- RtfControlWordInfo.cs
- DurationConverter.cs
- WebPartConnectionsCancelEventArgs.cs
- SafeMemoryMappedViewHandle.cs
- CatalogZone.cs
- SiteMapNode.cs
- TriState.cs
- DrawListViewColumnHeaderEventArgs.cs
- WebPartDisplayModeEventArgs.cs
- Point3D.cs
- ImageCodecInfoPrivate.cs
- TableRowGroupCollection.cs
- BufferAllocator.cs
- ProfileInfo.cs
- WebControl.cs
- Rectangle.cs
- ObjectDataSourceDisposingEventArgs.cs
- PanelStyle.cs
- HttpServerUtilityBase.cs
- DecoratedNameAttribute.cs
- XsdDateTime.cs
- PageSettings.cs
- Overlapped.cs
- Ops.cs
- TrackingWorkflowEventArgs.cs
- BamlWriter.cs