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
- DataBoundControlAdapter.cs
- StyleHelper.cs
- WebPartZoneCollection.cs
- XPathSelectionIterator.cs
- SimpleHandlerFactory.cs
- EdmTypeAttribute.cs
- userdatakeys.cs
- InvalidateEvent.cs
- CompilationUnit.cs
- RenderDataDrawingContext.cs
- LocalizeDesigner.cs
- BaseHashHelper.cs
- ValidationErrorEventArgs.cs
- Brushes.cs
- SettingsSection.cs
- ComplusTypeValidator.cs
- DataBindingList.cs
- ModelFunction.cs
- RunClient.cs
- TraceContext.cs
- __ComObject.cs
- FirstQueryOperator.cs
- InternalsVisibleToAttribute.cs
- PlatformNotSupportedException.cs
- ConnectionConsumerAttribute.cs
- GrammarBuilderBase.cs
- CacheVirtualItemsEvent.cs
- SystemBrushes.cs
- BamlLocalizer.cs
- XmlSignificantWhitespace.cs
- Literal.cs
- X509CertificateChain.cs
- StandardOleMarshalObject.cs
- DataSourceExpressionCollection.cs
- FilterException.cs
- MetadataWorkspace.cs
- DataGridViewRowsRemovedEventArgs.cs
- TableLayoutSettings.cs
- Number.cs
- ApplicationManager.cs
- x509utils.cs
- COM2PictureConverter.cs
- SolidColorBrush.cs
- InternalPolicyElement.cs
- OperationFormatUse.cs
- WebConfigurationHost.cs
- FormViewRow.cs
- CollectionViewProxy.cs
- InstanceHandleConflictException.cs
- TargetControlTypeCache.cs
- Compilation.cs
- ListMarkerSourceInfo.cs
- ValidationRuleCollection.cs
- EnvelopedPkcs7.cs
- TextBoxDesigner.cs
- TextTrailingWordEllipsis.cs
- dataobject.cs
- Utils.cs
- ScrollBarAutomationPeer.cs
- DataGridCellItemAutomationPeer.cs
- DataListItem.cs
- XmlAutoDetectWriter.cs
- EndpointConfigContainer.cs
- ProbeMatchesApril2005.cs
- TableLayoutRowStyleCollection.cs
- LostFocusEventManager.cs
- OutputCacheProfile.cs
- Task.cs
- SiteMapNodeCollection.cs
- ActivityDefaults.cs
- ObjectSecurityT.cs
- ContentFilePart.cs
- Timer.cs
- BrushValueSerializer.cs
- SerializationException.cs
- DSASignatureFormatter.cs
- ToolStripContainerActionList.cs
- CaseInsensitiveComparer.cs
- TransformGroup.cs
- TileBrush.cs
- IndexedGlyphRun.cs
- TPLETWProvider.cs
- Tool.cs
- BitmapMetadataEnumerator.cs
- TagPrefixAttribute.cs
- XmlDomTextWriter.cs
- baseaxisquery.cs
- LogReservationCollection.cs
- RenderDataDrawingContext.cs
- BorderSidesEditor.cs
- SimpleBitVector32.cs
- BitmapEncoder.cs
- CustomMenuItemCollection.cs
- TextBounds.cs
- MessageBox.cs
- _NetworkingPerfCounters.cs
- RangeContentEnumerator.cs
- ProcessHost.cs
- EntityParameterCollection.cs
- DispatcherOperation.cs