Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Common / DataRecordInfo.cs / 1 / DataRecordInfo.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common
{
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Diagnostics;
///
/// DataRecordInfo class providing a simple way to access both the type information and the column information.
///
public class DataRecordInfo
{
private readonly System.Collections.ObjectModel.ReadOnlyCollection _fieldMetadata;
private readonly TypeUsage _metadata;
///
/// Construct DataRecordInfo with list of EdmMembers.
/// Each memberInfo must be a member of metadata.
///
///
///
public DataRecordInfo(TypeUsage metadata, IEnumerable memberInfo)
{
EntityUtil.CheckArgumentNull(metadata, "metadata");
IBaseList members = TypeHelpers.GetAllStructuralMembers(metadata.EdmType);
List fieldList = new List(members.Count);
if (null != memberInfo)
{
foreach (EdmMember member in memberInfo)
{
if ((null != member) &&
(0 <= members.IndexOf(member)) &&
((BuiltInTypeKind.EdmProperty == member.BuiltInTypeKind) || // for ComplexType, EntityType; BuiltTypeKind.NaviationProperty not allowed
(BuiltInTypeKind.AssociationEndMember == member.BuiltInTypeKind))) // for AssociationType
{ // each memberInfo must be non-null and be part of Properties or AssociationEndMembers
//validate that EdmMembers are from the same type or base type of the passed in metadata.
if((member.DeclaringType != metadata.EdmType) &&
!member.DeclaringType.IsBaseTypeOf(metadata.EdmType))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.EdmMembersDefiningTypeDoNotAgreeWithMetadataType);
}
fieldList.Add(new FieldMetadata(fieldList.Count, member));
}
else
{ // expecting empty memberInfo for non-structural && non-null member part of members if structural
throw EntityUtil.Argument("memberInfo");
}
}
}
// expecting structural types to have something at least 1 property
// (((null == structural) && (0 == fieldList.Count)) || ((null != structural) && (0 < fieldList.Count)))
if (Helper.IsStructuralType(metadata.EdmType) == (0 < fieldList.Count))
{
_fieldMetadata = new System.Collections.ObjectModel.ReadOnlyCollection(fieldList);
_metadata = metadata;
}
else
{
throw EntityUtil.Argument("memberInfo");
}
}
///
/// Construct FieldMetadata for structuralType.Members from TypeUsage
///
internal DataRecordInfo(TypeUsage metadata)
{
Debug.Assert(null != metadata, "invalid attempt to instantiate DataRecordInfo with null metadata information");
IBaseList structuralMembers = TypeHelpers.GetAllStructuralMembers(metadata);
FieldMetadata[] fieldList = new FieldMetadata[structuralMembers.Count];
for (int i = 0; i < fieldList.Length; ++i)
{
EdmMember member = structuralMembers[i];
Debug.Assert((BuiltInTypeKind.EdmProperty == member.BuiltInTypeKind) ||
(BuiltInTypeKind.AssociationEndMember == member.BuiltInTypeKind),
"unexpected BuiltInTypeKind for member");
fieldList[i] = new FieldMetadata(i, member);
}
_fieldMetadata = new System.Collections.ObjectModel.ReadOnlyCollection(fieldList);
_metadata = metadata;
}
///
/// Reusing TypeUsage and FieldMetadata from another EntityRecordInfo which has all the same info
/// but with a different EntityKey instance.
///
internal DataRecordInfo(DataRecordInfo recordInfo)
{
_fieldMetadata = recordInfo._fieldMetadata;
_metadata = recordInfo._metadata;
}
///
/// Column information.
///
public System.Collections.ObjectModel.ReadOnlyCollection FieldMetadata
{
get
{
return _fieldMetadata;
}
}
///
/// Type information.
///
public TypeUsage RecordType
{
get
{
return _metadata;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common
{
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Diagnostics;
///
/// DataRecordInfo class providing a simple way to access both the type information and the column information.
///
public class DataRecordInfo
{
private readonly System.Collections.ObjectModel.ReadOnlyCollection _fieldMetadata;
private readonly TypeUsage _metadata;
///
/// Construct DataRecordInfo with list of EdmMembers.
/// Each memberInfo must be a member of metadata.
///
///
///
public DataRecordInfo(TypeUsage metadata, IEnumerable memberInfo)
{
EntityUtil.CheckArgumentNull(metadata, "metadata");
IBaseList members = TypeHelpers.GetAllStructuralMembers(metadata.EdmType);
List fieldList = new List(members.Count);
if (null != memberInfo)
{
foreach (EdmMember member in memberInfo)
{
if ((null != member) &&
(0 <= members.IndexOf(member)) &&
((BuiltInTypeKind.EdmProperty == member.BuiltInTypeKind) || // for ComplexType, EntityType; BuiltTypeKind.NaviationProperty not allowed
(BuiltInTypeKind.AssociationEndMember == member.BuiltInTypeKind))) // for AssociationType
{ // each memberInfo must be non-null and be part of Properties or AssociationEndMembers
//validate that EdmMembers are from the same type or base type of the passed in metadata.
if((member.DeclaringType != metadata.EdmType) &&
!member.DeclaringType.IsBaseTypeOf(metadata.EdmType))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.EdmMembersDefiningTypeDoNotAgreeWithMetadataType);
}
fieldList.Add(new FieldMetadata(fieldList.Count, member));
}
else
{ // expecting empty memberInfo for non-structural && non-null member part of members if structural
throw EntityUtil.Argument("memberInfo");
}
}
}
// expecting structural types to have something at least 1 property
// (((null == structural) && (0 == fieldList.Count)) || ((null != structural) && (0 < fieldList.Count)))
if (Helper.IsStructuralType(metadata.EdmType) == (0 < fieldList.Count))
{
_fieldMetadata = new System.Collections.ObjectModel.ReadOnlyCollection(fieldList);
_metadata = metadata;
}
else
{
throw EntityUtil.Argument("memberInfo");
}
}
///
/// Construct FieldMetadata for structuralType.Members from TypeUsage
///
internal DataRecordInfo(TypeUsage metadata)
{
Debug.Assert(null != metadata, "invalid attempt to instantiate DataRecordInfo with null metadata information");
IBaseList structuralMembers = TypeHelpers.GetAllStructuralMembers(metadata);
FieldMetadata[] fieldList = new FieldMetadata[structuralMembers.Count];
for (int i = 0; i < fieldList.Length; ++i)
{
EdmMember member = structuralMembers[i];
Debug.Assert((BuiltInTypeKind.EdmProperty == member.BuiltInTypeKind) ||
(BuiltInTypeKind.AssociationEndMember == member.BuiltInTypeKind),
"unexpected BuiltInTypeKind for member");
fieldList[i] = new FieldMetadata(i, member);
}
_fieldMetadata = new System.Collections.ObjectModel.ReadOnlyCollection(fieldList);
_metadata = metadata;
}
///
/// Reusing TypeUsage and FieldMetadata from another EntityRecordInfo which has all the same info
/// but with a different EntityKey instance.
///
internal DataRecordInfo(DataRecordInfo recordInfo)
{
_fieldMetadata = recordInfo._fieldMetadata;
_metadata = recordInfo._metadata;
}
///
/// Column information.
///
public System.Collections.ObjectModel.ReadOnlyCollection FieldMetadata
{
get
{
return _fieldMetadata;
}
}
///
/// Type information.
///
public TypeUsage RecordType
{
get
{
return _metadata;
}
}
}
}
// 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
- RequestCacheEntry.cs
- BufferedGraphics.cs
- XmlAttributeOverrides.cs
- RequestQueue.cs
- Symbol.cs
- Stylus.cs
- LinkArea.cs
- XmlObjectSerializerReadContextComplexJson.cs
- MergablePropertyAttribute.cs
- LinqExpressionNormalizer.cs
- CalendarDay.cs
- BrushConverter.cs
- SendOperation.cs
- InkCanvasSelectionAdorner.cs
- Types.cs
- Message.cs
- XslUrlEditor.cs
- TextBlockAutomationPeer.cs
- SqlDataSourceSelectingEventArgs.cs
- X509AsymmetricSecurityKey.cs
- Model3D.cs
- SqlRowUpdatedEvent.cs
- BindingMAnagerBase.cs
- FatalException.cs
- BaseValidatorDesigner.cs
- PostBackTrigger.cs
- NonVisualControlAttribute.cs
- TileBrush.cs
- IsolatedStorageFilePermission.cs
- TabPageDesigner.cs
- httpapplicationstate.cs
- GroupDescription.cs
- ScriptingProfileServiceSection.cs
- PageStatePersister.cs
- StateChangeEvent.cs
- MessageSecurityOverTcp.cs
- OdbcDataAdapter.cs
- UTF32Encoding.cs
- CodeNamespaceImport.cs
- IntegerFacetDescriptionElement.cs
- PropertiesTab.cs
- Marshal.cs
- DefaultEventAttribute.cs
- PropertyHelper.cs
- XpsFixedPageReaderWriter.cs
- AccessorTable.cs
- XslUrlEditor.cs
- WorkflowDebuggerSteppingAttribute.cs
- InputScopeNameConverter.cs
- diagnosticsswitches.cs
- SafePipeHandle.cs
- InvalidAsynchronousStateException.cs
- EdmSchemaError.cs
- BooleanExpr.cs
- UniqueSet.cs
- WebPartPersonalization.cs
- DataBindingList.cs
- CodeSnippetStatement.cs
- CodeGeneratorOptions.cs
- TemplateParser.cs
- FrameworkElementFactoryMarkupObject.cs
- ControlBindingsCollection.cs
- PathSegmentCollection.cs
- PartBasedPackageProperties.cs
- SByteConverter.cs
- TableColumn.cs
- ProfileInfo.cs
- SHA384.cs
- TypedElement.cs
- SynchronousChannel.cs
- DataTableMappingCollection.cs
- Point3DKeyFrameCollection.cs
- ColumnBinding.cs
- Itemizer.cs
- FunctionQuery.cs
- WebEventTraceProvider.cs
- TypeReference.cs
- FlowDocumentView.cs
- PathFigureCollection.cs
- ArrayExtension.cs
- XmlSerializationWriter.cs
- DataServiceRequestException.cs
- WindowsGraphicsWrapper.cs
- xml.cs
- FocusManager.cs
- SqlGatherConsumedAliases.cs
- OdbcErrorCollection.cs
- FontCollection.cs
- ProfileSection.cs
- FlowDecisionLabelFeature.cs
- BindingExpression.cs
- SerializationAttributes.cs
- GroupBoxAutomationPeer.cs
- oledbconnectionstring.cs
- AttributeCollection.cs
- RenderTargetBitmap.cs
- CqlQuery.cs
- TypeSchema.cs
- PluralizationServiceUtil.cs
- CheckStoreFileValidityRequest.cs