Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Objects / FieldDescriptor.cs / 2 / 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;
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:
throw EntityUtil.UnexpectedMetadataType(edmType);
}
return result;
}
///
/// Get instance associated with this field descriptor.
///
///
/// The instance associated with this field descriptor,
/// or null if there is no EDM property association.
///
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;
if (component is IEntityWithChangeTracker) //POCO will relax this requirement.
{
propertyValue = LightweightCodeGenerator.GetValue(_property, component);
}
else
{
DbDataRecord dbDataRecord = component as DbDataRecord;
if (dbDataRecord != null)
{
propertyValue = (dbDataRecord.GetValue(dbDataRecord.GetOrdinal(_property.Name)));
}
else
{
throw EntityUtil.NotSupported();
}
}
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 && component is IEntityWithChangeTracker) //POCO will relax this requirement
{
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.
//----------------------------------------------------------------------
//
// 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;
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:
throw EntityUtil.UnexpectedMetadataType(edmType);
}
return result;
}
///
/// Get instance associated with this field descriptor.
///
///
/// The instance associated with this field descriptor,
/// or null if there is no EDM property association.
///
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;
if (component is IEntityWithChangeTracker) //POCO will relax this requirement.
{
propertyValue = LightweightCodeGenerator.GetValue(_property, component);
}
else
{
DbDataRecord dbDataRecord = component as DbDataRecord;
if (dbDataRecord != null)
{
propertyValue = (dbDataRecord.GetValue(dbDataRecord.GetOrdinal(_property.Name)));
}
else
{
throw EntityUtil.NotSupported();
}
}
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 && component is IEntityWithChangeTracker) //POCO will relax this requirement
{
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AndMessageFilterTable.cs
- RangeValidator.cs
- SamlConditions.cs
- ImageSourceConverter.cs
- RectKeyFrameCollection.cs
- TableLayout.cs
- SqlCommandSet.cs
- RootDesignerSerializerAttribute.cs
- BitmapEffectInput.cs
- IFlowDocumentViewer.cs
- WebEvents.cs
- PassportAuthenticationModule.cs
- AttributeCollection.cs
- DataRowExtensions.cs
- EnumValidator.cs
- HttpClientProtocol.cs
- isolationinterop.cs
- StringConcat.cs
- EmptyEnumerator.cs
- ResXBuildProvider.cs
- SymLanguageVendor.cs
- TextElement.cs
- AsyncCompletedEventArgs.cs
- Translator.cs
- AliasExpr.cs
- StyleBamlRecordReader.cs
- VersionUtil.cs
- CustomCredentialPolicy.cs
- AlternationConverter.cs
- SafeCloseHandleCritical.cs
- CodeDelegateCreateExpression.cs
- RequestCacheEntry.cs
- HttpRequest.cs
- CodeBinaryOperatorExpression.cs
- DataContractSerializerSection.cs
- WebDescriptionAttribute.cs
- StorageModelBuildProvider.cs
- OdbcCommandBuilder.cs
- WCFModelStrings.Designer.cs
- ControlPersister.cs
- DataPagerFieldItem.cs
- XmlSchemaInferenceException.cs
- Inflater.cs
- ManipulationCompletedEventArgs.cs
- DataSourceGroupCollection.cs
- AnnotationHighlightLayer.cs
- TextEmbeddedObject.cs
- StringBuilder.cs
- ACE.cs
- ISCIIEncoding.cs
- SoapIgnoreAttribute.cs
- Debugger.cs
- DependencyPropertyHelper.cs
- RectKeyFrameCollection.cs
- ValueChangedEventManager.cs
- MarkupCompilePass2.cs
- FrameworkTextComposition.cs
- PropertyManager.cs
- ConfigurationLoaderException.cs
- XmlSchemas.cs
- WindowsListViewGroupSubsetLink.cs
- ImpersonationContext.cs
- ObjectContextServiceProvider.cs
- ComponentManagerBroker.cs
- ECDsaCng.cs
- DataGridColumnDropSeparator.cs
- GenericArgumentsUpdater.cs
- CollectionView.cs
- CqlLexer.cs
- ConstructorBuilder.cs
- Boolean.cs
- ClassHandlersStore.cs
- DictionaryChange.cs
- GridViewUpdatedEventArgs.cs
- CustomGrammar.cs
- OdbcDataAdapter.cs
- OdbcRowUpdatingEvent.cs
- ContextMenuStrip.cs
- SynchronizingStream.cs
- SmtpCommands.cs
- FirstQueryOperator.cs
- InitializationEventAttribute.cs
- GiveFeedbackEventArgs.cs
- DataGridView.cs
- SchemaImporterExtensionsSection.cs
- PreloadedPackages.cs
- PreDigestedSignedInfo.cs
- PerfProviderCollection.cs
- InfoCardServiceInstallComponent.cs
- TextLine.cs
- XmlQueryCardinality.cs
- ValidatorCompatibilityHelper.cs
- TextPointer.cs
- Ray3DHitTestResult.cs
- PageSettings.cs
- Int32AnimationBase.cs
- StructuredType.cs
- Point4DValueSerializer.cs
- SchemaMapping.cs
- _Connection.cs