Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Metadata / Edm / MetadataPropertyCollection.cs / 2 / MetadataPropertyCollection.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....],[....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Data.Common; using System.Diagnostics; using System.Reflection; using System.Data.Common.Utils; namespace System.Data.Metadata.Edm { ////// Metadata collection class supporting delay-loading of system item attributes and /// extended attributes. /// internal sealed class MetadataPropertyCollection : MetadataCollection{ /// /// Constructor taking item. /// /// Item with which the collection is associated. internal MetadataPropertyCollection(MetadataItem item) : base(GetSystemMetadataProperties(item)) { } private readonly static Memoizers_itemTypeMemoizer = new Memoizer (clrType => new ItemTypeInformation(clrType), null); // Given an item, returns all system type attributes for the item. private static IEnumerable GetSystemMetadataProperties(MetadataItem item) { EntityUtil.CheckArgumentNull(item, "item"); Type type = item.GetType(); ItemTypeInformation itemTypeInformation = GetItemTypeInformation(type); return itemTypeInformation.GetItemAttributes(item); } // Retrieves metadata for type. private static ItemTypeInformation GetItemTypeInformation(Type clrType) { return s_itemTypeMemoizer.Evaluate(clrType); } /// /// Encapsulates information about system item attributes for a particular item type. /// private class ItemTypeInformation { ////// Retrieves system attribute information for the given type. /// Requires: type must derive from MetadataItem /// /// Type internal ItemTypeInformation(Type clrType) { Debug.Assert(null != clrType); _itemProperties = GetItemProperties(clrType); } private readonly List_itemProperties; // Returns system item attributes for the given item. internal IEnumerable GetItemAttributes(MetadataItem item) { foreach (ItemPropertyInfo propertyInfo in _itemProperties) { yield return propertyInfo.GetMetadataProperty(item); } } // Gets type information for item with the given type. Uses cached information where // available. private static List GetItemProperties(Type clrType) { List result = new List (); foreach (PropertyInfo propertyInfo in clrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (MetadataPropertyAttribute attribute in propertyInfo.GetCustomAttributes( typeof(MetadataPropertyAttribute), false)) { result.Add(new ItemPropertyInfo(propertyInfo, attribute)); } } return result; } } /// /// Encapsulates information about a CLR property of an item class. /// private class ItemPropertyInfo { ////// Initialize information. /// Requires: attribute must belong to the given property. /// /// Property referenced. /// Attribute for the property. internal ItemPropertyInfo(PropertyInfo propertyInfo, MetadataPropertyAttribute attribute) { Debug.Assert(null != propertyInfo); Debug.Assert(null != attribute); _propertyInfo = propertyInfo; _attribute = attribute; } private readonly MetadataPropertyAttribute _attribute; private readonly PropertyInfo _propertyInfo; ////// Given an item, returns an instance of the item attribute described by this class. /// /// Item from which to retrieve attribute. ///Item attribute. internal MetadataProperty GetMetadataProperty(MetadataItem item) { return new MetadataProperty(_propertyInfo.Name, _attribute.Type, _attribute.IsCollectionType, new MetadataPropertyValue(_propertyInfo, item)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....],[....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Data.Common; using System.Diagnostics; using System.Reflection; using System.Data.Common.Utils; namespace System.Data.Metadata.Edm { ////// Metadata collection class supporting delay-loading of system item attributes and /// extended attributes. /// internal sealed class MetadataPropertyCollection : MetadataCollection{ /// /// Constructor taking item. /// /// Item with which the collection is associated. internal MetadataPropertyCollection(MetadataItem item) : base(GetSystemMetadataProperties(item)) { } private readonly static Memoizers_itemTypeMemoizer = new Memoizer (clrType => new ItemTypeInformation(clrType), null); // Given an item, returns all system type attributes for the item. private static IEnumerable GetSystemMetadataProperties(MetadataItem item) { EntityUtil.CheckArgumentNull(item, "item"); Type type = item.GetType(); ItemTypeInformation itemTypeInformation = GetItemTypeInformation(type); return itemTypeInformation.GetItemAttributes(item); } // Retrieves metadata for type. private static ItemTypeInformation GetItemTypeInformation(Type clrType) { return s_itemTypeMemoizer.Evaluate(clrType); } /// /// Encapsulates information about system item attributes for a particular item type. /// private class ItemTypeInformation { ////// Retrieves system attribute information for the given type. /// Requires: type must derive from MetadataItem /// /// Type internal ItemTypeInformation(Type clrType) { Debug.Assert(null != clrType); _itemProperties = GetItemProperties(clrType); } private readonly List_itemProperties; // Returns system item attributes for the given item. internal IEnumerable GetItemAttributes(MetadataItem item) { foreach (ItemPropertyInfo propertyInfo in _itemProperties) { yield return propertyInfo.GetMetadataProperty(item); } } // Gets type information for item with the given type. Uses cached information where // available. private static List GetItemProperties(Type clrType) { List result = new List (); foreach (PropertyInfo propertyInfo in clrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (MetadataPropertyAttribute attribute in propertyInfo.GetCustomAttributes( typeof(MetadataPropertyAttribute), false)) { result.Add(new ItemPropertyInfo(propertyInfo, attribute)); } } return result; } } /// /// Encapsulates information about a CLR property of an item class. /// private class ItemPropertyInfo { ////// Initialize information. /// Requires: attribute must belong to the given property. /// /// Property referenced. /// Attribute for the property. internal ItemPropertyInfo(PropertyInfo propertyInfo, MetadataPropertyAttribute attribute) { Debug.Assert(null != propertyInfo); Debug.Assert(null != attribute); _propertyInfo = propertyInfo; _attribute = attribute; } private readonly MetadataPropertyAttribute _attribute; private readonly PropertyInfo _propertyInfo; ////// Given an item, returns an instance of the item attribute described by this class. /// /// Item from which to retrieve attribute. ///Item attribute. internal MetadataProperty GetMetadataProperty(MetadataItem item) { return new MetadataProperty(_propertyInfo.Name, _attribute.Type, _attribute.IsCollectionType, new MetadataPropertyValue(_propertyInfo, item)); } } } } // 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
- ProgressChangedEventArgs.cs
- Operators.cs
- TextRangeEdit.cs
- IdleTimeoutMonitor.cs
- ToolBarPanel.cs
- ScopedKnownTypes.cs
- MimeFormatExtensions.cs
- _PooledStream.cs
- SqlConnectionHelper.cs
- StreamWithDictionary.cs
- EmptyStringExpandableObjectConverter.cs
- OdbcErrorCollection.cs
- PartBasedPackageProperties.cs
- DataViewManagerListItemTypeDescriptor.cs
- RectangleGeometry.cs
- NavigateEvent.cs
- ApplicationHost.cs
- PostBackOptions.cs
- UInt16Converter.cs
- CopyCodeAction.cs
- RegisteredArrayDeclaration.cs
- InputLanguage.cs
- ChtmlTextBoxAdapter.cs
- WindowsStatusBar.cs
- NotifyParentPropertyAttribute.cs
- UIElementIsland.cs
- DCSafeHandle.cs
- DurableMessageDispatchInspector.cs
- XmlDigitalSignatureProcessor.cs
- TextSimpleMarkerProperties.cs
- Geometry.cs
- Package.cs
- AppDomainUnloadedException.cs
- DirectoryRootQuery.cs
- MediaEntryAttribute.cs
- Helper.cs
- DataGridViewToolTip.cs
- Binding.cs
- WebPageTraceListener.cs
- ListComponentEditor.cs
- UnsafeNativeMethods.cs
- HttpGetClientProtocol.cs
- InputProcessorProfilesLoader.cs
- StreamAsIStream.cs
- XmlSchemaValidationException.cs
- PropertyGroupDescription.cs
- XmlText.cs
- ExpressionBuilderContext.cs
- StyleHelper.cs
- StateDesigner.cs
- ServiceDescriptionImporter.cs
- DbSetClause.cs
- CodeGenHelper.cs
- BitmapMetadataEnumerator.cs
- EpmSyndicationContentSerializer.cs
- HandoffBehavior.cs
- XmlAnyElementAttribute.cs
- PageAsyncTask.cs
- DataAccessor.cs
- XmlEncodedRawTextWriter.cs
- RadioButton.cs
- Serializer.cs
- MemberPathMap.cs
- RawStylusInputCustomData.cs
- OutputCacheProfileCollection.cs
- ConnectionConsumerAttribute.cs
- TypefaceCollection.cs
- NumericUpDownAccelerationCollection.cs
- AnonymousIdentificationSection.cs
- BoundsDrawingContextWalker.cs
- Asn1IntegerConverter.cs
- CategoryGridEntry.cs
- SkinBuilder.cs
- SpotLight.cs
- LogicalExpr.cs
- ActionItem.cs
- CombinedHttpChannel.cs
- exports.cs
- SectionInput.cs
- WinFormsSecurity.cs
- StylusLogic.cs
- StylusPoint.cs
- DataColumnCollection.cs
- X509Certificate2Collection.cs
- BuiltInPermissionSets.cs
- PropertyConverter.cs
- SecondaryViewProvider.cs
- WebPartEditorApplyVerb.cs
- CodeArrayIndexerExpression.cs
- SchemaSetCompiler.cs
- WorkflowServiceHost.cs
- SchemaCollectionPreprocessor.cs
- PrintControllerWithStatusDialog.cs
- __Error.cs
- Dictionary.cs
- SqlDataSourceStatusEventArgs.cs
- webbrowsersite.cs
- ReadOnlyMetadataCollection.cs
- VariantWrapper.cs
- FormViewPagerRow.cs