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
- ObjectResult.cs
- DocumentScope.cs
- ExpressionBuilder.cs
- DocumentViewerHelper.cs
- CheckBoxStandardAdapter.cs
- AnnotationHighlightLayer.cs
- OrderedParallelQuery.cs
- SortQueryOperator.cs
- PeerMessageDispatcher.cs
- TextFormatter.cs
- LowerCaseStringConverter.cs
- MexServiceChannelBuilder.cs
- HtmlSelect.cs
- ControlEvent.cs
- ContainerSelectorBehavior.cs
- TextServicesProperty.cs
- PrinterUnitConvert.cs
- SiteMapProvider.cs
- ContainerUIElement3D.cs
- CodeMemberField.cs
- Rijndael.cs
- SQLDateTimeStorage.cs
- SolidColorBrush.cs
- FormatConvertedBitmap.cs
- PackUriHelper.cs
- ConfigPathUtility.cs
- SignatureToken.cs
- OdbcErrorCollection.cs
- SemanticValue.cs
- MessageQueueAccessControlEntry.cs
- MaskDescriptor.cs
- PeerApplicationLaunchInfo.cs
- Renderer.cs
- TickBar.cs
- SafeNativeMethods.cs
- ResXResourceWriter.cs
- ProjectedSlot.cs
- StylusPlugin.cs
- AutomationProperty.cs
- RenderDataDrawingContext.cs
- Selector.cs
- CharacterBufferReference.cs
- AppendHelper.cs
- SemanticResultKey.cs
- BaseContextMenu.cs
- SqlProfileProvider.cs
- SQLGuid.cs
- DataPagerCommandEventArgs.cs
- MappingSource.cs
- GenericQueueSurrogate.cs
- WebPartManagerInternals.cs
- UriTemplateCompoundPathSegment.cs
- DirectionalLight.cs
- WhitespaceRule.cs
- DataGridViewRowConverter.cs
- TextServicesProperty.cs
- XmlWhitespace.cs
- util.cs
- WSFederationHttpBindingElement.cs
- SelfIssuedAuthAsymmetricKey.cs
- DataControlImageButton.cs
- JobStaple.cs
- ReferentialConstraint.cs
- OpenTypeCommon.cs
- TypeBuilderInstantiation.cs
- XmlTextReaderImpl.cs
- DesignerListAdapter.cs
- SoapObjectReader.cs
- TemplateInstanceAttribute.cs
- MessageQueueInstaller.cs
- EastAsianLunisolarCalendar.cs
- SamlAttributeStatement.cs
- Parser.cs
- LinkConverter.cs
- TypeSemantics.cs
- FaultBookmark.cs
- NullRuntimeConfig.cs
- X509Certificate.cs
- DynamicILGenerator.cs
- SQLMembershipProvider.cs
- Trace.cs
- FileDetails.cs
- LockCookie.cs
- RecommendedAsConfigurableAttribute.cs
- HttpGetProtocolImporter.cs
- BehaviorDragDropEventArgs.cs
- MenuRendererStandards.cs
- IPEndPointCollection.cs
- JumpItem.cs
- DataTablePropertyDescriptor.cs
- LayoutManager.cs
- WebPartCancelEventArgs.cs
- RouteValueDictionary.cs
- SpellerInterop.cs
- UpdatePanel.cs
- Aggregates.cs
- IApplicationTrustManager.cs
- ListViewUpdateEventArgs.cs
- CodePageEncoding.cs
- BitmapEffectGeneralTransform.cs