Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / FieldDescriptor.cs / 1305376 / FieldDescriptor.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.Common; using System.Data.Objects.DataClasses; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Globalization; namespace System.Data.Objects { internal sealed class FieldDescriptor : PropertyDescriptor { private readonly EdmProperty _property; private readonly Type _fieldType; private readonly Type _componentType; private readonly bool _isReadOnly; ////// Construct a new instance of the FieldDescriptor class that describes a property /// on components of the supplied type. /// /// Type of object whose property is described by this FieldDescriptor. /// /// True if property value on component can be modified; otherwise false. /// /// /// EdmProperty that describes the property on the component. /// internal FieldDescriptor(Type componentType, bool isReadOnly, EdmProperty property) : base(property.Name, null) { _componentType = componentType; _property = property; _isReadOnly = isReadOnly; _fieldType = DetermineClrType(_property.TypeUsage); System.Diagnostics.Debug.Assert(_fieldType != null, "FieldDescriptor's CLR type has unexpected value of null."); } ////// Determine a CLR Type to use a property descriptro form an EDM TypeUsage /// /// The EDM TypeUsage containing metadata about the type ///A CLR type that represents that EDM type private Type DetermineClrType(TypeUsage typeUsage) { Type result = null; EdmType edmType = typeUsage.EdmType; switch (edmType.BuiltInTypeKind) { case BuiltInTypeKind.EntityType: case BuiltInTypeKind.ComplexType: result = edmType.ClrType; break; case BuiltInTypeKind.RefType: result = typeof(EntityKey); break; case BuiltInTypeKind.CollectionType: TypeUsage elementTypeUse = ((CollectionType)edmType).TypeUsage; result = DetermineClrType(elementTypeUse); result = typeof(IEnumerable<>).MakeGenericType(result); break; case BuiltInTypeKind.PrimitiveType: result = edmType.ClrType; Facet nullable; if (result.IsValueType && typeUsage.Facets.TryGetValue(DbProviderManifest.NullableFacetName, false, out nullable) && ((bool)nullable.Value)) { result = typeof(Nullable<>).MakeGenericType(result); } break; case BuiltInTypeKind.RowType: result = typeof(IDataRecord); break; default: Debug.Fail(string.Format(CultureInfo.CurrentCulture, "The type {0} was not the expected scalar, enumeration, collection, structural, nominal, or reference type.", edmType.GetType())); break; } return result; } ////// Get ///instance associated with this field descriptor. /// /// The internal EdmProperty EdmProperty { get { return _property; } } public override Type ComponentType { get { return _componentType; } } public override bool IsReadOnly { get { return _isReadOnly; } } public override Type PropertyType { get { return _fieldType; } } public override bool CanResetValue(object component) { return false; } public override object GetValue(object component) { EntityUtil.CheckArgumentNull(component, "component"); if (!_componentType.IsAssignableFrom(component.GetType())) { throw EntityUtil.IncompatibleArgument(); } object propertyValue; DbDataRecord dbDataRecord = component as DbDataRecord; if (dbDataRecord != null) { propertyValue = (dbDataRecord.GetValue(dbDataRecord.GetOrdinal(_property.Name))); } else { propertyValue = LightweightCodeGenerator.GetValue(_property, component); } return propertyValue; } public override void ResetValue(object component) { throw EntityUtil.NotSupported(); } public override void SetValue(object component, object value) { EntityUtil.CheckArgumentNull(component, "component"); if (!_componentType.IsAssignableFrom(component.GetType())) { throw EntityUtil.IncompatibleArgument(); } if (!_isReadOnly) { LightweightCodeGenerator.SetValue(_property, component, value); } // if not entity it must be readonly else { throw EntityUtil.WriteOperationNotAllowedOnReadOnlyBindingList(); } } public override bool ShouldSerializeValue(object component) { return false; } public override bool IsBrowsable { get { return true; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //instance associated with this field descriptor, /// or null if there is no EDM property association. /// // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data.Common; using System.Data.Objects.DataClasses; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Globalization; namespace System.Data.Objects { internal sealed class FieldDescriptor : PropertyDescriptor { private readonly EdmProperty _property; private readonly Type _fieldType; private readonly Type _componentType; private readonly bool _isReadOnly; ////// Construct a new instance of the FieldDescriptor class that describes a property /// on components of the supplied type. /// /// Type of object whose property is described by this FieldDescriptor. /// /// True if property value on component can be modified; otherwise false. /// /// /// EdmProperty that describes the property on the component. /// internal FieldDescriptor(Type componentType, bool isReadOnly, EdmProperty property) : base(property.Name, null) { _componentType = componentType; _property = property; _isReadOnly = isReadOnly; _fieldType = DetermineClrType(_property.TypeUsage); System.Diagnostics.Debug.Assert(_fieldType != null, "FieldDescriptor's CLR type has unexpected value of null."); } ////// Determine a CLR Type to use a property descriptro form an EDM TypeUsage /// /// The EDM TypeUsage containing metadata about the type ///A CLR type that represents that EDM type private Type DetermineClrType(TypeUsage typeUsage) { Type result = null; EdmType edmType = typeUsage.EdmType; switch (edmType.BuiltInTypeKind) { case BuiltInTypeKind.EntityType: case BuiltInTypeKind.ComplexType: result = edmType.ClrType; break; case BuiltInTypeKind.RefType: result = typeof(EntityKey); break; case BuiltInTypeKind.CollectionType: TypeUsage elementTypeUse = ((CollectionType)edmType).TypeUsage; result = DetermineClrType(elementTypeUse); result = typeof(IEnumerable<>).MakeGenericType(result); break; case BuiltInTypeKind.PrimitiveType: result = edmType.ClrType; Facet nullable; if (result.IsValueType && typeUsage.Facets.TryGetValue(DbProviderManifest.NullableFacetName, false, out nullable) && ((bool)nullable.Value)) { result = typeof(Nullable<>).MakeGenericType(result); } break; case BuiltInTypeKind.RowType: result = typeof(IDataRecord); break; default: Debug.Fail(string.Format(CultureInfo.CurrentCulture, "The type {0} was not the expected scalar, enumeration, collection, structural, nominal, or reference type.", edmType.GetType())); break; } return result; } ////// Get ///instance associated with this field descriptor. /// /// The internal EdmProperty EdmProperty { get { return _property; } } public override Type ComponentType { get { return _componentType; } } public override bool IsReadOnly { get { return _isReadOnly; } } public override Type PropertyType { get { return _fieldType; } } public override bool CanResetValue(object component) { return false; } public override object GetValue(object component) { EntityUtil.CheckArgumentNull(component, "component"); if (!_componentType.IsAssignableFrom(component.GetType())) { throw EntityUtil.IncompatibleArgument(); } object propertyValue; DbDataRecord dbDataRecord = component as DbDataRecord; if (dbDataRecord != null) { propertyValue = (dbDataRecord.GetValue(dbDataRecord.GetOrdinal(_property.Name))); } else { propertyValue = LightweightCodeGenerator.GetValue(_property, component); } return propertyValue; } public override void ResetValue(object component) { throw EntityUtil.NotSupported(); } public override void SetValue(object component, object value) { EntityUtil.CheckArgumentNull(component, "component"); if (!_componentType.IsAssignableFrom(component.GetType())) { throw EntityUtil.IncompatibleArgument(); } if (!_isReadOnly) { LightweightCodeGenerator.SetValue(_property, component, value); } // if not entity it must be readonly else { throw EntityUtil.WriteOperationNotAllowedOnReadOnlyBindingList(); } } public override bool ShouldSerializeValue(object component) { return false; } public override bool IsBrowsable { get { return true; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.instance associated with this field descriptor, /// or null if there is no EDM property association. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WindowsGraphics2.cs
- SqlCacheDependencySection.cs
- MenuTracker.cs
- SrgsSemanticInterpretationTag.cs
- FrameSecurityDescriptor.cs
- TagPrefixInfo.cs
- NameValuePair.cs
- RequestQueryParser.cs
- CodeSnippetCompileUnit.cs
- securitycriticaldataClass.cs
- ConfigurationSectionHelper.cs
- TextCompositionManager.cs
- ElementNotEnabledException.cs
- tooltip.cs
- CopyOnWriteList.cs
- TextWriter.cs
- IdentityVerifier.cs
- IsolatedStorageFileStream.cs
- UIElement.cs
- ThumbButtonInfoCollection.cs
- CodeNamespaceCollection.cs
- BufferModesCollection.cs
- MissingSatelliteAssemblyException.cs
- HttpInputStream.cs
- ThreadStateException.cs
- XPathNodeInfoAtom.cs
- RawContentTypeMapper.cs
- Triplet.cs
- VisualBasicDesignerHelper.cs
- DBConcurrencyException.cs
- GeometryGroup.cs
- TdsParserStateObject.cs
- RSAPKCS1SignatureFormatter.cs
- IndentedTextWriter.cs
- DbException.cs
- LazyInitializer.cs
- ContractTypeNameCollection.cs
- SecurityBindingElement.cs
- RulePatternOps.cs
- VerificationAttribute.cs
- DataBoundControlParameterTarget.cs
- EventHandlersStore.cs
- XmlText.cs
- Window.cs
- DataTrigger.cs
- Storyboard.cs
- ScriptMethodAttribute.cs
- regiisutil.cs
- BindableAttribute.cs
- RootBrowserWindow.cs
- XmlSchemaSequence.cs
- ContentFilePart.cs
- RegexWorker.cs
- IsolatedStorageFileStream.cs
- TabletDeviceInfo.cs
- AssemblyCache.cs
- wgx_sdk_version.cs
- MetaData.cs
- SynchronizationValidator.cs
- CustomAttributeFormatException.cs
- ProfileSection.cs
- FixedSOMContainer.cs
- ListInitExpression.cs
- OrderedDictionaryStateHelper.cs
- DrawingGroupDrawingContext.cs
- DropDownList.cs
- DbMetaDataColumnNames.cs
- QueryCursorEventArgs.cs
- WebPartEditorCancelVerb.cs
- MenuItem.cs
- MsmqIntegrationBinding.cs
- ChannelBase.cs
- Int16AnimationUsingKeyFrames.cs
- UIElementAutomationPeer.cs
- InternalsVisibleToAttribute.cs
- QueueAccessMode.cs
- PersistNameAttribute.cs
- CaseExpr.cs
- FixedSOMSemanticBox.cs
- _Win32.cs
- DataGridLinkButton.cs
- XmlQueryOutput.cs
- FusionWrap.cs
- Size3DConverter.cs
- DataServiceContext.cs
- _HeaderInfo.cs
- TextComposition.cs
- PersonalizationStateQuery.cs
- XmlFormatReaderGenerator.cs
- BinaryCommonClasses.cs
- ObjectQueryExecutionPlan.cs
- HttpModuleActionCollection.cs
- DataGridPagingPage.cs
- PeerInvitationResponse.cs
- Nullable.cs
- TimerElapsedEvenArgs.cs
- Executor.cs
- HttpWebRequestElement.cs
- QueryResults.cs
- FontWeightConverter.cs