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
- ToolStripArrowRenderEventArgs.cs
- ColumnReorderedEventArgs.cs
- IsolatedStorageFilePermission.cs
- ConfigXmlText.cs
- StateMachineDesignerPaint.cs
- ListBoxAutomationPeer.cs
- ConnectionStringSettingsCollection.cs
- DiffuseMaterial.cs
- FixedSOMPageElement.cs
- DbProviderConfigurationHandler.cs
- AttachmentCollection.cs
- PersonalizationState.cs
- QilUnary.cs
- DebuggerAttributes.cs
- DBSchemaTable.cs
- PlaceHolder.cs
- ServicePointManagerElement.cs
- CategoryAttribute.cs
- ValueTable.cs
- SecurityVerifiedMessage.cs
- TextClipboardData.cs
- DataRecordInternal.cs
- CollectionTypeElement.cs
- DocumentViewerBaseAutomationPeer.cs
- DefaultEvaluationContext.cs
- QueryResult.cs
- MasterPage.cs
- HeaderedItemsControl.cs
- CodeAttributeDeclarationCollection.cs
- BaseCollection.cs
- SplitterEvent.cs
- CalendarDataBindingHandler.cs
- TextureBrush.cs
- NavigationPropertyEmitter.cs
- MexHttpsBindingCollectionElement.cs
- CollectionViewGroupInternal.cs
- WebDescriptionAttribute.cs
- CustomValidator.cs
- XmlElement.cs
- TreeNodeEventArgs.cs
- ColorMatrix.cs
- KeyBinding.cs
- FontFamily.cs
- SplayTreeNode.cs
- ListViewSortEventArgs.cs
- DataGridViewRowCollection.cs
- SqlDataSourceCache.cs
- LabelEditEvent.cs
- WinEventTracker.cs
- SharedStatics.cs
- shaper.cs
- PkcsMisc.cs
- EventSinkActivity.cs
- TextRange.cs
- Calendar.cs
- InvokePattern.cs
- SiteMapNodeItem.cs
- UnsafeNativeMethods.cs
- _ChunkParse.cs
- MarginsConverter.cs
- PersonalizationProviderCollection.cs
- Types.cs
- CompiledAction.cs
- NavigationProgressEventArgs.cs
- PageThemeBuildProvider.cs
- WindowsComboBox.cs
- DirectoryNotFoundException.cs
- BuildResult.cs
- SelectionEditingBehavior.cs
- Inflater.cs
- MenuItemStyle.cs
- RetrieveVirtualItemEventArgs.cs
- _AutoWebProxyScriptWrapper.cs
- UrlAuthFailedErrorFormatter.cs
- DisposableCollectionWrapper.cs
- SoapTypeAttribute.cs
- ProfileSettings.cs
- DataGridViewColumnCollection.cs
- FileDialog_Vista.cs
- CustomLineCap.cs
- PropertyOverridesTypeEditor.cs
- XNodeNavigator.cs
- NamespaceInfo.cs
- objectresult_tresulttype.cs
- HtmlInputSubmit.cs
- LassoHelper.cs
- TileModeValidation.cs
- SystemColors.cs
- DataListItemEventArgs.cs
- HtmlInputPassword.cs
- Subtract.cs
- SafeProcessHandle.cs
- GeometryModel3D.cs
- ListenerSessionConnection.cs
- HttpListenerException.cs
- ObjectQuery_EntitySqlExtensions.cs
- TransactedReceiveScope.cs
- PropertyToken.cs
- DSACryptoServiceProvider.cs
- TreeNodeCollection.cs