Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- MultipleViewPatternIdentifiers.cs
- securitycriticaldata.cs
- BitmapSizeOptions.cs
- CharEnumerator.cs
- UntrustedRecipientException.cs
- CqlQuery.cs
- SynchronousChannel.cs
- BrowserInteropHelper.cs
- PointValueSerializer.cs
- SqlDesignerDataSourceView.cs
- StringValueSerializer.cs
- MarshalByRefObject.cs
- ProfileParameter.cs
- MetadataItemCollectionFactory.cs
- PriorityBindingExpression.cs
- JsonSerializer.cs
- BamlLocalizationDictionary.cs
- DBBindings.cs
- WindowsImpersonationContext.cs
- IxmlLineInfo.cs
- ClientSection.cs
- XsdDataContractImporter.cs
- PersonalizationStateInfoCollection.cs
- PropertyPath.cs
- EnlistmentState.cs
- DataGridViewRowPostPaintEventArgs.cs
- SourceChangedEventArgs.cs
- AutomationIdentifier.cs
- HostedNamedPipeTransportManager.cs
- HealthMonitoringSection.cs
- UpdatePanelControlTrigger.cs
- Visitors.cs
- ProtocolsConfigurationEntry.cs
- SevenBitStream.cs
- Add.cs
- VirtualDirectoryMappingCollection.cs
- DataColumnSelectionConverter.cs
- RotateTransform3D.cs
- CharStorage.cs
- RepeaterItemCollection.cs
- FilterFactory.cs
- AuthenticationConfig.cs
- UiaCoreApi.cs
- SpnegoTokenProvider.cs
- XmlResolver.cs
- objectquery_tresulttype.cs
- FormsIdentity.cs
- XmlWhitespace.cs
- MenuBindingsEditorForm.cs
- RawStylusSystemGestureInputReport.cs
- UniqueEventHelper.cs
- Label.cs
- EntitySet.cs
- ListMarkerSourceInfo.cs
- ElapsedEventArgs.cs
- WizardForm.cs
- DescendantBaseQuery.cs
- Table.cs
- _IPv4Address.cs
- util.cs
- TrackBarRenderer.cs
- TypeDescriptionProvider.cs
- ColumnResult.cs
- MetaColumn.cs
- ComplusTypeValidator.cs
- WindowsListBox.cs
- AsymmetricKeyExchangeFormatter.cs
- SkipQueryOptionExpression.cs
- DatagridviewDisplayedBandsData.cs
- NavigationFailedEventArgs.cs
- ObjectDataSourceMethodEventArgs.cs
- MruCache.cs
- JumpItem.cs
- ContravarianceAdapter.cs
- TemplateBuilder.cs
- CodeIterationStatement.cs
- Point4D.cs
- RegionInfo.cs
- StateManagedCollection.cs
- BindUriHelper.cs
- XmlSerializationReader.cs
- PropertyToken.cs
- AspNetHostingPermission.cs
- WebPartHeaderCloseVerb.cs
- Matrix3D.cs
- DataChangedEventManager.cs
- Property.cs
- RotateTransform.cs
- Axis.cs
- EndEvent.cs
- NestPullup.cs
- AlternateView.cs
- TextEditorParagraphs.cs
- ClientBuildManagerCallback.cs
- SqlBuffer.cs
- ToolStripItemClickedEventArgs.cs
- OdbcDataAdapter.cs
- TextDecorations.cs
- StyleCollection.cs
- RegexWriter.cs