Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / TypeGenericEnumerableViewSchema.cs / 2 / TypeGenericEnumerableViewSchema.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
///
/// Represents a View's schema based on a generic IEnumerable. The
/// strongly-typed row type is determined based on the generic argument
/// of the enumerable.
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
internal sealed class TypeGenericEnumerableViewSchema : BaseTypeViewSchema {
public TypeGenericEnumerableViewSchema(string viewName, Type type)
: base(viewName, type) {
Debug.Assert(TypeSchema.IsBoundGenericEnumerable(type), String.Format(CultureInfo.InvariantCulture, "The type '{0}' does not implement System.Collections.Generic.IEnumerable, or the argument T is not bound to a type.", type.FullName));
}
protected override Type GetRowType(Type objectType) {
// Get the IEnumerable declaration
Type enumerableType = null;
if (objectType.IsInterface && objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) {
// If the type already is IEnumerable, that's the interface we want to inspect
enumerableType = objectType;
}
else {
// Otherwise we get a list of all the interafaces the type implements
Type[] interfaces = objectType.GetInterfaces();
foreach (Type i in interfaces) {
if (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>)) {
enumerableType = i;
break;
}
}
}
Debug.Assert(enumerableType != null, "Should have found an implementation of IEnumerable");
// Now return the value of the T argument
Type[] genericArguments = enumerableType.GetGenericArguments();
Debug.Assert(genericArguments != null && genericArguments.Length == 1, "Expected IEnumerable to have a generic argument");
// If a type has IsGenericParameter=true that means it is not bound.
if (genericArguments[0].IsGenericParameter) {
Debug.Fail("Expected the type argument to IEnumerable to be bound");
return null;
}
else {
return genericArguments[0];
}
}
}
}
// 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
- _SSPISessionCache.cs
- XNodeValidator.cs
- AddInAttribute.cs
- LazyTextWriterCreator.cs
- TextAutomationPeer.cs
- ScrollPattern.cs
- WebPart.cs
- ProgressPage.cs
- ITreeGenerator.cs
- CqlWriter.cs
- PlanCompilerUtil.cs
- SupportingTokenDuplexChannel.cs
- ActivityValidationServices.cs
- CursorConverter.cs
- ExtensionSimplifierMarkupObject.cs
- TableLayoutRowStyleCollection.cs
- DependencyPropertyConverter.cs
- MetadataArtifactLoaderCompositeFile.cs
- SqlConnectionHelper.cs
- HttpDigestClientCredential.cs
- TemplatePagerField.cs
- TextEditorDragDrop.cs
- XmlParser.cs
- Metadata.cs
- ItemCollection.cs
- RefExpr.cs
- SeverityFilter.cs
- SafeReadContext.cs
- datacache.cs
- ProcessHostConfigUtils.cs
- RectKeyFrameCollection.cs
- ThemeInfoAttribute.cs
- DrawingGroup.cs
- WebPartsPersonalizationAuthorization.cs
- CipherData.cs
- ScriptIgnoreAttribute.cs
- BidOverLoads.cs
- ExtentKey.cs
- TreeViewHitTestInfo.cs
- HScrollBar.cs
- XmlBoundElement.cs
- ToolStripDropTargetManager.cs
- CatalogZoneAutoFormat.cs
- PropertyFilterAttribute.cs
- DbProviderServices.cs
- RNGCryptoServiceProvider.cs
- QuaternionAnimation.cs
- GridViewColumnHeader.cs
- EntryPointNotFoundException.cs
- CounterCreationDataCollection.cs
- RegionData.cs
- WindowsIPAddress.cs
- Divide.cs
- DelegateArgumentReference.cs
- CodeSnippetTypeMember.cs
- EditingScopeUndoUnit.cs
- Vertex.cs
- COAUTHIDENTITY.cs
- DiscoveryClientElement.cs
- MembershipSection.cs
- FastEncoderWindow.cs
- DataViewListener.cs
- OdbcConnectionString.cs
- StoreAnnotationsMap.cs
- StringSorter.cs
- IndexedWhereQueryOperator.cs
- TextElementEnumerator.cs
- HMACSHA256.cs
- CursorConverter.cs
- AspCompat.cs
- MultipleViewProviderWrapper.cs
- BodyGlyph.cs
- ExpanderAutomationPeer.cs
- CombinedGeometry.cs
- GCHandleCookieTable.cs
- ExpanderAutomationPeer.cs
- OleDbStruct.cs
- _LocalDataStore.cs
- ToolBarButtonDesigner.cs
- EntityWrapperFactory.cs
- TextParagraph.cs
- XmlSerializationGeneratedCode.cs
- ProfilePropertyNameValidator.cs
- ProxyWebPartManagerDesigner.cs
- ResolveMatchesCD1.cs
- InheritanceAttribute.cs
- NumberSubstitution.cs
- DataKeyArray.cs
- ProtectedConfigurationSection.cs
- TripleDES.cs
- SurrogateSelector.cs
- Keyboard.cs
- _OverlappedAsyncResult.cs
- TextPenaltyModule.cs
- Drawing.cs
- XmlSchemaDatatype.cs
- ConnectivityStatus.cs
- WebPartUtil.cs
- ToolBarPanel.cs
- X509AudioLogo.cs