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 / Metadata / Edm / MetadataPropertyCollection.cs / 1 / 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 Memoizer s_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 Memoizer s_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
- TextViewSelectionProcessor.cs
- TransactionOptions.cs
- DesignTimeParseData.cs
- InvokePatternIdentifiers.cs
- ScrollBarRenderer.cs
- CodeLinePragma.cs
- FacetChecker.cs
- IERequestCache.cs
- StreamAsIStream.cs
- StringAttributeCollection.cs
- HtmlControl.cs
- ConnectionProviderAttribute.cs
- TreeWalkHelper.cs
- Trace.cs
- XmlSchemaAppInfo.cs
- XmlKeywords.cs
- DbMetaDataFactory.cs
- BinaryCommonClasses.cs
- _Semaphore.cs
- AccessedThroughPropertyAttribute.cs
- ExpressionVisitorHelpers.cs
- RestHandlerFactory.cs
- SqlTopReducer.cs
- TextEditorSpelling.cs
- SubpageParaClient.cs
- CompilerCollection.cs
- CharAnimationUsingKeyFrames.cs
- GridPatternIdentifiers.cs
- InvalidProgramException.cs
- StandardCommands.cs
- NameValueConfigurationElement.cs
- Vector.cs
- SchemaReference.cs
- DeploymentSection.cs
- XmlMapping.cs
- Translator.cs
- CacheRequest.cs
- log.cs
- FontDriver.cs
- handlecollector.cs
- HtmlHead.cs
- StringStorage.cs
- WebEvents.cs
- AccessibleObject.cs
- BaseComponentEditor.cs
- Knowncolors.cs
- Compress.cs
- BoundField.cs
- SrgsDocument.cs
- UInt64Converter.cs
- DataGridViewCellParsingEventArgs.cs
- CatalogPart.cs
- NullableIntMinMaxAggregationOperator.cs
- ResolvedKeyFrameEntry.cs
- StandardToolWindows.cs
- SamlAssertionKeyIdentifierClause.cs
- Adorner.cs
- FixedTextView.cs
- DialogResultConverter.cs
- UriParserTemplates.cs
- PathNode.cs
- IItemContainerGenerator.cs
- StylusPlugInCollection.cs
- SwitchLevelAttribute.cs
- VoiceSynthesis.cs
- TableDetailsRow.cs
- DataIdProcessor.cs
- dataprotectionpermission.cs
- ToolBar.cs
- ToolboxControl.cs
- SourceFileBuildProvider.cs
- keycontainerpermission.cs
- filewebrequest.cs
- BindingNavigator.cs
- DummyDataSource.cs
- HttpDictionary.cs
- RelationshipFixer.cs
- ChildDocumentBlock.cs
- ProgressBar.cs
- RefType.cs
- DbConnectionStringBuilder.cs
- BamlLocalizationDictionary.cs
- ConfigXmlReader.cs
- ControlCachePolicy.cs
- XmlSchemaException.cs
- TraceHandler.cs
- CommonRemoteMemoryBlock.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- LayoutEditorPart.cs
- Mapping.cs
- SerializerWriterEventHandlers.cs
- Button.cs
- IntSecurity.cs
- parserscommon.cs
- FamilyMap.cs
- MasterPageBuildProvider.cs
- DataBindEngine.cs
- ShortcutKeysEditor.cs
- SettingsPropertyIsReadOnlyException.cs
- ToolStripMenuItemDesigner.cs