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 / EdmProperty.cs / 2 / EdmProperty.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System.Data.Common;
using System.Threading;
namespace System.Data.Metadata.Edm
{
///
/// Represent the edm property class
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
public sealed class EdmProperty : EdmMember
{
#region Constructors
///
/// Initializes a new instance of the property class
///
/// name of the property
/// TypeUsage object containing the property type and its facets
/// Thrown if name or typeUsage arguments are null
/// Thrown if name argument is empty string
internal EdmProperty(string name, TypeUsage typeUsage)
: base(name, typeUsage)
{
EntityUtil.CheckStringArgument(name, "name");
EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage");
}
#endregion
#region Fields
/// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
internal readonly System.RuntimeMethodHandle PropertyGetterHandle;
/// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
internal readonly System.RuntimeMethodHandle PropertySetterHandle;
/// cached dynamic method to get the property value from a CLR instance
private Func _memberGetter;
/// cached dynamic method to set a CLR property value on a CLR instance
private Action _memberSetter;
#endregion
///
/// Initializes a new OSpace instance of the property class
///
/// name of the property
/// TypeUsage object containing the property type and its facets
/// for the property
internal EdmProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo)
: this(name, typeUsage)
{
System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName");
if (null != propertyInfo)
{
System.Reflection.MethodInfo method;
method = propertyInfo.GetGetMethod(true); // return public or non-public getter
PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));
method = propertyInfo.GetSetMethod(true); // return public or non-public getter
PropertySetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));
}
}
///
/// Returns the kind of the type
///
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EdmProperty; } }
///
/// Returns true if this property is nullable
///
/// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
public bool Nullable
{
get
{
return (bool)TypeUsage.Facets[DbProviderManifest.NullableFacetName].Value;
}
}
///
/// Returns the default value for this property
///
/// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
public Object DefaultValue
{
get
{
return TypeUsage.Facets[DbProviderManifest.DefaultValueFacetName].Value;
}
}
/// cached dynamic method to get the property value from a CLR instance
internal Func ValueGetter {
get { return _memberGetter; }
set
{
System.Diagnostics.Debug.Assert(null != value, "clearing ValueGetter");
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _memberGetter, value, null);
}
}
/// cached dynamic method to set a CLR property value on a CLR instance
internal Action ValueSetter
{
get { return _memberSetter; }
set
{
System.Diagnostics.Debug.Assert(null != value, "clearing ValueSetter");
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _memberSetter, value, null);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System.Data.Common;
using System.Threading;
namespace System.Data.Metadata.Edm
{
///
/// Represent the edm property class
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
public sealed class EdmProperty : EdmMember
{
#region Constructors
///
/// Initializes a new instance of the property class
///
/// name of the property
/// TypeUsage object containing the property type and its facets
/// Thrown if name or typeUsage arguments are null
/// Thrown if name argument is empty string
internal EdmProperty(string name, TypeUsage typeUsage)
: base(name, typeUsage)
{
EntityUtil.CheckStringArgument(name, "name");
EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage");
}
#endregion
#region Fields
/// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
internal readonly System.RuntimeMethodHandle PropertyGetterHandle;
/// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
internal readonly System.RuntimeMethodHandle PropertySetterHandle;
/// cached dynamic method to get the property value from a CLR instance
private Func _memberGetter;
/// cached dynamic method to set a CLR property value on a CLR instance
private Action _memberSetter;
#endregion
///
/// Initializes a new OSpace instance of the property class
///
/// name of the property
/// TypeUsage object containing the property type and its facets
/// for the property
internal EdmProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo)
: this(name, typeUsage)
{
System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName");
if (null != propertyInfo)
{
System.Reflection.MethodInfo method;
method = propertyInfo.GetGetMethod(true); // return public or non-public getter
PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));
method = propertyInfo.GetSetMethod(true); // return public or non-public getter
PropertySetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle));
}
}
///
/// Returns the kind of the type
///
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EdmProperty; } }
///
/// Returns true if this property is nullable
///
/// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
public bool Nullable
{
get
{
return (bool)TypeUsage.Facets[DbProviderManifest.NullableFacetName].Value;
}
}
///
/// Returns the default value for this property
///
/// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
public Object DefaultValue
{
get
{
return TypeUsage.Facets[DbProviderManifest.DefaultValueFacetName].Value;
}
}
/// cached dynamic method to get the property value from a CLR instance
internal Func ValueGetter {
get { return _memberGetter; }
set
{
System.Diagnostics.Debug.Assert(null != value, "clearing ValueGetter");
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _memberGetter, value, null);
}
}
/// cached dynamic method to set a CLR property value on a CLR instance
internal Action ValueSetter
{
get { return _memberSetter; }
set
{
System.Diagnostics.Debug.Assert(null != value, "clearing ValueSetter");
// It doesn't matter which delegate wins, but only one should be jitted
Interlocked.CompareExchange(ref _memberSetter, value, null);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.