Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWebControls / System / Data / WebControls / EntityDataSourceViewSchema.cs / 1 / EntityDataSourceViewSchema.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Linq; using System.Text; using System.Reflection; namespace System.Web.UI.WebControls { internal class EntityDataSourceViewSchema : DataTable { internal EntityDataSourceViewSchema(EntityDataSourceWrapperCollection wrappers) { DataColumn column; Listkeys = new List (); PropertyDescriptorCollection properties = wrappers.GetItemProperties(null); MetadataWorkspace workspace = wrappers.Context.MetadataWorkspace; foreach (EntityDataSourceWrapperPropertyDescriptor property in properties) { Type propertyType = property.PropertyType; column = ConstructColumn(property); column.AllowDBNull = property.Column.IsNullable; EntityDataSourcePropertyColumn propertyColumn = property.Column as EntityDataSourcePropertyColumn; if (null!= propertyColumn && propertyColumn.IsKey) { keys.Add(column); } Columns.Add(column); } this.PrimaryKey = keys.ToArray(); } internal EntityDataSourceViewSchema(ITypedList typedList) { PropertyDescriptorCollection properties = typedList.GetItemProperties(null); CreateColumnsFromPropDescs(properties); } internal EntityDataSourceViewSchema(IEnumerable results) { Type type = GetListItemType(results.GetType()); PropertyInfo[] infos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(type); CreateColumnsFromPropDescs(properties); } private void CreateColumnsFromPropDescs(PropertyDescriptorCollection properties) { foreach (PropertyDescriptor property in properties) { System.ComponentModel.BrowsableAttribute attr = (System.ComponentModel.BrowsableAttribute)property.Attributes[typeof(System.ComponentModel.BrowsableAttribute)]; if (attr.Browsable) { DataColumn column = ConstructColumn(property); this.Columns.Add(column); } } } private static DataColumn ConstructColumn(PropertyDescriptor property) { DataColumn column = new DataColumn(); column.ColumnName = property.Name; Type propertyType = property.PropertyType; if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { Type[] typeArguments = propertyType.GetGenericArguments(); Debug.Assert(typeArguments.Length == 1, "should only have one type argument from Nullable<> condition."); column.DataType = typeArguments[0]; column.AllowDBNull = true; } else { column.DataType = propertyType; column.AllowDBNull = !propertyType.IsValueType; } column.ReadOnly = property.IsReadOnly; column.Unique = false; column.AutoIncrement = false; column.MaxLength = -1; return column; } // see System.Data.Objects.DataRecordObjectView.cs private static PropertyInfo GetTypedIndexer(Type type) { PropertyInfo indexer = null; if (typeof(IList).IsAssignableFrom(type) || typeof(ITypedList).IsAssignableFrom(type) || typeof(IListSource).IsAssignableFrom(type)) { System.Reflection.PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); for (int idx = 0; idx < props.Length; idx++) { if (props[idx].GetIndexParameters().Length > 0 && props[idx].PropertyType != typeof(object)) { indexer = props[idx]; //Prefer the standard indexer, if there is one if (indexer.Name == "Item") { break; } } } } return indexer; } // see System.Data.Objects.DataRecordObjectView.cs private static Type GetListItemType(Type type) { Type itemType; if (typeof(Array).IsAssignableFrom(type)) { itemType = type.GetElementType(); } else { PropertyInfo typedIndexer = GetTypedIndexer(type); if (typedIndexer != null) { itemType = typedIndexer.PropertyType; } else { itemType = type; } } return itemType; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Linq; using System.Text; using System.Reflection; namespace System.Web.UI.WebControls { internal class EntityDataSourceViewSchema : DataTable { internal EntityDataSourceViewSchema(EntityDataSourceWrapperCollection wrappers) { DataColumn column; Listkeys = new List (); PropertyDescriptorCollection properties = wrappers.GetItemProperties(null); MetadataWorkspace workspace = wrappers.Context.MetadataWorkspace; foreach (EntityDataSourceWrapperPropertyDescriptor property in properties) { Type propertyType = property.PropertyType; column = ConstructColumn(property); column.AllowDBNull = property.Column.IsNullable; EntityDataSourcePropertyColumn propertyColumn = property.Column as EntityDataSourcePropertyColumn; if (null!= propertyColumn && propertyColumn.IsKey) { keys.Add(column); } Columns.Add(column); } this.PrimaryKey = keys.ToArray(); } internal EntityDataSourceViewSchema(ITypedList typedList) { PropertyDescriptorCollection properties = typedList.GetItemProperties(null); CreateColumnsFromPropDescs(properties); } internal EntityDataSourceViewSchema(IEnumerable results) { Type type = GetListItemType(results.GetType()); PropertyInfo[] infos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(type); CreateColumnsFromPropDescs(properties); } private void CreateColumnsFromPropDescs(PropertyDescriptorCollection properties) { foreach (PropertyDescriptor property in properties) { System.ComponentModel.BrowsableAttribute attr = (System.ComponentModel.BrowsableAttribute)property.Attributes[typeof(System.ComponentModel.BrowsableAttribute)]; if (attr.Browsable) { DataColumn column = ConstructColumn(property); this.Columns.Add(column); } } } private static DataColumn ConstructColumn(PropertyDescriptor property) { DataColumn column = new DataColumn(); column.ColumnName = property.Name; Type propertyType = property.PropertyType; if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { Type[] typeArguments = propertyType.GetGenericArguments(); Debug.Assert(typeArguments.Length == 1, "should only have one type argument from Nullable<> condition."); column.DataType = typeArguments[0]; column.AllowDBNull = true; } else { column.DataType = propertyType; column.AllowDBNull = !propertyType.IsValueType; } column.ReadOnly = property.IsReadOnly; column.Unique = false; column.AutoIncrement = false; column.MaxLength = -1; return column; } // see System.Data.Objects.DataRecordObjectView.cs private static PropertyInfo GetTypedIndexer(Type type) { PropertyInfo indexer = null; if (typeof(IList).IsAssignableFrom(type) || typeof(ITypedList).IsAssignableFrom(type) || typeof(IListSource).IsAssignableFrom(type)) { System.Reflection.PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); for (int idx = 0; idx < props.Length; idx++) { if (props[idx].GetIndexParameters().Length > 0 && props[idx].PropertyType != typeof(object)) { indexer = props[idx]; //Prefer the standard indexer, if there is one if (indexer.Name == "Item") { break; } } } } return indexer; } // see System.Data.Objects.DataRecordObjectView.cs private static Type GetListItemType(Type type) { Type itemType; if (typeof(Array).IsAssignableFrom(type)) { itemType = type.GetElementType(); } else { PropertyInfo typedIndexer = GetTypedIndexer(type); if (typedIndexer != null) { itemType = typedIndexer.PropertyType; } else { itemType = type; } } return itemType; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLString.cs
- BinaryCommonClasses.cs
- SQLDateTimeStorage.cs
- AuthenticationConfig.cs
- XmlSerializer.cs
- ReachBasicContext.cs
- ConfigurationManager.cs
- SchemaContext.cs
- DataGridCell.cs
- SpanIndex.cs
- GridViewDeletedEventArgs.cs
- CharKeyFrameCollection.cs
- XmlElementList.cs
- UIElementCollection.cs
- BaseInfoTable.cs
- ConnectionsZoneAutoFormat.cs
- HttpCapabilitiesBase.cs
- JpegBitmapDecoder.cs
- DependencyPropertyConverter.cs
- DesignSurface.cs
- XmlSchemaComplexContentRestriction.cs
- MultiByteCodec.cs
- ConfigurationManagerHelper.cs
- ObjectCache.cs
- ToolStripPanelRenderEventArgs.cs
- CodeConstructor.cs
- RelatedEnd.cs
- ClipboardProcessor.cs
- ContractBase.cs
- HeaderedItemsControl.cs
- CompositeFontFamily.cs
- SafeFindHandle.cs
- HtmlCalendarAdapter.cs
- LambdaReference.cs
- MissingSatelliteAssemblyException.cs
- Selection.cs
- OledbConnectionStringbuilder.cs
- MetadataArtifactLoaderCompositeFile.cs
- TaiwanLunisolarCalendar.cs
- DrawingVisual.cs
- WebException.cs
- TextFormatterImp.cs
- ResXDataNode.cs
- ConfigurationSectionGroup.cs
- CombinedGeometry.cs
- MSHTMLHost.cs
- Quaternion.cs
- AssemblyName.cs
- ViewCellSlot.cs
- CodeCatchClauseCollection.cs
- WebPartConnectionsConfigureVerb.cs
- DocumentsTrace.cs
- DeclaredTypeValidatorAttribute.cs
- KernelTypeValidation.cs
- CodeVariableDeclarationStatement.cs
- CompressedStack.cs
- DispatcherExceptionEventArgs.cs
- InvokeMethodActivityDesigner.cs
- SystemIPAddressInformation.cs
- SamlAttribute.cs
- SafeEventLogWriteHandle.cs
- DbReferenceCollection.cs
- SchemaAttDef.cs
- EntityStoreSchemaGenerator.cs
- SecureUICommand.cs
- CompoundFileStreamReference.cs
- RangeContentEnumerator.cs
- Rect.cs
- BatchServiceHost.cs
- SmtpFailedRecipientException.cs
- SqlBooleanMismatchVisitor.cs
- ReversePositionQuery.cs
- ProfileSettings.cs
- StandardBindingReliableSessionElement.cs
- ProfilePropertySettings.cs
- ProfilePropertySettingsCollection.cs
- PartialList.cs
- GregorianCalendar.cs
- XmlImplementation.cs
- Util.cs
- RuleSettings.cs
- ProxyElement.cs
- XmlSerializer.cs
- MediaElementAutomationPeer.cs
- ToolBarTray.cs
- CopyAction.cs
- ObjectConverter.cs
- TileBrush.cs
- sqlcontext.cs
- AuthorizationRuleCollection.cs
- CollectionContainer.cs
- FacetChecker.cs
- TaskFileService.cs
- GenericRootAutomationPeer.cs
- SchemaEntity.cs
- ModuleElement.cs
- XPathNodeInfoAtom.cs
- SQLConvert.cs
- HostedElements.cs
- ListViewSortEventArgs.cs