Code:
/ FX-1434 / FX-1434 / 1.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
- BasicCommandTreeVisitor.cs
- Identity.cs
- ObjectItemCollection.cs
- PrimitiveRenderer.cs
- TextSelection.cs
- Double.cs
- Trigger.cs
- ClientTarget.cs
- FrameDimension.cs
- DBNull.cs
- ClientBuildManagerCallback.cs
- ObjectViewFactory.cs
- NumericUpDownAccelerationCollection.cs
- Size.cs
- DecoderFallbackWithFailureFlag.cs
- Imaging.cs
- ControlTemplate.cs
- MasterPageCodeDomTreeGenerator.cs
- Window.cs
- TypeReference.cs
- AxWrapperGen.cs
- AllowedAudienceUriElementCollection.cs
- TextLineResult.cs
- VisualBasicSettings.cs
- ToolStripScrollButton.cs
- TextPenaltyModule.cs
- WindowsGraphicsWrapper.cs
- ListViewTableCell.cs
- SaveFileDialog.cs
- DBCommandBuilder.cs
- HostingEnvironmentSection.cs
- DoubleCollectionConverter.cs
- Clock.cs
- DocumentPageView.cs
- FontSource.cs
- ResourceDisplayNameAttribute.cs
- CultureInfoConverter.cs
- ReplacementText.cs
- TransactionManager.cs
- EntityModelSchemaGenerator.cs
- WindowsFormsHelpers.cs
- MonthChangedEventArgs.cs
- CellTreeNodeVisitors.cs
- MissingSatelliteAssemblyException.cs
- SignedPkcs7.cs
- ThreadExceptionDialog.cs
- DataViewListener.cs
- ActiveXHost.cs
- RegexBoyerMoore.cs
- DocumentsTrace.cs
- RightsManagementEncryptionTransform.cs
- XmlWellformedWriter.cs
- FlowDocumentScrollViewer.cs
- FormClosedEvent.cs
- DbgCompiler.cs
- DebugView.cs
- safemediahandle.cs
- COM2FontConverter.cs
- DataGridCellAutomationPeer.cs
- HebrewCalendar.cs
- GatewayIPAddressInformationCollection.cs
- WebUtility.cs
- ListViewItem.cs
- BoundPropertyEntry.cs
- CodeTypeReferenceCollection.cs
- SessionStateUtil.cs
- XmlNamespaceDeclarationsAttribute.cs
- WorkflowRuntime.cs
- StorageAssociationSetMapping.cs
- BitmapSource.cs
- OneOf.cs
- Page.cs
- FilterableAttribute.cs
- MediaElementAutomationPeer.cs
- Duration.cs
- RequestCachingSection.cs
- TextServicesDisplayAttributePropertyRanges.cs
- CatalogPartChrome.cs
- TemplateAction.cs
- BulletedListEventArgs.cs
- TypeDependencyAttribute.cs
- OleDbConnectionInternal.cs
- RegexCharClass.cs
- SignatureHelper.cs
- SByte.cs
- QilInvokeEarlyBound.cs
- ExpressionLink.cs
- WindowsSysHeader.cs
- ToolTip.cs
- AnnouncementSendsAsyncResult.cs
- AuthenticationSection.cs
- EntityCodeGenerator.cs
- Buffer.cs
- CallbackHandler.cs
- WrapPanel.cs
- OneToOneMappingSerializer.cs
- ElementAction.cs
- RefType.cs
- ShaperBuffers.cs
- LineBreakRecord.cs