Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Objects / DataRecordObjectView.cs / 1 / DataRecordObjectView.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner jhutson
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Data.Metadata;
using System.Data.Metadata.Edm;
using System.Reflection;
namespace System.Data.Objects
{
///
/// ObjectView that provides binding to a list of data records.
///
///
/// This class provides an implementation of ITypedList that returns property descriptors
/// for each column of results in a data record.
///
internal sealed class DataRecordObjectView : ObjectView, ITypedList
{
///
/// Cache of the property descriptors for the element type of the root list wrapped by ObjectView.
///
private PropertyDescriptorCollection _propertyDescriptorsCache;
///
/// EDM RowType that describes the shape of record elements.
///
private RowType _rowType;
internal DataRecordObjectView(IObjectViewData viewData, object eventDataSource, RowType rowType, Type propertyComponentType)
: base(viewData, eventDataSource)
{
if (!typeof(IDataRecord).IsAssignableFrom(propertyComponentType))
{
propertyComponentType = typeof(IDataRecord);
}
_rowType = rowType;
_propertyDescriptorsCache = MaterializedDataRecord.CreatePropertyDescriptorCollection(_rowType, propertyComponentType, true);
}
///
/// Return a instance that represents
/// a strongly-typed indexer property on the specified type.
///
///
/// that may define the appropriate indexer.
///
///
/// instance of indexer defined on supplied type
/// that returns an object of any type but ;
/// or null if no such indexer is defined on the supplied type.
///
///
/// The algorithm here is lifted from System.Windows.Forms.ListBindingHelper,
/// from the GetTypedIndexer method.
/// The Entity Framework could not take a dependency on WinForms,
/// so we lifted the appropriate parts from the WinForms code here.
/// A bit ----, but much better than guessing as to what algorithm is proper for data binding.
///
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;
}
///
/// Return the element type for the supplied type.
///
///
///
/// If represents a list type that doesn't also implement ITypedList or IListSource,
/// return the element type for items in that list.
/// Otherwise, return the type supplied by .
///
///
/// The algorithm here is lifted from System.Windows.Forms.ListBindingHelper,
/// from the GetListItemType(object) method.
/// The Entity Framework could not take a dependency on WinForms,
/// so we lifted the appropriate parts from the WinForms code here.
/// A bit ----, but much better than guessing as to what algorithm is proper for data binding.
///
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;
}
#region ITypedList Members
PropertyDescriptorCollection System.ComponentModel.ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection propertyDescriptors;
if (listAccessors == null || listAccessors.Length == 0)
{
// Caller is requesting property descriptors for the root element type.
propertyDescriptors = _propertyDescriptorsCache;
}
else
{
// Use the last PropertyDescriptor in the array to build the collection of returned property descriptors.
PropertyDescriptor propertyDescriptor = listAccessors[listAccessors.Length - 1];
FieldDescriptor fieldDescriptor = propertyDescriptor as FieldDescriptor;
// If the property descriptor describes a data record with the EDM type of RowType,
// construct the collection of property descriptors from the property's EDM metadata.
// Otherwise use the CLR type of the property.
if (fieldDescriptor != null && fieldDescriptor.EdmProperty != null && fieldDescriptor.EdmProperty.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.RowType)
{
// Retrieve property descriptors from EDM metadata.
propertyDescriptors = MaterializedDataRecord.CreatePropertyDescriptorCollection((RowType)fieldDescriptor.EdmProperty.TypeUsage.EdmType, typeof(IDataRecord), true);
}
else
{
// Use the CLR type.
propertyDescriptors = TypeDescriptor.GetProperties(GetListItemType(propertyDescriptor.PropertyType));
}
}
return propertyDescriptors;
}
string System.ComponentModel.ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return _rowType.Name;
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner jhutson
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Data.Metadata;
using System.Data.Metadata.Edm;
using System.Reflection;
namespace System.Data.Objects
{
///
/// ObjectView that provides binding to a list of data records.
///
///
/// This class provides an implementation of ITypedList that returns property descriptors
/// for each column of results in a data record.
///
internal sealed class DataRecordObjectView : ObjectView, ITypedList
{
///
/// Cache of the property descriptors for the element type of the root list wrapped by ObjectView.
///
private PropertyDescriptorCollection _propertyDescriptorsCache;
///
/// EDM RowType that describes the shape of record elements.
///
private RowType _rowType;
internal DataRecordObjectView(IObjectViewData viewData, object eventDataSource, RowType rowType, Type propertyComponentType)
: base(viewData, eventDataSource)
{
if (!typeof(IDataRecord).IsAssignableFrom(propertyComponentType))
{
propertyComponentType = typeof(IDataRecord);
}
_rowType = rowType;
_propertyDescriptorsCache = MaterializedDataRecord.CreatePropertyDescriptorCollection(_rowType, propertyComponentType, true);
}
///
/// Return a instance that represents
/// a strongly-typed indexer property on the specified type.
///
///
/// that may define the appropriate indexer.
///
///
/// instance of indexer defined on supplied type
/// that returns an object of any type but ;
/// or null if no such indexer is defined on the supplied type.
///
///
/// The algorithm here is lifted from System.Windows.Forms.ListBindingHelper,
/// from the GetTypedIndexer method.
/// The Entity Framework could not take a dependency on WinForms,
/// so we lifted the appropriate parts from the WinForms code here.
/// A bit ----, but much better than guessing as to what algorithm is proper for data binding.
///
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;
}
///
/// Return the element type for the supplied type.
///
///
///
/// If represents a list type that doesn't also implement ITypedList or IListSource,
/// return the element type for items in that list.
/// Otherwise, return the type supplied by .
///
///
/// The algorithm here is lifted from System.Windows.Forms.ListBindingHelper,
/// from the GetListItemType(object) method.
/// The Entity Framework could not take a dependency on WinForms,
/// so we lifted the appropriate parts from the WinForms code here.
/// A bit ----, but much better than guessing as to what algorithm is proper for data binding.
///
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;
}
#region ITypedList Members
PropertyDescriptorCollection System.ComponentModel.ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection propertyDescriptors;
if (listAccessors == null || listAccessors.Length == 0)
{
// Caller is requesting property descriptors for the root element type.
propertyDescriptors = _propertyDescriptorsCache;
}
else
{
// Use the last PropertyDescriptor in the array to build the collection of returned property descriptors.
PropertyDescriptor propertyDescriptor = listAccessors[listAccessors.Length - 1];
FieldDescriptor fieldDescriptor = propertyDescriptor as FieldDescriptor;
// If the property descriptor describes a data record with the EDM type of RowType,
// construct the collection of property descriptors from the property's EDM metadata.
// Otherwise use the CLR type of the property.
if (fieldDescriptor != null && fieldDescriptor.EdmProperty != null && fieldDescriptor.EdmProperty.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.RowType)
{
// Retrieve property descriptors from EDM metadata.
propertyDescriptors = MaterializedDataRecord.CreatePropertyDescriptorCollection((RowType)fieldDescriptor.EdmProperty.TypeUsage.EdmType, typeof(IDataRecord), true);
}
else
{
// Use the CLR type.
propertyDescriptors = TypeDescriptor.GetProperties(GetListItemType(propertyDescriptor.PropertyType));
}
}
return propertyDescriptors;
}
string System.ComponentModel.ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return _rowType.Name;
}
#endregion
}
}
// 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
- SimpleType.cs
- UmAlQuraCalendar.cs
- HttpHandlersSection.cs
- ContentPresenter.cs
- HttpCachePolicyWrapper.cs
- PackagePart.cs
- XmlSchemaSimpleTypeList.cs
- SqlProvider.cs
- DictionaryEntry.cs
- SerializationBinder.cs
- BmpBitmapEncoder.cs
- QueryFunctions.cs
- ClientApiGenerator.cs
- DataServiceConfiguration.cs
- ToggleProviderWrapper.cs
- GuidConverter.cs
- SqlUnionizer.cs
- ObjectCloneHelper.cs
- IListConverters.cs
- _TimerThread.cs
- OleDbErrorCollection.cs
- IDQuery.cs
- SystemIPInterfaceProperties.cs
- QueryParameter.cs
- PtsHelper.cs
- CompiledQueryCacheEntry.cs
- CacheMode.cs
- SoapConverter.cs
- OperationDescriptionCollection.cs
- ListSortDescription.cs
- TemplateBuilder.cs
- ToolStripSeparatorRenderEventArgs.cs
- DbgUtil.cs
- FormViewPagerRow.cs
- DbProviderSpecificTypePropertyAttribute.cs
- ConstraintManager.cs
- NotifyIcon.cs
- FontStretchConverter.cs
- DependencyObjectType.cs
- Missing.cs
- Point3DCollection.cs
- WebHttpElement.cs
- DataGridViewAutoSizeModeEventArgs.cs
- DataBindingHandlerAttribute.cs
- WebPartTransformerAttribute.cs
- StrongNamePublicKeyBlob.cs
- AnimationClockResource.cs
- ScriptResourceHandler.cs
- FontResourceCache.cs
- ScriptingJsonSerializationSection.cs
- RelationshipNavigation.cs
- RequiredArgumentAttribute.cs
- RestrictedTransactionalPackage.cs
- InvocationExpression.cs
- Brushes.cs
- ApplicationContext.cs
- CngProperty.cs
- SystemIPAddressInformation.cs
- MergablePropertyAttribute.cs
- ResourceType.cs
- DiffuseMaterial.cs
- HttpRawResponse.cs
- DbParameterCollection.cs
- XPathAxisIterator.cs
- XmlDownloadManager.cs
- XmlBufferReader.cs
- XPathNode.cs
- RijndaelManaged.cs
- InlineCollection.cs
- RectangleConverter.cs
- Util.cs
- ImageListImage.cs
- CheckedListBox.cs
- UrlPath.cs
- AffineTransform3D.cs
- CommentEmitter.cs
- ProbeDuplex11AsyncResult.cs
- MaskInputRejectedEventArgs.cs
- TrailingSpaceComparer.cs
- GenericUriParser.cs
- Message.cs
- GenericFlowSwitchHelper.cs
- GeneralTransform3DTo2D.cs
- MetadataCache.cs
- UTF8Encoding.cs
- TextFormatterContext.cs
- NameTable.cs
- ShutDownListener.cs
- oledbmetadatacollectionnames.cs
- InstanceDataCollection.cs
- UserControl.cs
- WindowsContainer.cs
- MLangCodePageEncoding.cs
- ConfigXmlElement.cs
- UserNamePasswordValidator.cs
- IDQuery.cs
- XmlReturnWriter.cs
- WindowsFormsEditorServiceHelper.cs
- FixedFlowMap.cs
- BaseCollection.cs